@wordpress/dataviews 9.0.1-next.6f42e1382.0 → 9.0.1-next.a730c9c8c.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +106 -11
- package/build/components/dataviews-filters/input-widget.js +48 -4
- package/build/components/dataviews-filters/input-widget.js.map +1 -1
- package/build/dataform-controls/array.js +9 -7
- package/build/dataform-controls/array.js.map +1 -1
- package/build/dataform-controls/checkbox.js +31 -20
- package/build/dataform-controls/checkbox.js.map +1 -1
- package/build/dataform-controls/color.js +29 -24
- package/build/dataform-controls/color.js.map +1 -1
- package/build/dataform-controls/date.js +32 -24
- package/build/dataform-controls/date.js.map +1 -1
- package/build/dataform-controls/datetime.js +133 -19
- package/build/dataform-controls/datetime.js.map +1 -1
- package/build/dataform-controls/email.js +7 -1
- package/build/dataform-controls/email.js.map +1 -1
- package/build/dataform-controls/index.js +23 -0
- package/build/dataform-controls/index.js.map +1 -1
- package/build/dataform-controls/integer.js +47 -34
- package/build/dataform-controls/integer.js.map +1 -1
- package/build/dataform-controls/radio.js +42 -9
- package/build/dataform-controls/radio.js.map +1 -1
- package/build/dataform-controls/relative-date-control.js +6 -10
- package/build/dataform-controls/relative-date-control.js.map +1 -1
- package/build/dataform-controls/select.js +41 -10
- package/build/dataform-controls/select.js.map +1 -1
- package/build/dataform-controls/telephone.js +7 -1
- package/build/dataform-controls/telephone.js.map +1 -1
- package/build/dataform-controls/text.js +14 -2
- package/build/dataform-controls/text.js.map +1 -1
- package/build/dataform-controls/textarea.js +33 -20
- package/build/dataform-controls/textarea.js.map +1 -1
- package/build/dataform-controls/toggle-group.js +36 -6
- package/build/dataform-controls/toggle-group.js.map +1 -1
- package/build/dataform-controls/toggle.js +33 -22
- package/build/dataform-controls/toggle.js.map +1 -1
- package/build/dataform-controls/url.js +7 -1
- package/build/dataform-controls/url.js.map +1 -1
- package/build/dataform-controls/utils/validated-input.js +34 -32
- package/build/dataform-controls/utils/validated-input.js.map +1 -1
- package/build/dataforms-layouts/panel/dropdown.js +10 -14
- package/build/dataforms-layouts/panel/dropdown.js.map +1 -1
- package/build/dataforms-layouts/panel/index.js +24 -11
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/panel/modal.js +22 -27
- package/build/dataforms-layouts/panel/modal.js.map +1 -1
- package/build/dataforms-layouts/panel/summary-button.js +67 -0
- package/build/dataforms-layouts/panel/summary-button.js.map +1 -0
- package/build/normalize-fields.js +17 -0
- package/build/normalize-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/components/dataviews-filters/input-widget.js +48 -4
- package/build-module/components/dataviews-filters/input-widget.js.map +1 -1
- package/build-module/dataform-controls/array.js +9 -7
- package/build-module/dataform-controls/array.js.map +1 -1
- package/build-module/dataform-controls/checkbox.js +31 -21
- package/build-module/dataform-controls/checkbox.js.map +1 -1
- package/build-module/dataform-controls/color.js +28 -24
- package/build-module/dataform-controls/color.js.map +1 -1
- package/build-module/dataform-controls/date.js +32 -24
- package/build-module/dataform-controls/date.js.map +1 -1
- package/build-module/dataform-controls/datetime.js +135 -21
- package/build-module/dataform-controls/datetime.js.map +1 -1
- package/build-module/dataform-controls/email.js +7 -1
- package/build-module/dataform-controls/email.js.map +1 -1
- package/build-module/dataform-controls/index.js +23 -0
- package/build-module/dataform-controls/index.js.map +1 -1
- package/build-module/dataform-controls/integer.js +46 -34
- package/build-module/dataform-controls/integer.js.map +1 -1
- package/build-module/dataform-controls/radio.js +44 -11
- package/build-module/dataform-controls/radio.js.map +1 -1
- package/build-module/dataform-controls/relative-date-control.js +6 -10
- package/build-module/dataform-controls/relative-date-control.js.map +1 -1
- package/build-module/dataform-controls/select.js +43 -12
- package/build-module/dataform-controls/select.js.map +1 -1
- package/build-module/dataform-controls/telephone.js +7 -1
- package/build-module/dataform-controls/telephone.js.map +1 -1
- package/build-module/dataform-controls/text.js +14 -2
- package/build-module/dataform-controls/text.js.map +1 -1
- package/build-module/dataform-controls/textarea.js +32 -20
- package/build-module/dataform-controls/textarea.js.map +1 -1
- package/build-module/dataform-controls/toggle-group.js +38 -8
- package/build-module/dataform-controls/toggle-group.js.map +1 -1
- package/build-module/dataform-controls/toggle.js +33 -23
- package/build-module/dataform-controls/toggle.js.map +1 -1
- package/build-module/dataform-controls/url.js +7 -1
- package/build-module/dataform-controls/url.js.map +1 -1
- package/build-module/dataform-controls/utils/validated-input.js +34 -33
- package/build-module/dataform-controls/utils/validated-input.js.map +1 -1
- package/build-module/dataforms-layouts/panel/dropdown.js +10 -15
- package/build-module/dataforms-layouts/panel/dropdown.js.map +1 -1
- package/build-module/dataforms-layouts/panel/index.js +24 -11
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/modal.js +22 -28
- package/build-module/dataforms-layouts/panel/modal.js.map +1 -1
- package/build-module/dataforms-layouts/panel/summary-button.js +60 -0
- package/build-module/dataforms-layouts/panel/summary-button.js.map +1 -0
- package/build-module/normalize-fields.js +15 -0
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-types/components/dataform/stories/index.story.d.ts +3 -0
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts +4 -2
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -1
- package/build-types/dataform-controls/array.d.ts.map +1 -1
- package/build-types/dataform-controls/checkbox.d.ts.map +1 -1
- package/build-types/dataform-controls/color.d.ts.map +1 -1
- package/build-types/dataform-controls/date.d.ts.map +1 -1
- package/build-types/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/dataform-controls/email.d.ts.map +1 -1
- package/build-types/dataform-controls/index.d.ts +1 -1
- package/build-types/dataform-controls/index.d.ts.map +1 -1
- package/build-types/dataform-controls/integer.d.ts.map +1 -1
- package/build-types/dataform-controls/radio.d.ts.map +1 -1
- package/build-types/dataform-controls/relative-date-control.d.ts +6 -5
- package/build-types/dataform-controls/relative-date-control.d.ts.map +1 -1
- package/build-types/dataform-controls/select.d.ts.map +1 -1
- package/build-types/dataform-controls/telephone.d.ts.map +1 -1
- package/build-types/dataform-controls/text.d.ts +1 -1
- package/build-types/dataform-controls/text.d.ts.map +1 -1
- package/build-types/dataform-controls/textarea.d.ts +1 -1
- package/build-types/dataform-controls/textarea.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle-group.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle.d.ts.map +1 -1
- package/build-types/dataform-controls/url.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/validated-input.d.ts +4 -4
- package/build-types/dataform-controls/utils/validated-input.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/dropdown.d.ts +2 -1
- package/build-types/dataforms-layouts/panel/dropdown.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/modal.d.ts +2 -1
- package/build-types/dataforms-layouts/panel/modal.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/summary-button.d.ts +15 -0
- package/build-types/dataforms-layouts/panel/summary-button.d.ts.map +1 -0
- package/build-types/field-types/stories/index.story.d.ts.map +1 -1
- package/build-types/normalize-fields.d.ts +3 -0
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/types.d.ts +66 -3
- package/build-types/types.d.ts.map +1 -1
- package/build-wp/index.js +1468 -1422
- package/package.json +16 -15
- package/src/components/dataform/stories/index.story.tsx +436 -7
- package/src/components/dataviews/stories/fixtures.tsx +99 -41
- package/src/components/dataviews/stories/index.story.tsx +1 -1
- package/src/components/dataviews-filters/input-widget.tsx +44 -5
- package/src/components/dataviews-picker/stories/index.story.tsx +1 -1
- package/src/dataform-controls/array.tsx +4 -6
- package/src/dataform-controls/checkbox.tsx +41 -24
- package/src/dataform-controls/color.tsx +33 -24
- package/src/dataform-controls/date.tsx +47 -21
- package/src/dataform-controls/datetime.tsx +171 -23
- package/src/dataform-controls/email.tsx +9 -1
- package/src/dataform-controls/index.tsx +26 -0
- package/src/dataform-controls/integer.tsx +82 -49
- package/src/dataform-controls/radio.tsx +53 -11
- package/src/dataform-controls/relative-date-control.tsx +11 -10
- package/src/dataform-controls/select.tsx +53 -10
- package/src/dataform-controls/telephone.tsx +9 -1
- package/src/dataform-controls/text.tsx +18 -1
- package/src/dataform-controls/textarea.tsx +38 -24
- package/src/dataform-controls/toggle-group.tsx +50 -10
- package/src/dataform-controls/toggle.tsx +41 -24
- package/src/dataform-controls/url.tsx +9 -1
- package/src/dataform-controls/utils/validated-input.tsx +50 -50
- package/src/dataforms-layouts/panel/dropdown.tsx +12 -23
- package/src/dataforms-layouts/panel/index.tsx +39 -16
- package/src/dataforms-layouts/panel/modal.tsx +24 -30
- package/src/dataforms-layouts/panel/summary-button.tsx +92 -0
- package/src/field-types/stories/index.story.tsx +89 -1
- package/src/normalize-fields.ts +18 -0
- package/src/test/filter-and-sort-data-view.js +148 -138
- package/src/test/normalize-fields.ts +114 -0
- package/src/types.ts +73 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -34,18 +34,29 @@ function FormPanelField({
|
|
|
34
34
|
const {
|
|
35
35
|
fields
|
|
36
36
|
} = (0, _element.useContext)(_dataformContext.default);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (simpleChildren.length === 0) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
const firstChildFieldId = typeof simpleChildren[0] === 'string' ? simpleChildren[0] : simpleChildren[0].id;
|
|
45
|
-
return _field.id === firstChildFieldId;
|
|
37
|
+
const getSummaryFields = () => {
|
|
38
|
+
if (!(0, _isCombinedField.isCombinedField)(field)) {
|
|
39
|
+
const fieldDef = fields.find(_field => _field.id === field.id);
|
|
40
|
+
return fieldDef ? [fieldDef] : [];
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
|
|
43
|
+
// Use summary field(s) if specified for combined fields
|
|
44
|
+
if (field.summary) {
|
|
45
|
+
const summaryIds = Array.isArray(field.summary) ? field.summary : [field.summary];
|
|
46
|
+
return summaryIds.map(summaryId => fields.find(_field => _field.id === summaryId)).filter(_field => _field !== undefined);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Default to the first simple child
|
|
50
|
+
const simpleChildren = field.children.filter(child => typeof child === 'string' || !(0, _isCombinedField.isCombinedField)(child));
|
|
51
|
+
if (simpleChildren.length === 0) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
const firstChildFieldId = typeof simpleChildren[0] === 'string' ? simpleChildren[0] : simpleChildren[0].id;
|
|
55
|
+
const fieldDef = fields.find(_field => _field.id === firstChildFieldId);
|
|
56
|
+
return fieldDef ? [fieldDef] : [];
|
|
57
|
+
};
|
|
58
|
+
const summaryFields = getSummaryFields();
|
|
59
|
+
const fieldDefinition = summaryFields[0]; // For backward compatibility
|
|
49
60
|
|
|
50
61
|
// Use internal state instead of a ref to make sure that the component
|
|
51
62
|
// re-renders when the popover's anchor updates.
|
|
@@ -63,6 +74,7 @@ function FormPanelField({
|
|
|
63
74
|
const renderedControl = layout.openAs === 'modal' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_modal.default, {
|
|
64
75
|
field: field,
|
|
65
76
|
fieldDefinition: fieldDefinition,
|
|
77
|
+
summaryFields: summaryFields,
|
|
66
78
|
data: data,
|
|
67
79
|
onChange: onChange,
|
|
68
80
|
labelPosition: labelPosition
|
|
@@ -70,6 +82,7 @@ function FormPanelField({
|
|
|
70
82
|
field: field,
|
|
71
83
|
popoverAnchor: popoverAnchor,
|
|
72
84
|
fieldDefinition: fieldDefinition,
|
|
85
|
+
summaryFields: summaryFields,
|
|
73
86
|
data: data,
|
|
74
87
|
onChange: onChange,
|
|
75
88
|
labelPosition: labelPosition
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_components","_element","_dataformContext","_isCombinedField","_normalizeFormFields","_dropdown","_modal","_jsxRuntime","FormPanelField","data","field","onChange","fields","useContext","DataFormContext","
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_components","_element","_dataformContext","_isCombinedField","_normalizeFormFields","_dropdown","_modal","_jsxRuntime","FormPanelField","data","field","onChange","fields","useContext","DataFormContext","getSummaryFields","isCombinedField","fieldDef","find","_field","id","summary","summaryIds","Array","isArray","map","summaryId","filter","undefined","simpleChildren","children","child","length","firstChildFieldId","summaryFields","fieldDefinition","popoverAnchor","setPopoverAnchor","useState","layout","normalizeLayout","type","labelPosition","labelClassName","clsx","fieldLabel","label","renderedControl","openAs","jsx","default","jsxs","__experimentalVStack","className","spacing","style","paddingBottom","__experimentalHStack","ref"],"sources":["@wordpress/dataviews/src/dataforms-layouts/panel/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { useState, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tFieldLayoutProps,\n\tNormalizedPanelLayout,\n\tSimpleFormField,\n} from '../../types';\nimport DataFormContext from '../../components/dataform-context';\nimport { isCombinedField } from '../is-combined-field';\nimport { normalizeLayout } from '../../normalize-form-fields';\nimport PanelDropdown from './dropdown';\nimport PanelModal from './modal';\n\nexport default function FormPanelField< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n}: FieldLayoutProps< Item > ) {\n\tconst { fields } = useContext( DataFormContext );\n\tconst getSummaryFields = () => {\n\t\tif ( ! isCombinedField( field ) ) {\n\t\t\tconst fieldDef = fields.find(\n\t\t\t\t( _field ) => _field.id === field.id\n\t\t\t);\n\t\t\treturn fieldDef ? [ fieldDef ] : [];\n\t\t}\n\n\t\t// Use summary field(s) if specified for combined fields\n\t\tif ( field.summary ) {\n\t\t\tconst summaryIds = Array.isArray( field.summary )\n\t\t\t\t? field.summary\n\t\t\t\t: [ field.summary ];\n\t\t\treturn summaryIds\n\t\t\t\t.map( ( summaryId ) =>\n\t\t\t\t\tfields.find( ( _field ) => _field.id === summaryId )\n\t\t\t\t)\n\t\t\t\t.filter( ( _field ) => _field !== undefined );\n\t\t}\n\n\t\t// Default to the first simple child\n\t\tconst simpleChildren = field.children.filter(\n\t\t\t( child ): child is string | SimpleFormField =>\n\t\t\t\ttypeof child === 'string' || ! isCombinedField( child )\n\t\t);\n\n\t\tif ( simpleChildren.length === 0 ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst firstChildFieldId =\n\t\t\ttypeof simpleChildren[ 0 ] === 'string'\n\t\t\t\t? simpleChildren[ 0 ]\n\t\t\t\t: simpleChildren[ 0 ].id;\n\n\t\tconst fieldDef = fields.find(\n\t\t\t( _field ) => _field.id === firstChildFieldId\n\t\t);\n\t\treturn fieldDef ? [ fieldDef ] : [];\n\t};\n\n\tconst summaryFields = getSummaryFields();\n\tconst fieldDefinition = summaryFields[ 0 ]; // For backward compatibility\n\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState< HTMLElement | null >(\n\t\tnull\n\t);\n\n\tif ( ! fieldDefinition ) {\n\t\treturn null;\n\t}\n\n\tconst layout: NormalizedPanelLayout = normalizeLayout( {\n\t\t...field.layout,\n\t\ttype: 'panel',\n\t} ) as NormalizedPanelLayout;\n\n\tconst labelPosition = layout.labelPosition;\n\tconst labelClassName = clsx(\n\t\t'dataforms-layouts-panel__field-label',\n\t\t`dataforms-layouts-panel__field-label--label-position-${ labelPosition }`\n\t);\n\tconst fieldLabel = isCombinedField( field )\n\t\t? field.label\n\t\t: fieldDefinition?.label;\n\n\tconst renderedControl =\n\t\tlayout.openAs === 'modal' ? (\n\t\t\t<PanelModal\n\t\t\t\tfield={ field }\n\t\t\t\tfieldDefinition={ fieldDefinition }\n\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\tdata={ data }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tlabelPosition={ labelPosition }\n\t\t\t/>\n\t\t) : (\n\t\t\t<PanelDropdown\n\t\t\t\tfield={ field }\n\t\t\t\tpopoverAnchor={ popoverAnchor }\n\t\t\t\tfieldDefinition={ fieldDefinition }\n\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\tdata={ data }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tlabelPosition={ labelPosition }\n\t\t\t/>\n\t\t);\n\n\tif ( labelPosition === 'top' ) {\n\t\treturn (\n\t\t\t<VStack className=\"dataforms-layouts-panel__field\" spacing={ 0 }>\n\t\t\t\t<div\n\t\t\t\t\tclassName={ labelClassName }\n\t\t\t\t\tstyle={ { paddingBottom: 0 } }\n\t\t\t\t>\n\t\t\t\t\t{ fieldLabel }\n\t\t\t\t</div>\n\t\t\t\t<div className=\"dataforms-layouts-panel__field-control\">\n\t\t\t\t\t{ renderedControl }\n\t\t\t\t</div>\n\t\t\t</VStack>\n\t\t);\n\t}\n\n\tif ( labelPosition === 'none' ) {\n\t\treturn (\n\t\t\t<div className=\"dataforms-layouts-panel__field\">\n\t\t\t\t{ renderedControl }\n\t\t\t</div>\n\t\t);\n\t}\n\n\t// Defaults to label position side.\n\treturn (\n\t\t<HStack\n\t\t\tref={ setPopoverAnchor }\n\t\t\tclassName=\"dataforms-layouts-panel__field\"\n\t\t>\n\t\t\t<div className={ labelClassName }>{ fieldLabel }</div>\n\t\t\t<div className=\"dataforms-layouts-panel__field-control\">\n\t\t\t\t{ renderedControl }\n\t\t\t</div>\n\t\t</HStack>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AAIA,IAAAE,QAAA,GAAAF,OAAA;AAUA,IAAAG,gBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,gBAA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S,EAAC,wCAAwC;MAAAvB,QAAA,EACpDiB;IAAe,CACb,CAAC;EAAA,CACC,CAAC;AAEX","ignoreList":[]}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.default = void 0;
|
|
8
|
+
var _deepmerge = _interopRequireDefault(require("deepmerge"));
|
|
7
9
|
var _components = require("@wordpress/components");
|
|
8
10
|
var _i18n = require("@wordpress/i18n");
|
|
9
11
|
var _element = require("@wordpress/element");
|
|
10
12
|
var _dataFormLayout = require("../data-form-layout");
|
|
11
13
|
var _isCombinedField = require("../is-combined-field");
|
|
12
14
|
var _normalizeFormFields = require("../../normalize-form-fields");
|
|
15
|
+
var _summaryButton = _interopRequireDefault(require("./summary-button"));
|
|
13
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
+
/**
|
|
18
|
+
* External dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
22
|
* WordPress dependencies
|
|
16
23
|
*/
|
|
@@ -27,21 +34,15 @@ function ModalContent({
|
|
|
27
34
|
onClose
|
|
28
35
|
}) {
|
|
29
36
|
const [changes, setChanges] = (0, _element.useState)({});
|
|
37
|
+
const modalData = (0, _element.useMemo)(() => {
|
|
38
|
+
return (0, _deepmerge.default)(data, changes);
|
|
39
|
+
}, [data, changes]);
|
|
30
40
|
const onApply = () => {
|
|
31
41
|
onChange(changes);
|
|
32
42
|
onClose();
|
|
33
43
|
};
|
|
34
|
-
const handleOnChange =
|
|
35
|
-
setChanges(prev => (
|
|
36
|
-
...prev,
|
|
37
|
-
...value
|
|
38
|
-
}));
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// Merge original data with local changes for display
|
|
42
|
-
const displayData = {
|
|
43
|
-
...data,
|
|
44
|
-
...changes
|
|
44
|
+
const handleOnChange = newValue => {
|
|
45
|
+
setChanges(prev => (0, _deepmerge.default)(prev, newValue));
|
|
45
46
|
};
|
|
46
47
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Modal, {
|
|
47
48
|
className: "dataforms-layouts-panel__modal",
|
|
@@ -50,13 +51,13 @@ function ModalContent({
|
|
|
50
51
|
title: fieldLabel,
|
|
51
52
|
size: "medium",
|
|
52
53
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_dataFormLayout.DataFormLayout, {
|
|
53
|
-
data:
|
|
54
|
+
data: modalData,
|
|
54
55
|
form: form,
|
|
55
56
|
onChange: handleOnChange,
|
|
56
57
|
children: (FieldLayout, nestedField) => {
|
|
57
58
|
var _form$fields;
|
|
58
59
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(FieldLayout, {
|
|
59
|
-
data:
|
|
60
|
+
data: modalData,
|
|
60
61
|
field: nestedField,
|
|
61
62
|
onChange: handleOnChange,
|
|
62
63
|
hideLabelFromVision: ((_form$fields = form?.fields) !== null && _form$fields !== void 0 ? _form$fields : []).length < 2
|
|
@@ -81,6 +82,7 @@ function ModalContent({
|
|
|
81
82
|
}
|
|
82
83
|
function PanelModal({
|
|
83
84
|
fieldDefinition,
|
|
85
|
+
summaryFields,
|
|
84
86
|
labelPosition,
|
|
85
87
|
data,
|
|
86
88
|
onChange,
|
|
@@ -97,21 +99,14 @@ function PanelModal({
|
|
|
97
99
|
}]
|
|
98
100
|
}), [field]);
|
|
99
101
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
100
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
"aria-label": (0, _i18n.sprintf)(
|
|
106
|
-
// translators: %s: Field name.
|
|
107
|
-
(0, _i18n._x)('Edit %s', 'field'), fieldLabel || ''),
|
|
108
|
-
onClick: () => setIsOpen(true),
|
|
102
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_summaryButton.default, {
|
|
103
|
+
summaryFields: summaryFields,
|
|
104
|
+
data: data,
|
|
105
|
+
labelPosition: labelPosition,
|
|
106
|
+
fieldLabel: fieldLabel,
|
|
109
107
|
disabled: fieldDefinition.readOnly === true,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
item: data,
|
|
113
|
-
field: fieldDefinition
|
|
114
|
-
})
|
|
108
|
+
onClick: () => setIsOpen(true),
|
|
109
|
+
"aria-expanded": isOpen
|
|
115
110
|
}), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(ModalContent, {
|
|
116
111
|
data: data,
|
|
117
112
|
form: form,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_deepmerge","_interopRequireDefault","require","_components","_i18n","_element","_dataFormLayout","_isCombinedField","_normalizeFormFields","_summaryButton","_jsxRuntime","ModalContent","data","form","fieldLabel","onChange","onClose","changes","setChanges","useState","modalData","useMemo","deepMerge","onApply","handleOnChange","newValue","prev","jsxs","Modal","className","onRequestClose","isFullScreen","title","size","children","jsx","DataFormLayout","FieldLayout","nestedField","_form$fields","field","hideLabelFromVision","fields","length","id","__experimentalHStack","spacing","__experimentalSpacer","Button","variant","onClick","__next40pxDefaultSize","__","PanelModal","fieldDefinition","summaryFields","labelPosition","isOpen","setIsOpen","isCombinedField","label","layout","DEFAULT_LAYOUT","Fragment","default","disabled","readOnly","_default","exports"],"sources":["@wordpress/dataviews/src/dataforms-layouts/panel/modal.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalSpacer as Spacer,\n\tButton,\n\tModal,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { Form, FormField, NormalizedField } from '../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { isCombinedField } from '../is-combined-field';\nimport { DEFAULT_LAYOUT } from '../../normalize-form-fields';\nimport SummaryButton from './summary-button';\n\nfunction ModalContent< Item >( {\n\tdata,\n\tform,\n\tfieldLabel,\n\tonChange,\n\tonClose,\n}: {\n\tdata: Item;\n\tform: Form;\n\tfieldLabel: string;\n\tonChange: ( data: Partial< Item > ) => void;\n\tonClose: () => void;\n} ) {\n\tconst [ changes, setChanges ] = useState< Partial< Item > >( {} );\n\tconst modalData = useMemo( () => {\n\t\treturn deepMerge( data, changes );\n\t}, [ data, changes ] );\n\n\tconst onApply = () => {\n\t\tonChange( changes );\n\t\tonClose();\n\t};\n\n\tconst handleOnChange = ( newValue: Partial< Item > ) => {\n\t\tsetChanges( ( prev ) => deepMerge( prev, newValue ) );\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"dataforms-layouts-panel__modal\"\n\t\t\tonRequestClose={ onClose }\n\t\t\tisFullScreen={ false }\n\t\t\ttitle={ fieldLabel }\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<DataFormLayout\n\t\t\t\tdata={ modalData }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ handleOnChange }\n\t\t\t>\n\t\t\t\t{ ( FieldLayout, nestedField ) => (\n\t\t\t\t\t<FieldLayout\n\t\t\t\t\t\tkey={ nestedField.id }\n\t\t\t\t\t\tdata={ modalData }\n\t\t\t\t\t\tfield={ nestedField }\n\t\t\t\t\t\tonChange={ handleOnChange }\n\t\t\t\t\t\thideLabelFromVision={\n\t\t\t\t\t\t\t( form?.fields ?? [] ).length < 2\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</DataFormLayout>\n\t\t\t<HStack\n\t\t\t\tclassName=\"dataforms-layouts-panel__modal-footer\"\n\t\t\t\tspacing={ 3 }\n\t\t\t>\n\t\t\t\t<Spacer />\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</Button>\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\tonClick={ onApply }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Apply' ) }\n\t\t\t\t</Button>\n\t\t\t</HStack>\n\t\t</Modal>\n\t);\n}\n\nfunction PanelModal< Item >( {\n\tfieldDefinition,\n\tsummaryFields,\n\tlabelPosition,\n\tdata,\n\tonChange,\n\tfield,\n}: {\n\tfieldDefinition: NormalizedField< Item >;\n\tsummaryFields: NormalizedField< Item >[];\n\tlabelPosition: 'side' | 'top' | 'none';\n\tdata: Item;\n\tonChange: ( value: any ) => void;\n\tfield: FormField;\n} ) {\n\tconst [ isOpen, setIsOpen ] = useState( false );\n\n\tconst fieldLabel = isCombinedField( field )\n\t\t? field.label\n\t\t: fieldDefinition?.label;\n\n\tconst form: Form = useMemo(\n\t\t(): Form => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: isCombinedField( field )\n\t\t\t\t? field.children\n\t\t\t\t: // If not explicit children return the field id itself.\n\t\t\t\t [ { id: field.id } ],\n\t\t} ),\n\t\t[ field ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<SummaryButton\n\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\tdata={ data }\n\t\t\t\tlabelPosition={ labelPosition }\n\t\t\t\tfieldLabel={ fieldLabel }\n\t\t\t\tdisabled={ fieldDefinition.readOnly === true }\n\t\t\t\tonClick={ () => setIsOpen( true ) }\n\t\t\t\taria-expanded={ isOpen }\n\t\t\t/>\n\t\t\t{ isOpen && (\n\t\t\t\t<ModalContent\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tform={ form as Form }\n\t\t\t\t\tfieldLabel={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GAAI,EAAI;MAC/BC,QAAQ,EAAGA,QAAU;MACrBC,OAAO,EAAGA,CAAA,KAAM0C,SAAS,CAAE,KAAM;IAAG,CACpC,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAAS,QAAA,GAAAC,OAAA,CAAAJ,OAAA,GAEcX,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _components = require("@wordpress/components");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function SummaryButton({
|
|
19
|
+
summaryFields,
|
|
20
|
+
data,
|
|
21
|
+
labelPosition,
|
|
22
|
+
fieldLabel,
|
|
23
|
+
disabled,
|
|
24
|
+
onClick,
|
|
25
|
+
'aria-expanded': ariaExpanded
|
|
26
|
+
}) {
|
|
27
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
28
|
+
className: "dataforms-layouts-panel__summary-button",
|
|
29
|
+
size: "compact",
|
|
30
|
+
variant: ['none', 'top'].includes(labelPosition) ? 'link' : 'tertiary',
|
|
31
|
+
"aria-expanded": ariaExpanded,
|
|
32
|
+
"aria-label": (0, _i18n.sprintf)(
|
|
33
|
+
// translators: %s: Field name.
|
|
34
|
+
(0, _i18n._x)('Edit %s', 'field'), fieldLabel || ''),
|
|
35
|
+
onClick: onClick,
|
|
36
|
+
disabled: disabled,
|
|
37
|
+
accessibleWhenDisabled: true,
|
|
38
|
+
style: summaryFields.length > 1 ? {
|
|
39
|
+
minHeight: 'auto',
|
|
40
|
+
height: 'auto',
|
|
41
|
+
alignItems: 'flex-start'
|
|
42
|
+
} : undefined,
|
|
43
|
+
children: summaryFields.length > 1 ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
44
|
+
style: {
|
|
45
|
+
display: 'flex',
|
|
46
|
+
flexDirection: 'column',
|
|
47
|
+
alignItems: 'flex-start',
|
|
48
|
+
width: '100%',
|
|
49
|
+
gap: '2px'
|
|
50
|
+
},
|
|
51
|
+
children: summaryFields.map(summaryField => /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
52
|
+
style: {
|
|
53
|
+
width: '100%'
|
|
54
|
+
},
|
|
55
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(summaryField.render, {
|
|
56
|
+
item: data,
|
|
57
|
+
field: summaryField
|
|
58
|
+
})
|
|
59
|
+
}, summaryField.id))
|
|
60
|
+
}) : summaryFields.map(summaryField => /*#__PURE__*/(0, _jsxRuntime.jsx)(summaryField.render, {
|
|
61
|
+
item: data,
|
|
62
|
+
field: summaryField
|
|
63
|
+
}, summaryField.id))
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
var _default = exports.default = SummaryButton;
|
|
67
|
+
//# sourceMappingURL=summary-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_jsxRuntime","SummaryButton","summaryFields","data","labelPosition","fieldLabel","disabled","onClick","ariaExpanded","jsx","Button","className","size","variant","includes","sprintf","_x","accessibleWhenDisabled","style","length","minHeight","height","alignItems","undefined","children","display","flexDirection","width","gap","map","summaryField","render","item","field","id","_default","exports","default"],"sources":["@wordpress/dataviews/src/dataforms-layouts/panel/summary-button.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { sprintf, _x } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { NormalizedField } from '../../types';\n\nfunction SummaryButton< Item >( {\n\tsummaryFields,\n\tdata,\n\tlabelPosition,\n\tfieldLabel,\n\tdisabled,\n\tonClick,\n\t'aria-expanded': ariaExpanded,\n}: {\n\tsummaryFields: NormalizedField< Item >[];\n\tdata: Item;\n\tlabelPosition: 'side' | 'top' | 'none';\n\tfieldLabel?: string;\n\tdisabled?: boolean;\n\tonClick: () => void;\n\t'aria-expanded'?: boolean;\n} ) {\n\treturn (\n\t\t<Button\n\t\t\tclassName=\"dataforms-layouts-panel__summary-button\"\n\t\t\tsize=\"compact\"\n\t\t\tvariant={\n\t\t\t\t[ 'none', 'top' ].includes( labelPosition )\n\t\t\t\t\t? 'link'\n\t\t\t\t\t: 'tertiary'\n\t\t\t}\n\t\t\taria-expanded={ ariaExpanded }\n\t\t\taria-label={ sprintf(\n\t\t\t\t// translators: %s: Field name.\n\t\t\t\t_x( 'Edit %s', 'field' ),\n\t\t\t\tfieldLabel || ''\n\t\t\t) }\n\t\t\tonClick={ onClick }\n\t\t\tdisabled={ disabled }\n\t\t\taccessibleWhenDisabled\n\t\t\tstyle={\n\t\t\t\tsummaryFields.length > 1\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tminHeight: 'auto',\n\t\t\t\t\t\t\theight: 'auto',\n\t\t\t\t\t\t\talignItems: 'flex-start',\n\t\t\t\t\t }\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t>\n\t\t\t{ summaryFields.length > 1 ? (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\t\tflexDirection: 'column',\n\t\t\t\t\t\talignItems: 'flex-start',\n\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\tgap: '2px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ summaryFields.map( ( summaryField ) => (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t) : (\n\t\t\t\tsummaryFields.map( ( summaryField ) => (\n\t\t\t\t\t<summaryField.render\n\t\t\t\t\t\tkey={ summaryField.id }\n\t\t\t\t\t\titem={ data }\n\t\t\t\t\t\tfield={ summaryField }\n\t\t\t\t\t/>\n\t\t\t\t) )\n\t\t\t) }\n\t\t</Button>\n\t);\n}\n\nexport default SummaryButton;\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAA8C,IAAAE,WAAA,GAAAF,OAAA;AAJ9C;AACA;AACA;;AAIA;AACA;AACA;;AAGA,SAASG,aAAaA,CAAU;EAC/BC,aAAa;EACbC,IAAI;EACJC,aAAa;EACbC,UAAU;EACVC,QAAQ;EACRC,OAAO;EACP,eAAe,EAAEC;AASlB,CAAC,EAAG;EACH,oBACC,IAAAR,WAAA,CAAAS,GAAA,EAACZ,WAAA,CAAAa,MAAM;IACNC,SAAS,EAAC,yCAAyC;IACnDC,IAAI,EAAC,SAAS;IACdC,OAAO,EACN,CAAE,MAAM,EAAE,KAAK,CAAE,CAACC,QAAQ,CAAEV,aAAc,CAAC,GACxC,MAAM,GACN,UACH;IACD,iBAAgBI,YAAc;IAC9B,cAAa,IAAAO,aAAO;IACnB;IACA,IAAAC,QAAE,EAAE,SAAS,EAAE,OAAQ,CAAC,EACxBX,UAAU,IAAI,EACf,CAAG;IACHE,OAAO,EAAGA,OAAS;IACnBD,QAAQ,EAAGA,QAAU;IACrBW,sBAAsB;IACtBC,KAAK,EACJhB,aAAa,CAACiB,MAAM,GAAG,CAAC,GACrB;MACAC,SAAS,EAAE,MAAM;MACjBC,MAAM,EAAE,MAAM;MACdC,UAAU,EAAE;IACZ,CAAC,GACDC,SACH;IAAAC,QAAA,EAECtB,aAAa,CAACiB,MAAM,GAAG,CAAC,gBACzB,IAAAnB,WAAA,CAAAS,GAAA;MACCS,KAAK,EAAG;QACPO,OAAO,EAAE,MAAM;QACfC,aAAa,EAAE,QAAQ;QACvBJ,UAAU,EAAE,YAAY;QACxBK,KAAK,EAAE,MAAM;QACbC,GAAG,EAAE;MACN,CAAG;MAAAJ,QAAA,EAEDtB,aAAa,CAAC2B,GAAG,CAAIC,YAAY,iBAClC,IAAA9B,WAAA,CAAAS,GAAA;QAECS,KAAK,EAAG;UAAES,KAAK,EAAE;QAAO,CAAG;QAAAH,QAAA,eAE3B,IAAAxB,WAAA,CAAAS,GAAA,EAACqB,YAAY,CAACC,MAAM;UACnBC,IAAI,EAAG7B,IAAM;UACb8B,KAAK,EAAGH;QAAc,CACtB;MAAC,GANIA,YAAY,CAACI,EAOf,CACJ;IAAC,CACC,CAAC,GAENhC,aAAa,CAAC2B,GAAG,CAAIC,YAAY,iBAChC,IAAA9B,WAAA,CAAAS,GAAA,EAACqB,YAAY,CAACC,MAAM;MAEnBC,IAAI,EAAG7B,IAAM;MACb8B,KAAK,EAAGH;IAAc,GAFhBA,YAAY,CAACI,EAGnB,CACA;EACF,CACM,CAAC;AAEX;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcpC,aAAa","ignoreList":[]}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.normalizeFields = normalizeFields;
|
|
8
|
+
exports.setValueFromId = void 0;
|
|
8
9
|
var _fieldTypes = _interopRequireDefault(require("./field-types"));
|
|
9
10
|
var _dataformControls = require("./dataform-controls");
|
|
10
11
|
var _constants = require("./constants");
|
|
@@ -30,6 +31,20 @@ const getValueFromId = id => ({
|
|
|
30
31
|
}
|
|
31
32
|
return value;
|
|
32
33
|
};
|
|
34
|
+
const setValueFromId = id => ({
|
|
35
|
+
value
|
|
36
|
+
}) => {
|
|
37
|
+
const path = id.split('.');
|
|
38
|
+
const result = {};
|
|
39
|
+
let current = result;
|
|
40
|
+
for (const segment of path.slice(0, -1)) {
|
|
41
|
+
current[segment] = {};
|
|
42
|
+
current = current[segment];
|
|
43
|
+
}
|
|
44
|
+
current[path.at(-1)] = value;
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
exports.setValueFromId = setValueFromId;
|
|
33
48
|
function getFilterBy(field, fieldTypeDefinition) {
|
|
34
49
|
if (field.filterBy === false) {
|
|
35
50
|
return false;
|
|
@@ -97,6 +112,7 @@ function normalizeFields(fields) {
|
|
|
97
112
|
var _field$sort, _field$render, _field$enableHiding, _ref, _field$enableSorting, _ref2, _field$readOnly;
|
|
98
113
|
const fieldTypeDefinition = (0, _fieldTypes.default)(field.type);
|
|
99
114
|
const getValue = field.getValue || getValueFromId(field.id);
|
|
115
|
+
const setValue = field.setValue || setValueFromId(field.id);
|
|
100
116
|
const sort = (_field$sort = field.sort) !== null && _field$sort !== void 0 ? _field$sort : function sort(a, b, direction) {
|
|
101
117
|
return fieldTypeDefinition.sort(getValue({
|
|
102
118
|
item: a
|
|
@@ -124,6 +140,7 @@ function normalizeFields(fields) {
|
|
|
124
140
|
label: field.label || field.id,
|
|
125
141
|
header: field.header || field.label || field.id,
|
|
126
142
|
getValue,
|
|
143
|
+
setValue,
|
|
127
144
|
render,
|
|
128
145
|
sort,
|
|
129
146
|
isValid,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fieldTypes","_interopRequireDefault","require","_dataformControls","_constants","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","getFilterBy","field","fieldTypeDefinition","filterBy","operators","Array","isArray","defaultOperators","validOperators","ALL_OPERATORS","filter","operator","includes","elements","OPERATOR_BETWEEN","hasSingleSelectionOperator","some","SINGLE_SELECTION_OPERATORS","length","isPrimary","normalizeFields","fields","map","_field$sort","_field$render","_field$enableHiding","_ref","_field$enableSorting","_ref2","_field$readOnly","getFieldTypeDefinition","type","getValue","sort","a","b","direction","isValid","Edit","getControl","render","renderedField","label","header","enableHiding","enableSorting","readOnly"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type {\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from './types';\nimport { getControl } from './dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from './constants';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( field.elements && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif ( field.elements && defaultOperators.includes( OPERATOR_BETWEEN ) ) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid = {\n\t\t\t...fieldTypeDefinition.isValid,\n\t\t\t...field.isValid,\n\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting:\n\t\t\t\tfield.enableSorting ??\n\t\t\t\tfieldTypeDefinition.enableSorting ??\n\t\t\t\ttrue,\n\t\t\tfilterBy,\n\t\t\treadOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;AAQA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA,MAAMG,cAAc,GACjBC,EAAU,IACZ,CAAE;EAAEC;AAAoB,CAAC,KAAM;EAC9B,MAAMC,IAAI,GAAGF,EAAE,CAACG,KAAK,CAAE,GAAI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IAAAC,oBAAA,GACZ1B,KAAK,CAAC4C,aAAa,cAAAlB,oBAAA,cAAAA,oBAAA,GACnBzB,mBAAmB,CAAC2C,aAAa,cAAAnB,IAAA,cAAAA,IAAA,GACjC,IAAI;MACLvB,QAAQ;MACR2C,QAAQ,GAAAlB,KAAA,IAAAC,eAAA,GAAE5B,KAAK,CAAC6C,QAAQ,cAAAjB,eAAA,cAAAA,eAAA,GAAI3B,mBAAmB,CAAC4C,QAAQ,cAAAlB,KAAA,cAAAA,KAAA,GAAI;IAC7D,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_fieldTypes","_interopRequireDefault","require","_dataformControls","_constants","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","setValueFromId","result","current","slice","at","exports","getFilterBy","field","fieldTypeDefinition","filterBy","operators","Array","isArray","defaultOperators","validOperators","ALL_OPERATORS","filter","operator","includes","elements","OPERATOR_BETWEEN","hasSingleSelectionOperator","some","SINGLE_SELECTION_OPERATORS","length","isPrimary","normalizeFields","fields","map","_field$sort","_field$render","_field$enableHiding","_ref","_field$enableSorting","_ref2","_field$readOnly","getFieldTypeDefinition","type","getValue","setValue","sort","a","b","direction","isValid","Edit","getControl","render","renderedField","label","header","enableHiding","enableSorting","readOnly"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type {\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from './types';\nimport { getControl } from './dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from './constants';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nexport const setValueFromId =\n\t( id: string ) =>\n\t( { value }: { value: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tconst result: any = {};\n\t\tlet current = result;\n\n\t\tfor ( const segment of path.slice( 0, -1 ) ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t\tcurrent = current[ segment ];\n\t\t}\n\n\t\tcurrent[ path.at( -1 )! ] = value;\n\t\treturn result;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( field.elements && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif ( field.elements && defaultOperators.includes( OPERATOR_BETWEEN ) ) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\t\tconst setValue = field.setValue || setValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid = {\n\t\t\t...fieldTypeDefinition.isValid,\n\t\t\t...field.isValid,\n\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\tsetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting:\n\t\t\t\tfield.enableSorting ??\n\t\t\t\tfieldTypeDefinition.enableSorting ??\n\t\t\t\ttrue,\n\t\t\tfilterBy,\n\t\t\treadOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;;AAQA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA,MAAMG,cAAc,GACjBC,EAAU,IACZ,CAAE;EAAEC;AAAoB,CAAC,KAAM;EAC9B,MAAMC,IAAI,GAAGF,EAAE,CAACG,KAAK,CAAE,GAAI,CAAC;EAC5B,IAAIC,KAAK,GAAGH,IAAI;EAChB,KAAM,MAAMI,OAAO,IAAIH,IAAI,EAAG;IAC7B,IAAKE,KAAK,CAACE,cAAc,CAAED,OAAQ,CAAC,EAAG;MACtCD,KAAK,GAAGA,KAAK,CAAEC,OAAO,CAAE;IACzB,C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AAMvC,QAAQ,GAAGH,WAAW,CAAEC,KAAK,EAAEC,mBAAoB,CAAC;IAE1D,OAAO;MACN,GAAGD,KAAK;MACR0C,KAAK,EAAE1C,KAAK,CAAC0C,KAAK,IAAI1C,KAAK,CAACf,EAAE;MAC9B0D,MAAM,EAAE3C,KAAK,CAAC2C,MAAM,IAAI3C,KAAK,CAAC0C,KAAK,IAAI1C,KAAK,CAACf,EAAE;MAC/C8C,QAAQ;MACRC,QAAQ;MACRQ,MAAM;MACNP,IAAI;MACJI,OAAO;MACPC,IAAI;MACJM,YAAY,GAAApB,mBAAA,GAAExB,KAAK,CAAC4C,YAAY,cAAApB,mBAAA,cAAAA,mBAAA,GAAI,IAAI;MACxCqB,aAAa,GAAApB,IAAA,IAAAC,oBAAA,GACZ1B,KAAK,CAAC6C,aAAa,cAAAnB,oBAAA,cAAAA,oBAAA,GACnBzB,mBAAmB,CAAC4C,aAAa,cAAApB,IAAA,cAAAA,IAAA,GACjC,IAAI;MACLvB,QAAQ;MACR4C,QAAQ,GAAAnB,KAAA,IAAAC,eAAA,GAAE5B,KAAK,CAAC8C,QAAQ,cAAAlB,eAAA,cAAAA,eAAA,GAAI3B,mBAAmB,CAAC6C,QAAQ,cAAAnB,KAAA,cAAAA,KAAA,GAAI;IAC7D,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tReactElement,\n\tReactNode,\n\tComponentType,\n\tComponentProps,\n} from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport interface NormalizedFilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: Rules< Item >;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit: ComponentType< DataFormControlProps< Item > > | string | null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\tcustom?: ( item: Item, field: NormalizedField< Item > ) => null | string;\n};\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field is filterable.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n};\n\nexport type NormalizedField< Item > = Omit< Field< Item >, 'Edit' > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: Rules< Item >;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: NormalizedFilterByConfig | false;\n\treadOnly: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: Record< string, any > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n\tconfig?: {\n\t\tsizes: string;\n\t};\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked?: boolean;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The field to group by.\n\t */\n\tgroupByField?: string;\n\n\t/**\n\t * Whether infinite scroll is enabled.\n\t */\n\tinfiniteScrollEnabled?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerGrid extends ViewBase {\n\ttype: 'pickerGrid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable | ViewPickerGrid;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n\tempty: ReactNode;\n}\n\nexport type ViewPickerBaseProps< Item > = Omit<\n\tViewBaseProps< Item >,\n\t| 'view'\n\t| 'onChangeView'\n\t// The following props are not supported for pickers.\n\t| 'isItemClickable'\n\t| 'onClickItem'\n\t| 'renderItemLink'\n\t| 'getItemLevel'\n> & {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n};\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport interface ViewPickerGridProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport type ViewPickerProps< Item > = ViewPickerGridProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n\tpickerGrid?: Omit< ViewPickerGrid, 'type' >;\n}\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n};\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n};\n\nexport type Layout = RegularLayout | PanelLayout | CardLayout | RowLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout\n\t| NormalizedRowLayout;\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: Layout;\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tdescription?: string;\n\tlayout?: Layout;\n\tchildren: Array< FormField | string >;\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\tlayout?: Layout;\n\tfields?: Array< FormField | string >;\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tReactElement,\n\tReactNode,\n\tComponentType,\n\tComponentProps,\n} from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Utility type that makes all properties of T optional recursively.\n * Used by field setValue functions to allow partial item updates.\n */\nexport type DeepPartial< T > = {\n\t[ P in keyof T ]?: T[ P ] extends object ? DeepPartial< T[ P ] > : T[ P ];\n};\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport interface NormalizedFilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: Rules< Item >;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit:\n\t\t| ComponentType< DataFormControlProps< Item > >\n\t\t| string\n\t\t| EditConfig\n\t\t| null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\tcustom?: ( item: Item, field: NormalizedField< Item > ) => null | string;\n};\n\n/**\n * Edit configuration for textarea controls.\n */\nexport type EditConfigTextarea = {\n\tcontrol: 'textarea';\n\t/**\n\t * Number of rows for the textarea.\n\t */\n\trows?: number;\n};\n\n/**\n * Edit configuration for text controls.\n */\nexport type EditConfigText = {\n\tcontrol: 'text';\n\t/**\n\t * Prefix component to display before the input.\n\t */\n\tprefix?: React.ComponentType;\n\t/**\n\t * Suffix component to display after the input.\n\t */\n\tsuffix?: React.ComponentType;\n};\n\n/**\n * Edit configuration for other control types (excluding 'text' and 'textarea').\n */\nexport type EditConfigGeneric = {\n\tcontrol: Exclude< FieldType, 'text' | 'textarea' >;\n};\n\n/**\n * Edit configuration object with type-safe control options.\n * Each control type has its own specific configuration properties.\n */\nexport type EditConfig =\n\t| EditConfigTextarea\n\t| EditConfigText\n\t| EditConfigGeneric;\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string | EditConfig;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field is filterable.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n\n\t/**\n\t * Callback used to set the value of the field on the item.\n\t * Used for editing operations to update field values.\n\t */\n\tsetValue?: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n};\n\nexport type NormalizedField< Item > = Omit< Field< Item >, 'Edit' > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\tsetValue: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: Rules< Item >;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: NormalizedFilterByConfig | false;\n\treadOnly: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: DeepPartial< Item > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n\t/**\n\t * Configuration object for the control.\n\t */\n\tconfig?: {\n\t\tprefix?: React.ComponentType;\n\t\tsuffix?: React.ComponentType;\n\t\trows?: number;\n\t};\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n\tconfig?: {\n\t\tsizes: string;\n\t};\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked?: boolean;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n\n\t/**\n\t * Whether the filter can be edited by the user.\n\t */\n\tisLocked: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The field to group by.\n\t */\n\tgroupByField?: string;\n\n\t/**\n\t * Whether infinite scroll is enabled.\n\t */\n\tinfiniteScrollEnabled?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\n\t\t/**\n\t\t * Whether the view allows column moving.\n\t\t */\n\t\tenableMoving?: boolean;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport interface ViewPickerGrid extends ViewBase {\n\ttype: 'pickerGrid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable | ViewPickerGrid;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n\tempty: ReactNode;\n}\n\nexport type ViewPickerBaseProps< Item > = Omit<\n\tViewBaseProps< Item >,\n\t| 'view'\n\t| 'onChangeView'\n\t// The following props are not supported for pickers.\n\t| 'isItemClickable'\n\t| 'onClickItem'\n\t| 'renderItemLink'\n\t| 'getItemLevel'\n> & {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n};\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport interface ViewPickerGridProps< Item >\n\textends Omit< ViewPickerBaseProps< Item >, 'view' > {\n\tview: ViewPickerGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport type ViewPickerProps< Item > = ViewPickerGridProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n\tpickerGrid?: Omit< ViewPickerGrid, 'type' >;\n}\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n};\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n};\n\nexport type Layout = RegularLayout | PanelLayout | CardLayout | RowLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout\n\t| NormalizedRowLayout;\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: Layout;\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tdescription?: string;\n\tlayout?: Layout;\n\tchildren: Array< FormField | string >;\n\tsummary?: string | string[];\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\tlayout?: Layout;\n\tfields?: Array< FormField | string >;\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -23,12 +23,54 @@ export default function InputWidget({
|
|
|
23
23
|
fields
|
|
24
24
|
}) {
|
|
25
25
|
const currentFilter = view.filters?.find(f => f.field === filter.field);
|
|
26
|
-
const field = fields.find(f => f.id === filter.field);
|
|
27
26
|
const currentValue = getCurrentValue(filter, currentFilter);
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* We are reusing the field.Edit component for filters. By doing so,
|
|
30
|
+
* we get for free a filter control specific to the field type
|
|
31
|
+
* and other aspects of the field API (Edit control configuration, etc.).
|
|
32
|
+
*
|
|
33
|
+
* This approach comes with an issue: the field.Edit controls work with getValue
|
|
34
|
+
* and setValue methods, which take an item (Item) as parameter. But, at this point,
|
|
35
|
+
* we don't have an item and we don't know how to create one, either.
|
|
36
|
+
*
|
|
37
|
+
* So, what we do is to prepare the data and the relevant field configuration
|
|
38
|
+
* as if Item was a plain object whose keys are the field ids:
|
|
39
|
+
*
|
|
40
|
+
* {
|
|
41
|
+
* [ fieldOne.id ]: value,
|
|
42
|
+
* [ fieldTwo.id ]: value,
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
const field = useMemo(() => {
|
|
47
|
+
const currentField = fields.find(f => f.id === filter.field);
|
|
48
|
+
if (currentField) {
|
|
49
|
+
return {
|
|
50
|
+
...currentField,
|
|
51
|
+
// Deactivate validation for filters.
|
|
52
|
+
isValid: {
|
|
53
|
+
required: false,
|
|
54
|
+
custom: () => null
|
|
55
|
+
},
|
|
56
|
+
// Configure getValue/setValue as if Item was a plain object.
|
|
57
|
+
getValue: ({
|
|
58
|
+
item
|
|
59
|
+
}) => item[currentField.id],
|
|
60
|
+
setValue: ({
|
|
61
|
+
value
|
|
62
|
+
}) => ({
|
|
63
|
+
[currentField.id]: value
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return currentField;
|
|
68
|
+
}, [fields, filter.field]);
|
|
28
69
|
const data = useMemo(() => {
|
|
29
70
|
var _view$filters;
|
|
30
|
-
return ((_view$filters = view.filters) !== null && _view$filters !== void 0 ? _view$filters : []).reduce((acc,
|
|
31
|
-
|
|
71
|
+
return ((_view$filters = view.filters) !== null && _view$filters !== void 0 ? _view$filters : []).reduce((acc, activeFilter) => {
|
|
72
|
+
// We can now assume the field is stored as a Item prop.
|
|
73
|
+
acc[activeFilter.field] = activeFilter.value;
|
|
32
74
|
return acc;
|
|
33
75
|
}, {});
|
|
34
76
|
}, [view.filters]);
|
|
@@ -37,7 +79,9 @@ export default function InputWidget({
|
|
|
37
79
|
if (!field || !currentFilter) {
|
|
38
80
|
return;
|
|
39
81
|
}
|
|
40
|
-
const nextValue =
|
|
82
|
+
const nextValue = field.getValue({
|
|
83
|
+
item: updatedData
|
|
84
|
+
});
|
|
41
85
|
if (fastDeepEqual(nextValue, currentValue)) {
|
|
42
86
|
return;
|
|
43
87
|
}
|