@wordpress/dataviews 8.0.1-next.e256d081a.0 → 9.0.1-next.6870dfe5b.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 +24 -1
- package/README.md +96 -1
- package/build/components/dataform-context/index.js +1 -0
- package/build/components/dataform-context/index.js.map +1 -1
- package/build/components/dataviews/index.js +11 -1
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-context/index.js +1 -0
- package/build/components/dataviews-context/index.js.map +1 -1
- package/build/components/dataviews-layout/index.js +2 -1
- package/build/components/dataviews-layout/index.js.map +1 -1
- package/build/components/dataviews-picker/footer.js +145 -0
- package/build/components/dataviews-picker/footer.js.map +1 -0
- package/build/components/dataviews-picker/index.js +201 -0
- package/build/components/dataviews-picker/index.js.map +1 -0
- package/build/components/dataviews-selection-checkbox/index.js +4 -2
- package/build/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +1 -0
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/constants.js +4 -1
- package/build/constants.js.map +1 -1
- package/build/dataform-controls/checkbox.js +23 -2
- package/build/dataform-controls/checkbox.js.map +1 -1
- package/build/dataform-controls/color.js +128 -0
- package/build/dataform-controls/color.js.map +1 -0
- package/build/dataform-controls/email.js +10 -45
- package/build/dataform-controls/email.js.map +1 -1
- package/build/dataform-controls/index.js +8 -2
- package/build/dataform-controls/index.js.map +1 -1
- package/build/dataform-controls/telephone.js +34 -0
- package/build/dataform-controls/telephone.js.map +1 -0
- package/build/dataform-controls/text.js +7 -48
- package/build/dataform-controls/text.js.map +1 -1
- package/build/dataform-controls/{boolean.js → toggle.js} +6 -4
- package/build/dataform-controls/toggle.js.map +1 -0
- package/build/dataform-controls/url.js +34 -0
- package/build/dataform-controls/url.js.map +1 -0
- package/build/dataform-controls/utils/validated-text.js +76 -0
- package/build/dataform-controls/utils/validated-text.js.map +1 -0
- package/build/dataforms-layouts/card/index.js +6 -7
- package/build/dataforms-layouts/card/index.js.map +1 -1
- package/build/dataforms-layouts/data-form-layout.js +16 -4
- package/build/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build/dataforms-layouts/index.js +31 -1
- package/build/dataforms-layouts/index.js.map +1 -1
- package/build/dataforms-layouts/row/index.js +113 -0
- package/build/dataforms-layouts/row/index.js.map +1 -0
- package/build/dataviews-layouts/grid/index.js +16 -11
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/index.js +9 -1
- package/build/dataviews-layouts/index.js.map +1 -1
- package/build/dataviews-layouts/picker-grid/index.js +357 -0
- package/build/dataviews-layouts/picker-grid/index.js.map +1 -0
- package/build/dataviews-layouts/utils/grid-items.js +37 -0
- package/build/dataviews-layouts/utils/grid-items.js.map +1 -0
- package/build/dataviews-layouts/utils/preview-size-picker.js +81 -0
- package/build/dataviews-layouts/utils/preview-size-picker.js.map +1 -0
- package/build/field-types/boolean.js +1 -1
- package/build/field-types/boolean.js.map +1 -1
- package/build/field-types/color.js +113 -0
- package/build/field-types/color.js.map +1 -0
- package/build/field-types/index.js +12 -0
- package/build/field-types/index.js.map +1 -1
- package/build/field-types/telephone.js +57 -0
- package/build/field-types/telephone.js.map +1 -0
- package/build/field-types/url.js +57 -0
- package/build/field-types/url.js.map +1 -0
- package/build/normalize-form-fields.js +6 -0
- package/build/normalize-form-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/validation.js +1 -1
- package/build/validation.js.map +1 -1
- package/build-module/components/dataform-context/index.js +1 -0
- package/build-module/components/dataform-context/index.js.map +1 -1
- package/build-module/components/dataviews/index.js +11 -1
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-context/index.js +1 -0
- package/build-module/components/dataviews-context/index.js.map +1 -1
- package/build-module/components/dataviews-layout/index.js +2 -1
- package/build-module/components/dataviews-layout/index.js.map +1 -1
- package/build-module/components/dataviews-picker/footer.js +136 -0
- package/build-module/components/dataviews-picker/footer.js.map +1 -0
- package/build-module/components/dataviews-picker/index.js +191 -0
- package/build-module/components/dataviews-picker/index.js.map +1 -0
- package/build-module/components/dataviews-selection-checkbox/index.js +4 -2
- package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +1 -0
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/constants.js +3 -0
- package/build-module/constants.js.map +1 -1
- package/build-module/dataform-controls/checkbox.js +25 -3
- package/build-module/dataform-controls/checkbox.js.map +1 -1
- package/build-module/dataform-controls/color.js +122 -0
- package/build-module/dataform-controls/color.js.map +1 -0
- package/build-module/dataform-controls/email.js +9 -45
- package/build-module/dataform-controls/email.js.map +1 -1
- package/build-module/dataform-controls/index.js +8 -2
- package/build-module/dataform-controls/index.js.map +1 -1
- package/build-module/dataform-controls/telephone.js +27 -0
- package/build-module/dataform-controls/telephone.js.map +1 -0
- package/build-module/dataform-controls/text.js +6 -48
- package/build-module/dataform-controls/text.js.map +1 -1
- package/build-module/dataform-controls/{boolean.js → toggle.js} +5 -3
- package/build-module/dataform-controls/toggle.js.map +1 -0
- package/build-module/dataform-controls/url.js +27 -0
- package/build-module/dataform-controls/url.js.map +1 -0
- package/build-module/dataform-controls/utils/validated-text.js +70 -0
- package/build-module/dataform-controls/utils/validated-text.js.map +1 -0
- package/build-module/dataforms-layouts/card/index.js +6 -7
- package/build-module/dataforms-layouts/card/index.js.map +1 -1
- package/build-module/dataforms-layouts/data-form-layout.js +14 -4
- package/build-module/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build-module/dataforms-layouts/index.js +32 -1
- package/build-module/dataforms-layouts/index.js.map +1 -1
- package/build-module/dataforms-layouts/row/index.js +106 -0
- package/build-module/dataforms-layouts/row/index.js.map +1 -0
- package/build-module/dataviews-layouts/grid/index.js +16 -11
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/index.js +10 -2
- package/build-module/dataviews-layouts/index.js.map +1 -1
- package/build-module/dataviews-layouts/picker-grid/index.js +348 -0
- package/build-module/dataviews-layouts/picker-grid/index.js.map +1 -0
- package/build-module/dataviews-layouts/utils/grid-items.js +29 -0
- package/build-module/dataviews-layouts/utils/grid-items.js.map +1 -0
- package/build-module/dataviews-layouts/utils/preview-size-picker.js +73 -0
- package/build-module/dataviews-layouts/utils/preview-size-picker.js.map +1 -0
- package/build-module/field-types/boolean.js +1 -1
- package/build-module/field-types/boolean.js.map +1 -1
- package/build-module/field-types/color.js +107 -0
- package/build-module/field-types/color.js.map +1 -0
- package/build-module/field-types/index.js +12 -0
- package/build-module/field-types/index.js.map +1 -1
- package/build-module/field-types/telephone.js +51 -0
- package/build-module/field-types/telephone.js.map +1 -0
- package/build-module/field-types/url.js +51 -0
- package/build-module/field-types/url.js.map +1 -0
- package/build-module/normalize-form-fields.js +6 -0
- package/build-module/normalize-form-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/validation.js +1 -1
- package/build-module/validation.js.map +1 -1
- package/build-style/style-rtl.css +252 -12
- package/build-style/style.css +252 -12
- package/build-types/components/dataform/stories/index.story.d.ts +19 -4
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataform-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews/index.d.ts +1 -1
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +1 -0
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
- package/build-types/components/dataviews-picker/footer.d.ts +4 -0
- package/build-types/components/dataviews-picker/footer.d.ts.map +1 -0
- package/build-types/components/dataviews-picker/index.d.ts +55 -0
- package/build-types/components/dataviews-picker/index.d.ts.map +1 -0
- package/build-types/components/dataviews-picker/stories/index.story.d.ts +42 -0
- package/build-types/components/dataviews-picker/stories/index.story.d.ts.map +1 -0
- package/build-types/components/dataviews-selection-checkbox/index.d.ts +2 -1
- package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/constants.d.ts +1 -0
- package/build-types/constants.d.ts.map +1 -1
- package/build-types/dataform-controls/checkbox.d.ts.map +1 -1
- package/build-types/dataform-controls/color.d.ts +6 -0
- package/build-types/dataform-controls/color.d.ts.map +1 -0
- 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/telephone.d.ts +6 -0
- package/build-types/dataform-controls/telephone.d.ts.map +1 -0
- package/build-types/dataform-controls/text.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle.d.ts +6 -0
- package/build-types/dataform-controls/toggle.d.ts.map +1 -0
- package/build-types/dataform-controls/url.d.ts +6 -0
- package/build-types/dataform-controls/url.d.ts.map +1 -0
- package/build-types/dataform-controls/utils/validated-text.d.ts +16 -0
- package/build-types/dataform-controls/utils/validated-text.d.ts.map +1 -0
- package/build-types/dataforms-layouts/card/index.d.ts +0 -3
- package/build-types/dataforms-layouts/card/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/data-form-layout.d.ts +4 -1
- package/build-types/dataforms-layouts/data-form-layout.d.ts.map +1 -1
- package/build-types/dataforms-layouts/index.d.ts +10 -0
- package/build-types/dataforms-layouts/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/row/index.d.ts +6 -0
- package/build-types/dataforms-layouts/row/index.d.ts.map +1 -0
- package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/index.d.ts +12 -1
- package/build-types/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/picker-grid/index.d.ts +4 -0
- package/build-types/dataviews-layouts/picker-grid/index.d.ts.map +1 -0
- package/build-types/dataviews-layouts/utils/grid-items.d.ts +5 -0
- package/build-types/dataviews-layouts/utils/grid-items.d.ts.map +1 -0
- package/build-types/dataviews-layouts/utils/preview-size-picker.d.ts +2 -0
- package/build-types/dataviews-layouts/utils/preview-size-picker.d.ts.map +1 -0
- package/build-types/field-types/color.d.ts +20 -0
- package/build-types/field-types/color.d.ts.map +1 -0
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/stories/index.story.d.ts +81 -0
- package/build-types/field-types/stories/index.story.d.ts.map +1 -0
- package/build-types/field-types/telephone.d.ts +20 -0
- package/build-types/field-types/telephone.d.ts.map +1 -0
- package/build-types/field-types/url.d.ts +20 -0
- package/build-types/field-types/url.d.ts.map +1 -0
- package/build-types/normalize-form-fields.d.ts.map +1 -1
- package/build-types/test/dataviews-picker.d.ts +2 -0
- package/build-types/test/dataviews-picker.d.ts.map +1 -0
- package/build-types/types.d.ts +36 -5
- package/build-types/types.d.ts.map +1 -1
- package/build-types/validation.d.ts.map +1 -1
- package/build-wp/index.js +5061 -4013
- package/package.json +16 -15
- package/src/components/dataform/stories/index.story.tsx +333 -11
- package/src/components/dataform-context/index.tsx +1 -0
- package/src/components/dataviews/index.tsx +25 -1
- package/src/components/dataviews/stories/fixtures.tsx +1 -1
- package/src/components/dataviews/stories/index.story.tsx +14 -0
- package/src/components/dataviews/style.scss +4 -2
- package/src/components/dataviews-context/index.ts +3 -0
- package/src/components/dataviews-layout/index.tsx +4 -2
- package/src/components/dataviews-picker/footer.tsx +207 -0
- package/src/components/dataviews-picker/index.tsx +284 -0
- package/src/components/dataviews-picker/stories/index.story.tsx +251 -0
- package/src/components/dataviews-picker/style.scss +10 -0
- package/src/components/dataviews-selection-checkbox/index.tsx +3 -0
- package/src/components/dataviews-view-config/index.tsx +1 -0
- package/src/constants.ts +3 -0
- package/src/dataform-controls/checkbox.tsx +33 -3
- package/src/dataform-controls/color.tsx +139 -0
- package/src/dataform-controls/email.tsx +10 -52
- package/src/dataform-controls/index.tsx +8 -2
- package/src/dataform-controls/telephone.tsx +30 -0
- package/src/dataform-controls/text.tsx +2 -57
- package/src/dataform-controls/{boolean.tsx → toggle.tsx} +3 -2
- package/src/dataform-controls/url.tsx +30 -0
- package/src/dataform-controls/utils/validated-text.tsx +96 -0
- package/src/dataforms-layouts/card/index.tsx +5 -4
- package/src/dataforms-layouts/card/style.scss +7 -0
- package/src/dataforms-layouts/data-form-layout.tsx +15 -3
- package/src/dataforms-layouts/index.tsx +35 -0
- package/src/dataforms-layouts/row/index.tsx +115 -0
- package/src/dataforms-layouts/row/style.scss +3 -0
- package/src/dataviews-layouts/grid/index.tsx +38 -33
- package/src/dataviews-layouts/grid/style.scss +42 -20
- package/src/dataviews-layouts/index.ts +16 -2
- package/src/dataviews-layouts/picker-grid/index.tsx +490 -0
- package/src/dataviews-layouts/picker-grid/style.scss +171 -0
- package/src/dataviews-layouts/utils/grid-items.scss +21 -0
- package/src/dataviews-layouts/utils/grid-items.tsx +35 -0
- package/src/dataviews-layouts/utils/preview-size-picker.tsx +87 -0
- package/src/field-types/boolean.tsx +1 -1
- package/src/field-types/color.tsx +115 -0
- package/src/field-types/index.tsx +15 -0
- package/src/field-types/stories/index.story.tsx +719 -0
- package/src/field-types/telephone.tsx +71 -0
- package/src/field-types/url.tsx +71 -0
- package/src/normalize-form-fields.ts +6 -0
- package/src/style.scss +4 -0
- package/src/test/dataform.tsx +2 -2
- package/src/test/dataviews-picker.tsx +478 -0
- package/src/test/dataviews.tsx +86 -0
- package/src/types.ts +56 -4
- package/src/validation.ts +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/dataform-controls/boolean.js.map +0 -1
- package/build-module/dataform-controls/boolean.js.map +0 -1
- package/build-types/components/stories/index.story.d.ts +0 -63
- package/build-types/components/stories/index.story.d.ts.map +0 -1
- package/build-types/dataform-controls/boolean.d.ts +0 -6
- package/build-types/dataform-controls/boolean.d.ts.map +0 -1
- package/src/components/stories/index.story.tsx +0 -372
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_element","require","_clsx","_interopRequireDefault","_jsxRuntime","GridItems","exports","forwardRef","className","previewSize","props","ref","jsx","clsx","style","gridTemplateColumns"],"sources":["@wordpress/dataviews/src/dataviews-layouts/utils/grid-items.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ComponentPropsWithoutRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\nexport const GridItems = forwardRef<\n\tHTMLDivElement,\n\t{\n\t\tclassName?: string;\n\t\tpreviewSize: number | undefined;\n\t} & ComponentPropsWithoutRef< 'div' >\n>( ( { className, previewSize, ...props }, ref ) => {\n\treturn (\n\t\t<div\n\t\t\tref={ ref }\n\t\t\tclassName={ clsx( 'dataviews-view-grid-items', className ) }\n\t\t\tstyle={ {\n\t\t\t\tgridTemplateColumns:\n\t\t\t\t\tpreviewSize &&\n\t\t\t\t\t`repeat(auto-fill, minmax(${ previewSize }px, 1fr))`,\n\t\t\t} }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n} );\n"],"mappings":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAwB,IAAAG,WAAA,GAAAH,OAAA;AAbxB;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGO,MAAMI,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,IAAAE,mBAAU,EAMhC,CAAE;EAAEC,SAAS;EAAEC,WAAW;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAM;EACnD,oBACC,IAAAP,WAAA,CAAAQ,GAAA;IACCD,GAAG,EAAGA,GAAK;IACXH,SAAS,EAAG,IAAAK,aAAI,EAAE,2BAA2B,EAAEL,SAAU,CAAG;IAC5DM,KAAK,EAAG;MACPC,mBAAmB,EAClBN,WAAW,IACX,4BAA6BA,WAAW;IAC1C,CAAG;IAAA,GACEC;EAAK,CACV,CAAC;AAEJ,CAAE,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = PreviewSizePicker;
|
|
8
|
+
var _components = require("@wordpress/components");
|
|
9
|
+
var _i18n = require("@wordpress/i18n");
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
var _dataviewsContext = _interopRequireDefault(require("../../components/dataviews-context"));
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
/**
|
|
14
|
+
* WordPress dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Internal dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const imageSizes = [{
|
|
22
|
+
value: 120,
|
|
23
|
+
breakpoint: 1
|
|
24
|
+
}, {
|
|
25
|
+
value: 170,
|
|
26
|
+
breakpoint: 1
|
|
27
|
+
}, {
|
|
28
|
+
value: 230,
|
|
29
|
+
breakpoint: 1
|
|
30
|
+
}, {
|
|
31
|
+
value: 290,
|
|
32
|
+
breakpoint: 1112 // at minimum image width, 4 images display at this container size
|
|
33
|
+
}, {
|
|
34
|
+
value: 350,
|
|
35
|
+
breakpoint: 1636 // at minimum image width, 6 images display at this container size
|
|
36
|
+
}, {
|
|
37
|
+
value: 430,
|
|
38
|
+
breakpoint: 588 // at minimum image width, 2 images display at this container size
|
|
39
|
+
}];
|
|
40
|
+
function PreviewSizePicker() {
|
|
41
|
+
var _view$layout$previewS, _breakValues$map$filt;
|
|
42
|
+
const context = (0, _element.useContext)(_dataviewsContext.default);
|
|
43
|
+
const view = context.view;
|
|
44
|
+
const breakValues = imageSizes.filter(size => {
|
|
45
|
+
return context.containerWidth >= size.breakpoint;
|
|
46
|
+
});
|
|
47
|
+
const layoutPreviewSize = (_view$layout$previewS = view.layout?.previewSize) !== null && _view$layout$previewS !== void 0 ? _view$layout$previewS : 230; // Default to the third smallest size if no preview size is set.
|
|
48
|
+
// If the container has resized and the set preview size is no longer available,
|
|
49
|
+
// we reset it to the next smallest size, or the smallest available size.
|
|
50
|
+
const previewSizeToUse = (_breakValues$map$filt = breakValues.map((size, index) => ({
|
|
51
|
+
...size,
|
|
52
|
+
index
|
|
53
|
+
})).filter(size => size.value <= layoutPreviewSize).sort((a, b) => b.value - a.value)[0]?.index) !== null && _breakValues$map$filt !== void 0 ? _breakValues$map$filt : 0;
|
|
54
|
+
const marks = breakValues.map((size, index) => {
|
|
55
|
+
return {
|
|
56
|
+
value: index
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.RangeControl, {
|
|
60
|
+
__nextHasNoMarginBottom: true,
|
|
61
|
+
__next40pxDefaultSize: true,
|
|
62
|
+
showTooltip: false,
|
|
63
|
+
label: (0, _i18n.__)('Preview size'),
|
|
64
|
+
value: previewSizeToUse,
|
|
65
|
+
min: 0,
|
|
66
|
+
max: breakValues.length - 1,
|
|
67
|
+
withInputField: false,
|
|
68
|
+
onChange: (value = 0) => {
|
|
69
|
+
context.onChangeView({
|
|
70
|
+
...view,
|
|
71
|
+
layout: {
|
|
72
|
+
...view.layout,
|
|
73
|
+
previewSize: breakValues[value].value
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
step: 1,
|
|
78
|
+
marks: marks
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=preview-size-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_element","_dataviewsContext","_interopRequireDefault","_jsxRuntime","imageSizes","value","breakpoint","PreviewSizePicker","_view$layout$previewS","_breakValues$map$filt","context","useContext","DataViewsContext","view","breakValues","filter","size","containerWidth","layoutPreviewSize","layout","previewSize","previewSizeToUse","map","index","sort","a","b","marks","jsx","RangeControl","__nextHasNoMarginBottom","__next40pxDefaultSize","showTooltip","label","__","min","max","length","withInputField","onChange","onChangeView","step"],"sources":["@wordpress/dataviews/src/dataviews-layouts/utils/preview-size-picker.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RangeControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../../components/dataviews-context';\nimport type { ViewGrid } from '../../types';\n\nconst imageSizes = [\n\t{\n\t\tvalue: 120,\n\t\tbreakpoint: 1,\n\t},\n\t{\n\t\tvalue: 170,\n\t\tbreakpoint: 1,\n\t},\n\t{\n\t\tvalue: 230,\n\t\tbreakpoint: 1,\n\t},\n\t{\n\t\tvalue: 290,\n\t\tbreakpoint: 1112, // at minimum image width, 4 images display at this container size\n\t},\n\t{\n\t\tvalue: 350,\n\t\tbreakpoint: 1636, // at minimum image width, 6 images display at this container size\n\t},\n\t{\n\t\tvalue: 430,\n\t\tbreakpoint: 588, // at minimum image width, 2 images display at this container size\n\t},\n];\n\nexport default function PreviewSizePicker() {\n\tconst context = useContext( DataViewsContext );\n\tconst view = context.view as ViewGrid;\n\n\tconst breakValues = imageSizes.filter( ( size ) => {\n\t\treturn context.containerWidth >= size.breakpoint;\n\t} );\n\n\tconst layoutPreviewSize = view.layout?.previewSize ?? 230; // Default to the third smallest size if no preview size is set.\n\t// If the container has resized and the set preview size is no longer available,\n\t// we reset it to the next smallest size, or the smallest available size.\n\tconst previewSizeToUse =\n\t\tbreakValues\n\t\t\t.map( ( size, index ) => ( { ...size, index } ) )\n\t\t\t.filter( ( size ) => size.value <= layoutPreviewSize )\n\t\t\t.sort( ( a, b ) => b.value - a.value )[ 0 ]?.index ?? 0;\n\n\tconst marks = breakValues.map( ( size, index ) => {\n\t\treturn {\n\t\t\tvalue: index,\n\t\t};\n\t} );\n\n\treturn (\n\t\t<RangeControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t\tshowTooltip={ false }\n\t\t\tlabel={ __( 'Preview size' ) }\n\t\t\tvalue={ previewSizeToUse }\n\t\t\tmin={ 0 }\n\t\t\tmax={ breakValues.length - 1 }\n\t\t\twithInputField={ false }\n\t\t\tonChange={ ( value = 0 ) => {\n\t\t\t\tcontext.onChangeView( {\n\t\t\t\t\t...view,\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\t...view.layout,\n\t\t\t\t\t\tpreviewSize: breakValues[ value ].value,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tstep={ 1 }\n\t\t\tmarks={ marks }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,iBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAkE,IAAAK,WAAA,GAAAL,OAAA;AAVlE;AACA;AACA;;AAKA;AACA;AACA;;AAIA,MAAMM,UAAU,GAAG,CAClB;EACCC,KAAK,EAAE,GAAG;EACVC,UAAU,EAAE;AACb,CAAC,EACD;EACCD,KAAK,EAAE,GAAG;EACVC,UAAU,EAAE;AACb,CAAC,EACD;EACCD,KAAK,EAAE,GAAG;EACVC,UAAU,EAAE;AACb,CAAC,EACD;EACCD,KAAK,EAAE,GAAG;EACVC,UAAU,EAAE,IAAI,CAAE;AACnB,CAAC,EACD;EACCD,KAAK,EAAE,GAAG;EACVC,UAAU,EAAE,IAAI,CAAE;AACnB,CAAC,EACD;EACCD,KAAK,EAAE,GAAG;EACVC,UAAU,EAAE,GAAG,CAAE;AAClB,CAAC,CACD;AAEc,SAASC,iBAAiBA,CAAA,EAAG;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EAC3C,MAAMC,OAAO,GAAG,IAAAC,mBAAU,EAAEC,yBAAiB,CAAC;EAC9C,MAAMC,IAAI,GAAGH,OAAO,CAAC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Y,CAAE;QACrB,GAAG3B,IAAI;QACPM,MAAM,EAAE;UACP,GAAGN,IAAI,CAACM,MAAM;UACdC,WAAW,EAAEN,WAAW,CAAET,KAAK,CAAE,CAACA;QACnC;MACD,CAAE,CAAC;IACJ,CAAG;IACHoC,IAAI,EAAG,CAAG;IACVd,KAAK,EAAGA;EAAO,CACf,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_utils","_constants","sort","a","b","direction","boolA","Boolean","boolB","_default","exports","default","isValid","custom","item","field","value","getValue","undefined","includes","__","Edit","render","elements","renderFromElements","enableSorting","filterBy","defaultOperators","OPERATOR_IS","OPERATOR_IS_NOT","validOperators"],"sources":["@wordpress/dataviews/src/field-types/boolean.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tFieldTypeDefinition,\n\tNormalizedField,\n} from '../types';\nimport { renderFromElements } from '../utils';\nimport { OPERATOR_IS, OPERATOR_IS_NOT } from '../constants';\n\nfunction sort( a: any, b: any, direction: SortDirection ) {\n\tconst boolA = Boolean( a );\n\tconst boolB = Boolean( b );\n\n\tif ( boolA === boolB ) {\n\t\treturn 0;\n\t}\n\n\t// In ascending order, false comes before true\n\tif ( direction === 'asc' ) {\n\t\treturn boolA ? 1 : -1;\n\t}\n\n\t// In descending order, true comes before false\n\treturn boolA ? -1 : 1;\n}\n\nexport default {\n\tsort,\n\tisValid: {\n\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\tconst value = field.getValue( { item } );\n\n\t\t\tif (\n\t\t\t\t! [ undefined, '', null ].includes( value ) &&\n\t\t\t\t! [ true, false ].includes( value )\n\t\t\t) {\n\t\t\t\treturn __( 'Value must be true, false, or undefined' );\n\t\t\t}\n\n\t\t\treturn null;\n\t\t},\n\t},\n\tEdit: '
|
|
1
|
+
{"version":3,"names":["_i18n","require","_utils","_constants","sort","a","b","direction","boolA","Boolean","boolB","_default","exports","default","isValid","custom","item","field","value","getValue","undefined","includes","__","Edit","render","elements","renderFromElements","enableSorting","filterBy","defaultOperators","OPERATOR_IS","OPERATOR_IS_NOT","validOperators"],"sources":["@wordpress/dataviews/src/field-types/boolean.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tFieldTypeDefinition,\n\tNormalizedField,\n} from '../types';\nimport { renderFromElements } from '../utils';\nimport { OPERATOR_IS, OPERATOR_IS_NOT } from '../constants';\n\nfunction sort( a: any, b: any, direction: SortDirection ) {\n\tconst boolA = Boolean( a );\n\tconst boolB = Boolean( b );\n\n\tif ( boolA === boolB ) {\n\t\treturn 0;\n\t}\n\n\t// In ascending order, false comes before true\n\tif ( direction === 'asc' ) {\n\t\treturn boolA ? 1 : -1;\n\t}\n\n\t// In descending order, true comes before false\n\treturn boolA ? -1 : 1;\n}\n\nexport default {\n\tsort,\n\tisValid: {\n\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\tconst value = field.getValue( { item } );\n\n\t\t\tif (\n\t\t\t\t! [ undefined, '', null ].includes( value ) &&\n\t\t\t\t! [ true, false ].includes( value )\n\t\t\t) {\n\t\t\t\treturn __( 'Value must be true, false, or undefined' );\n\t\t\t}\n\n\t\t\treturn null;\n\t\t},\n\t},\n\tEdit: 'checkbox',\n\trender: ( { item, field }: DataViewRenderFieldProps< any > ) => {\n\t\tif ( field.elements ) {\n\t\t\treturn renderFromElements( { item, field } );\n\t\t}\n\n\t\tif ( field.getValue( { item } ) === true ) {\n\t\t\treturn __( 'True' );\n\t\t}\n\n\t\tif ( field.getValue( { item } ) === false ) {\n\t\t\treturn __( 'False' );\n\t\t}\n\n\t\treturn null;\n\t},\n\tenableSorting: true,\n\tfilterBy: {\n\t\tdefaultOperators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KAAK,CAACQ,QAAQ,EAAG;MACrB,OAAO,IAAAC,yBAAkB,EAAE;QAAEV,IAAI;QAAEC;MAAM,CAAE,CAAC;IAC7C;IAEA,IAAKA,KAAK,CAACE,QAAQ,CAAE;MAAEH;IAAK,CAAE,CAAC,KAAK,IAAI,EAAG;MAC1C,OAAO,IAAAM,QAAE,EAAE,MAAO,CAAC;IACpB;IAEA,IAAKL,KAAK,CAACE,QAAQ,CAAE;MAAEH;IAAK,CAAE,CAAC,KAAK,KAAK,EAAG;MAC3C,OAAO,IAAAM,QAAE,EAAE,OAAQ,CAAC;IACrB;IAEA,OAAO,IAAI;EACZ,CAAC;EACDK,aAAa,EAAE,IAAI;EACnBC,QAAQ,EAAE;IACTC,gBAAgB,EAAE,CAAEC,sBAAW,EAAEC,0BAAe,CAAE;IAClDC,cAAc,EAAE,CAAEF,sBAAW,EAAEC,0BAAe;EAC/C;AACD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _colord = require("colord");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _utils = require("../utils");
|
|
10
|
+
var _constants = require("../constants");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
/**
|
|
13
|
+
* External dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function sort(valueA, valueB, direction) {
|
|
25
|
+
// Convert colors to HSL for better sorting
|
|
26
|
+
const colorA = (0, _colord.colord)(valueA);
|
|
27
|
+
const colorB = (0, _colord.colord)(valueB);
|
|
28
|
+
if (!colorA.isValid() && !colorB.isValid()) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
if (!colorA.isValid()) {
|
|
32
|
+
return direction === 'asc' ? 1 : -1;
|
|
33
|
+
}
|
|
34
|
+
if (!colorB.isValid()) {
|
|
35
|
+
return direction === 'asc' ? -1 : 1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Sort by hue, then saturation, then lightness
|
|
39
|
+
const hslA = colorA.toHsl();
|
|
40
|
+
const hslB = colorB.toHsl();
|
|
41
|
+
if (hslA.h !== hslB.h) {
|
|
42
|
+
return direction === 'asc' ? hslA.h - hslB.h : hslB.h - hslA.h;
|
|
43
|
+
}
|
|
44
|
+
if (hslA.s !== hslB.s) {
|
|
45
|
+
return direction === 'asc' ? hslA.s - hslB.s : hslB.s - hslA.s;
|
|
46
|
+
}
|
|
47
|
+
return direction === 'asc' ? hslA.l - hslB.l : hslB.l - hslA.l;
|
|
48
|
+
}
|
|
49
|
+
var _default = exports.default = {
|
|
50
|
+
sort,
|
|
51
|
+
isValid: {
|
|
52
|
+
custom: (item, field) => {
|
|
53
|
+
const value = field.getValue({
|
|
54
|
+
item
|
|
55
|
+
});
|
|
56
|
+
if (![undefined, '', null].includes(value) && !(0, _colord.colord)(value).isValid()) {
|
|
57
|
+
return (0, _i18n.__)('Value must be a valid color.');
|
|
58
|
+
}
|
|
59
|
+
if (field.elements) {
|
|
60
|
+
const validValues = field.elements.map(f => f.value);
|
|
61
|
+
if (!validValues.includes(value)) {
|
|
62
|
+
return (0, _i18n.__)('Value must be one of the elements.');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
Edit: 'color',
|
|
69
|
+
render: ({
|
|
70
|
+
item,
|
|
71
|
+
field
|
|
72
|
+
}) => {
|
|
73
|
+
if (field.elements) {
|
|
74
|
+
return (0, _utils.renderFromElements)({
|
|
75
|
+
item,
|
|
76
|
+
field
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const value = field.getValue({
|
|
80
|
+
item
|
|
81
|
+
});
|
|
82
|
+
if (!value || !(0, _colord.colord)(value).isValid()) {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Render color with visual preview
|
|
87
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
88
|
+
style: {
|
|
89
|
+
display: 'flex',
|
|
90
|
+
alignItems: 'center',
|
|
91
|
+
gap: '8px'
|
|
92
|
+
},
|
|
93
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
94
|
+
style: {
|
|
95
|
+
width: '16px',
|
|
96
|
+
height: '16px',
|
|
97
|
+
borderRadius: '50%',
|
|
98
|
+
backgroundColor: value,
|
|
99
|
+
border: '1px solid #ddd',
|
|
100
|
+
flexShrink: 0
|
|
101
|
+
}
|
|
102
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
103
|
+
children: value
|
|
104
|
+
})]
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
enableSorting: true,
|
|
108
|
+
filterBy: {
|
|
109
|
+
defaultOperators: [_constants.OPERATOR_IS_ANY, _constants.OPERATOR_IS_NONE],
|
|
110
|
+
validOperators: [_constants.OPERATOR_IS, _constants.OPERATOR_IS_NOT]
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_colord","require","_i18n","_utils","_constants","_jsxRuntime","sort","valueA","valueB","direction","colorA","colord","colorB","isValid","hslA","toHsl","hslB","h","s","l","_default","exports","default","custom","item","field","value","getValue","undefined","includes","__","elements","validValues","map","f","Edit","render","renderFromElements","jsxs","style","display","alignItems","gap","children","jsx","width","height","borderRadius","backgroundColor","border","flexShrink","enableSorting","filterBy","defaultOperators","OPERATOR_IS_ANY","OPERATOR_IS_NONE","validOperators","OPERATOR_IS","OPERATOR_IS_NOT"],"sources":["@wordpress/dataviews/src/field-types/color.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { colord } from 'colord';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tNormalizedField,\n\tFieldTypeDefinition,\n} from '../types';\nimport { renderFromElements } from '../utils';\nimport {\n\tOPERATOR_IS,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_NOT,\n} from '../constants';\n\nfunction sort( valueA: any, valueB: any, direction: SortDirection ) {\n\t// Convert colors to HSL for better sorting\n\tconst colorA = colord( valueA );\n\tconst colorB = colord( valueB );\n\n\tif ( ! colorA.isValid() && ! colorB.isValid() ) {\n\t\treturn 0;\n\t}\n\tif ( ! colorA.isValid() ) {\n\t\treturn direction === 'asc' ? 1 : -1;\n\t}\n\tif ( ! colorB.isValid() ) {\n\t\treturn direction === 'asc' ? -1 : 1;\n\t}\n\n\t// Sort by hue, then saturation, then lightness\n\tconst hslA = colorA.toHsl();\n\tconst hslB = colorB.toHsl();\n\n\tif ( hslA.h !== hslB.h ) {\n\t\treturn direction === 'asc' ? hslA.h - hslB.h : hslB.h - hslA.h;\n\t}\n\tif ( hslA.s !== hslB.s ) {\n\t\treturn direction === 'asc' ? hslA.s - hslB.s : hslB.s - hslA.s;\n\t}\n\treturn direction === 'asc' ? hslA.l - hslB.l : hslB.l - hslA.l;\n}\n\nexport default {\n\tsort,\n\tisValid: {\n\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\tconst value = field.getValue( { item } );\n\n\t\t\tif (\n\t\t\t\t! [ undefined, '', null ].includes( value ) &&\n\t\t\t\t! colord( value ).isValid()\n\t\t\t) {\n\t\t\t\treturn __( 'Value must be a valid color.' );\n\t\t\t}\n\n\t\t\tif ( field.elements ) {\n\t\t\t\tconst validValues = field.elements.map( ( f ) => f.value );\n\t\t\t\tif ( ! validValues.includes( value ) ) {\n\t\t\t\t\treturn __( 'Value must be one of the elements.' );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t},\n\t},\n\tEdit: 'color',\n\trender: ( { item, field }: DataViewRenderFieldProps< any > ) => {\n\t\tif ( field.elements ) {\n\t\t\treturn renderFromElements( { item, field } );\n\t\t}\n\n\t\tconst value = field.getValue( { item } );\n\n\t\tif ( ! value || ! colord( value ).isValid() ) {\n\t\t\treturn value;\n\t\t}\n\n\t\t// Render color with visual preview\n\t\treturn (\n\t\t\t<div\n\t\t\t\tstyle={ { display: 'flex', alignItems: 'center', gap: '8px' } }\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\twidth: '16px',\n\t\t\t\t\t\theight: '16px',\n\t\t\t\t\t\tborderRadius: '50%',\n\t\t\t\t\t\tbackgroundColor: value,\n\t\t\t\t\t\tborder: '1px solid #ddd',\n\t\t\t\t\t\tflexShrink: 0,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<span>{ value }</span>\n\t\t\t</div>\n\t\t);\n\t},\n\tenableSorting: true,\n\tfilterBy: {\n\t\tdefaultOperators: [ OPERATOR_IS_ANY, OPERATOR_IS_NONE ],\n\t\tvalidOperators: [ OPERATOR_IS, OPERATOR_IS_NOT ],\n\t},\n} satisfies FieldTypeDefinition< any >;\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AAWA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAKsB,IAAAI,WAAA,GAAAJ,OAAA;AAzBtB;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAeA,SAASK,IAAIA,CAAEC,MAAW,EAAEC,MAAW,EAAEC,SAAwB,EAAG;EACnE;EACA,MAAMC,MAAM,GAAG,IAAAC,cAAM,EAAEJ,M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UACPM,KAAK,EAAE,MAAM;UACbC,MAAM,EAAE,MAAM;UACdC,YAAY,EAAE,KAAK;UACnBC,eAAe,EAAEtB,KAAK;UACtBuB,MAAM,EAAE,gBAAgB;UACxBC,UAAU,EAAE;QACb;MAAG,CACH,CAAC,eACF,IAAA7C,WAAA,CAAAuC,GAAA;QAAAD,QAAA,EAAQjB;MAAK,CAAQ,CAAC;IAAA,CAClB,CAAC;EAER,CAAC;EACDyB,aAAa,EAAE,IAAI;EACnBC,QAAQ,EAAE;IACTC,gBAAgB,EAAE,CAAEC,0BAAe,EAAEC,2BAAgB,CAAE;IACvDC,cAAc,EAAE,CAAEC,sBAAW,EAAEC,0BAAe;EAC/C;AACD,CAAC","ignoreList":[]}
|
|
@@ -14,6 +14,9 @@ var _date = _interopRequireDefault(require("./date"));
|
|
|
14
14
|
var _boolean = _interopRequireDefault(require("./boolean"));
|
|
15
15
|
var _media = _interopRequireDefault(require("./media"));
|
|
16
16
|
var _array = _interopRequireDefault(require("./array"));
|
|
17
|
+
var _telephone = _interopRequireDefault(require("./telephone"));
|
|
18
|
+
var _color = _interopRequireDefault(require("./color"));
|
|
19
|
+
var _url = _interopRequireDefault(require("./url"));
|
|
17
20
|
var _utils = require("../utils");
|
|
18
21
|
var _constants = require("../constants");
|
|
19
22
|
/**
|
|
@@ -55,6 +58,15 @@ function getFieldTypeDefinition(type) {
|
|
|
55
58
|
if ('array' === type) {
|
|
56
59
|
return _array.default;
|
|
57
60
|
}
|
|
61
|
+
if ('telephone' === type) {
|
|
62
|
+
return _telephone.default;
|
|
63
|
+
}
|
|
64
|
+
if ('color' === type) {
|
|
65
|
+
return _color.default;
|
|
66
|
+
}
|
|
67
|
+
if ('url' === type) {
|
|
68
|
+
return _url.default;
|
|
69
|
+
}
|
|
58
70
|
|
|
59
71
|
// This is a fallback for fields that don't provide a type.
|
|
60
72
|
// It can be removed when the field.type is mandatory.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_email","_interopRequireDefault","_integer","_text","_datetime","_date","_boolean","_media","_array","_utils","_constants","getFieldTypeDefinition","type","email","integer","text","datetime","date","boolean","media","array","sort","a","b","direction","localeCompare","isValid","custom","item","field","elements","value","getValue","validValues","map","f","includes","__","Edit","render","renderFromElements","enableSorting","filterBy","defaultOperators","OPERATOR_IS","OPERATOR_IS_NOT","validOperators","ALL_OPERATORS"],"sources":["@wordpress/dataviews/src/field-types/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tNormalizedField,\n\tFieldType,\n\tFieldTypeDefinition,\n\tSortDirection,\n} from '../types';\nimport { default as email } from './email';\nimport { default as integer } from './integer';\nimport { default as text } from './text';\nimport { default as datetime } from './datetime';\nimport { default as date } from './date';\nimport { default as boolean } from './boolean';\nimport { default as media } from './media';\nimport { default as array } from './array';\nimport { renderFromElements } from '../utils';\nimport { ALL_OPERATORS, OPERATOR_IS, OPERATOR_IS_NOT } from '../constants';\n\n/**\n *\n * @param {FieldType} type The field type definition to get.\n *\n * @return A field type definition.\n */\nexport default function getFieldTypeDefinition< Item >(\n\ttype?: FieldType\n): FieldTypeDefinition< Item > {\n\tif ( 'email' === type ) {\n\t\treturn email;\n\t}\n\n\tif ( 'integer' === type ) {\n\t\treturn integer;\n\t}\n\n\tif ( 'text' === type ) {\n\t\treturn text;\n\t}\n\n\tif ( 'datetime' === type ) {\n\t\treturn datetime;\n\t}\n\n\tif ( 'date' === type ) {\n\t\treturn date;\n\t}\n\n\tif ( 'boolean' === type ) {\n\t\treturn boolean;\n\t}\n\n\tif ( 'media' === type ) {\n\t\treturn media;\n\t}\n\n\tif ( 'array' === type ) {\n\t\treturn array;\n\t}\n\n\t// This is a fallback for fields that don't provide a type.\n\t// It can be removed when the field.type is mandatory.\n\treturn {\n\t\tsort: ( a: any, b: any, direction: SortDirection ) => {\n\t\t\tif ( typeof a === 'number' && typeof b === 'number' ) {\n\t\t\t\treturn direction === 'asc' ? a - b : b - a;\n\t\t\t}\n\n\t\t\treturn direction === 'asc'\n\t\t\t\t? a.localeCompare( b )\n\t\t\t\t: b.localeCompare( a );\n\t\t},\n\t\tisValid: {\n\t\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\t\tif ( field?.elements ) {\n\t\t\t\t\tconst value = field.getValue( { item } );\n\t\t\t\t\tconst validValues = field?.elements?.map(\n\t\t\t\t\t\t( f ) => f.value\n\t\t\t\t\t);\n\t\t\t\t\tif ( ! validValues.includes( value ) ) {\n\t\t\t\t\t\treturn __( 'Value must be one of the elements.' );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn null;\n\t\t\t},\n\t\t},\n\t\tEdit: null,\n\t\trender: ( { item, field }: DataViewRenderFieldProps< Item > ) => {\n\t\t\treturn field.elements\n\t\t\t\t? renderFromElements( { item, field } )\n\t\t\t\t: field.getValue( { item } );\n\t\t},\n\t\tenableSorting: true,\n\t\tfilterBy: {\n\t\t\tdefaultOperators: [ OPERATOR_IS, OPERATOR_IS_NOT ],\n\t\t\tvalidOperators: ALL_OPERATORS,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAYA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,KAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,KAAA,GAAAJ,sBAAA,CAAAF,OAAA;AACA,IAAAO,QAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAAQ,MAAA,GAAAN,sBAAA,CAAAF,OAAA;AACA,IAAAS,MAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,MAAA,GAAAV,OAAA;AACA,
|
|
1
|
+
{"version":3,"names":["_i18n","require","_email","_interopRequireDefault","_integer","_text","_datetime","_date","_boolean","_media","_array","_telephone","_color","_url","_utils","_constants","getFieldTypeDefinition","type","email","integer","text","datetime","date","boolean","media","array","telephone","color","url","sort","a","b","direction","localeCompare","isValid","custom","item","field","elements","value","getValue","validValues","map","f","includes","__","Edit","render","renderFromElements","enableSorting","filterBy","defaultOperators","OPERATOR_IS","OPERATOR_IS_NOT","validOperators","ALL_OPERATORS"],"sources":["@wordpress/dataviews/src/field-types/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tNormalizedField,\n\tFieldType,\n\tFieldTypeDefinition,\n\tSortDirection,\n} from '../types';\nimport { default as email } from './email';\nimport { default as integer } from './integer';\nimport { default as text } from './text';\nimport { default as datetime } from './datetime';\nimport { default as date } from './date';\nimport { default as boolean } from './boolean';\nimport { default as media } from './media';\nimport { default as array } from './array';\nimport { default as telephone } from './telephone';\nimport { default as color } from './color';\nimport { default as url } from './url';\nimport { renderFromElements } from '../utils';\nimport { ALL_OPERATORS, OPERATOR_IS, OPERATOR_IS_NOT } from '../constants';\n\n/**\n *\n * @param {FieldType} type The field type definition to get.\n *\n * @return A field type definition.\n */\nexport default function getFieldTypeDefinition< Item >(\n\ttype?: FieldType\n): FieldTypeDefinition< Item > {\n\tif ( 'email' === type ) {\n\t\treturn email;\n\t}\n\n\tif ( 'integer' === type ) {\n\t\treturn integer;\n\t}\n\n\tif ( 'text' === type ) {\n\t\treturn text;\n\t}\n\n\tif ( 'datetime' === type ) {\n\t\treturn datetime;\n\t}\n\n\tif ( 'date' === type ) {\n\t\treturn date;\n\t}\n\n\tif ( 'boolean' === type ) {\n\t\treturn boolean;\n\t}\n\n\tif ( 'media' === type ) {\n\t\treturn media;\n\t}\n\n\tif ( 'array' === type ) {\n\t\treturn array;\n\t}\n\n\tif ( 'telephone' === type ) {\n\t\treturn telephone;\n\t}\n\n\tif ( 'color' === type ) {\n\t\treturn color;\n\t}\n\n\tif ( 'url' === type ) {\n\t\treturn url;\n\t}\n\n\t// This is a fallback for fields that don't provide a type.\n\t// It can be removed when the field.type is mandatory.\n\treturn {\n\t\tsort: ( a: any, b: any, direction: SortDirection ) => {\n\t\t\tif ( typeof a === 'number' && typeof b === 'number' ) {\n\t\t\t\treturn direction === 'asc' ? a - b : b - a;\n\t\t\t}\n\n\t\t\treturn direction === 'asc'\n\t\t\t\t? a.localeCompare( b )\n\t\t\t\t: b.localeCompare( a );\n\t\t},\n\t\tisValid: {\n\t\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\t\tif ( field?.elements ) {\n\t\t\t\t\tconst value = field.getValue( { item } );\n\t\t\t\t\tconst validValues = field?.elements?.map(\n\t\t\t\t\t\t( f ) => f.value\n\t\t\t\t\t);\n\t\t\t\t\tif ( ! validValues.includes( value ) ) {\n\t\t\t\t\t\treturn __( 'Value must be one of the elements.' );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn null;\n\t\t\t},\n\t\t},\n\t\tEdit: null,\n\t\trender: ( { item, field }: DataViewRenderFieldProps< Item > ) => {\n\t\t\treturn field.elements\n\t\t\t\t? renderFromElements( { item, field } )\n\t\t\t\t: field.getValue( { item } );\n\t\t},\n\t\tenableSorting: true,\n\t\tfilterBy: {\n\t\t\tdefaultOperators: [ OPERATOR_IS, OPERATOR_IS_NOT ],\n\t\t\tvalidOperators: ALL_OPERATORS,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAYA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,KAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,KAAA,GAAAJ,sBAAA,CAAAF,OAAA;AACA,IAAAO,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"__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _i18n = require("@wordpress/i18n");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _constants = require("../constants");
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function sort(valueA, valueB, direction) {
|
|
19
|
+
return direction === 'asc' ? valueA.localeCompare(valueB) : valueB.localeCompare(valueA);
|
|
20
|
+
}
|
|
21
|
+
var _default = exports.default = {
|
|
22
|
+
sort,
|
|
23
|
+
isValid: {
|
|
24
|
+
custom: (item, field) => {
|
|
25
|
+
const value = field.getValue({
|
|
26
|
+
item
|
|
27
|
+
});
|
|
28
|
+
if (field?.elements) {
|
|
29
|
+
const validValues = field.elements.map(f => f.value);
|
|
30
|
+
if (!validValues.includes(value)) {
|
|
31
|
+
return (0, _i18n.__)('Value must be one of the elements.');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
Edit: 'telephone',
|
|
38
|
+
render: ({
|
|
39
|
+
item,
|
|
40
|
+
field
|
|
41
|
+
}) => {
|
|
42
|
+
return field.elements ? (0, _utils.renderFromElements)({
|
|
43
|
+
item,
|
|
44
|
+
field
|
|
45
|
+
}) : field.getValue({
|
|
46
|
+
item
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
enableSorting: true,
|
|
50
|
+
filterBy: {
|
|
51
|
+
defaultOperators: [_constants.OPERATOR_IS_ANY, _constants.OPERATOR_IS_NONE],
|
|
52
|
+
validOperators: [_constants.OPERATOR_IS, _constants.OPERATOR_IS_NOT, _constants.OPERATOR_CONTAINS, _constants.OPERATOR_NOT_CONTAINS, _constants.OPERATOR_STARTS_WITH,
|
|
53
|
+
// Multiple selection
|
|
54
|
+
_constants.OPERATOR_IS_ANY, _constants.OPERATOR_IS_NONE, _constants.OPERATOR_IS_ALL, _constants.OPERATOR_IS_NOT_ALL]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=telephone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_i18n","require","_utils","_constants","sort","valueA","valueB","direction","localeCompare","_default","exports","default","isValid","custom","item","field","value","getValue","elements","validValues","map","f","includes","__","Edit","render","renderFromElements","enableSorting","filterBy","defaultOperators","OPERATOR_IS_ANY","OPERATOR_IS_NONE","validOperators","OPERATOR_IS","OPERATOR_IS_NOT","OPERATOR_CONTAINS","OPERATOR_NOT_CONTAINS","OPERATOR_STARTS_WITH","OPERATOR_IS_ALL","OPERATOR_IS_NOT_ALL"],"sources":["@wordpress/dataviews/src/field-types/telephone.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tNormalizedField,\n\tFieldTypeDefinition,\n} from '../types';\nimport { renderFromElements } from '../utils';\nimport {\n\tOPERATOR_IS,\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_NOT_ALL,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_CONTAINS,\n\tOPERATOR_NOT_CONTAINS,\n\tOPERATOR_STARTS_WITH,\n} from '../constants';\n\nfunction sort( valueA: any, valueB: any, direction: SortDirection ) {\n\treturn direction === 'asc'\n\t\t? valueA.localeCompare( valueB )\n\t\t: valueB.localeCompare( valueA );\n}\n\nexport default {\n\tsort,\n\tisValid: {\n\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\tconst value = field.getValue( { item } );\n\t\t\tif ( field?.elements ) {\n\t\t\t\tconst validValues = field.elements.map( ( f ) => f.value );\n\t\t\t\tif ( ! validValues.includes( value ) ) {\n\t\t\t\t\treturn __( 'Value must be one of the elements.' );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t},\n\t},\n\tEdit: 'telephone',\n\trender: ( { item, field }: DataViewRenderFieldProps< any > ) => {\n\t\treturn field.elements\n\t\t\t? renderFromElements( { item, field } )\n\t\t\t: field.getValue( { item } );\n\t},\n\tenableSorting: true,\n\tfilterBy: {\n\t\tdefaultOperators: [ OPERATOR_IS_ANY, OPERATOR_IS_NONE ],\n\t\tvalidOperators: [\n\t\t\tOPERATOR_IS,\n\t\t\tOPERATOR_IS_NOT,\n\t\t\tOPERATOR_CONTAINS,\n\t\t\tOPERATOR_NOT_CONTAINS,\n\t\t\tOPERATOR_STARTS_WITH,\n\t\t\t// Multiple selection\n\t\t\tOPERATOR_IS_ANY,\n\t\t\tOPERATOR_IS_NONE,\n\t\t\tOPERATOR_IS_ALL,\n\t\t\tOPERATOR_IS_NOT_ALL,\n\t\t],\n\t},\n} satisfies FieldTypeDefinition< any >;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAWA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAoBA,SAASG,IAAIA,CAAEC,MAAW,EAAEC,MAAW,EAAEC,SAAwB,EAAG;EACnE,OAAOA,SAAS,KAAK,KAAK,GACvBF,MAAM,CAACG,aAAa,CAAEF,MAAO,CAAC,GAC9BA,MAAM,CAACE,aAAa,CAAEH,MAAO,CAAC;AAClC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc;EACdP,IAAI;EACJQ,OAAO,EAAE;IACRC,MAAM,EAAEA,CAAEC,IAAS,EAAEC,KAA6B,KAAM;MACvD,MAAMC,KAAK,GAAGD,KAAK,CAACE,QAAQ,CAAE;QAAEH;MAAK,CAAE,CAAC;MACxC,IAAKC,KAAK,EAAEG,QAAQ,EAAG;QACtB,MAAMC,WAAW,GAAGJ,KAAK,CAACG,QAAQ,CAACE,GAAG,CAAIC,CAAC,IAAMA,CAAC,CAACL,KAAM,CAAC;QAC1D,IAAK,CAAEG,WAAW,CAACG,QAAQ,CAAEN,KAAM,CAAC,EAAG;UACtC,OAAO,IAAAO,QAAE,EAAE,oCAAqC,CAAC;QAClD;MACD;MAEA,OAAO,IAAI;IACZ;EACD,CAAC;EACDC,IAAI,EAAE,WAAW;EACjBC,MAAM,EAAEA,CAAE;IAAEX,IAAI;IAAEC;EAAuC,CAAC,KAAM;IAC/D,OAAOA,KAAK,CAACG,QAAQ,GAClB,IAAAQ,yBAAkB,EAAE;MAAEZ,IAAI;MAAEC;IAAM,CAAE,CAAC,GACrCA,KAAK,CAACE,QAAQ,CAAE;MAAEH;IAAK,CAAE,CAAC;EAC9B,CAAC;EACDa,aAAa,EAAE,IAAI;EACnBC,QAAQ,EAAE;IACTC,gBAAgB,EAAE,CAAEC,0BAAe,EAAEC,2BAAgB,CAAE;IACvDC,cAAc,EAAE,CACfC,sBAAW,EACXC,0BAAe,EACfC,4BAAiB,EACjBC,gCAAqB,EACrBC,+BAAoB;IACpB;IACAP,0BAAe,EACfC,2BAAgB,EAChBO,0BAAe,EACfC,8BAAmB;EAErB;AACD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _i18n = require("@wordpress/i18n");
|
|
8
|
+
var _utils = require("../utils");
|
|
9
|
+
var _constants = require("../constants");
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function sort(valueA, valueB, direction) {
|
|
19
|
+
return direction === 'asc' ? valueA.localeCompare(valueB) : valueB.localeCompare(valueA);
|
|
20
|
+
}
|
|
21
|
+
var _default = exports.default = {
|
|
22
|
+
sort,
|
|
23
|
+
isValid: {
|
|
24
|
+
custom: (item, field) => {
|
|
25
|
+
const value = field.getValue({
|
|
26
|
+
item
|
|
27
|
+
});
|
|
28
|
+
if (field?.elements) {
|
|
29
|
+
const validValues = field.elements.map(f => f.value);
|
|
30
|
+
if (!validValues.includes(value)) {
|
|
31
|
+
return (0, _i18n.__)('Value must be one of the elements.');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
Edit: 'url',
|
|
38
|
+
render: ({
|
|
39
|
+
item,
|
|
40
|
+
field
|
|
41
|
+
}) => {
|
|
42
|
+
return field.elements ? (0, _utils.renderFromElements)({
|
|
43
|
+
item,
|
|
44
|
+
field
|
|
45
|
+
}) : field.getValue({
|
|
46
|
+
item
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
enableSorting: true,
|
|
50
|
+
filterBy: {
|
|
51
|
+
defaultOperators: [_constants.OPERATOR_IS_ANY, _constants.OPERATOR_IS_NONE],
|
|
52
|
+
validOperators: [_constants.OPERATOR_IS, _constants.OPERATOR_IS_NOT, _constants.OPERATOR_CONTAINS, _constants.OPERATOR_NOT_CONTAINS, _constants.OPERATOR_STARTS_WITH,
|
|
53
|
+
// Multiple selection
|
|
54
|
+
_constants.OPERATOR_IS_ANY, _constants.OPERATOR_IS_NONE, _constants.OPERATOR_IS_ALL, _constants.OPERATOR_IS_NOT_ALL]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_i18n","require","_utils","_constants","sort","valueA","valueB","direction","localeCompare","_default","exports","default","isValid","custom","item","field","value","getValue","elements","validValues","map","f","includes","__","Edit","render","renderFromElements","enableSorting","filterBy","defaultOperators","OPERATOR_IS_ANY","OPERATOR_IS_NONE","validOperators","OPERATOR_IS","OPERATOR_IS_NOT","OPERATOR_CONTAINS","OPERATOR_NOT_CONTAINS","OPERATOR_STARTS_WITH","OPERATOR_IS_ALL","OPERATOR_IS_NOT_ALL"],"sources":["@wordpress/dataviews/src/field-types/url.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tDataViewRenderFieldProps,\n\tSortDirection,\n\tNormalizedField,\n\tFieldTypeDefinition,\n} from '../types';\nimport { renderFromElements } from '../utils';\nimport {\n\tOPERATOR_IS,\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_NOT_ALL,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_CONTAINS,\n\tOPERATOR_NOT_CONTAINS,\n\tOPERATOR_STARTS_WITH,\n} from '../constants';\n\nfunction sort( valueA: any, valueB: any, direction: SortDirection ) {\n\treturn direction === 'asc'\n\t\t? valueA.localeCompare( valueB )\n\t\t: valueB.localeCompare( valueA );\n}\n\nexport default {\n\tsort,\n\tisValid: {\n\t\tcustom: ( item: any, field: NormalizedField< any > ) => {\n\t\t\tconst value = field.getValue( { item } );\n\t\t\tif ( field?.elements ) {\n\t\t\t\tconst validValues = field.elements.map( ( f ) => f.value );\n\t\t\t\tif ( ! validValues.includes( value ) ) {\n\t\t\t\t\treturn __( 'Value must be one of the elements.' );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn null;\n\t\t},\n\t},\n\tEdit: 'url',\n\trender: ( { item, field }: DataViewRenderFieldProps< any > ) => {\n\t\treturn field.elements\n\t\t\t? renderFromElements( { item, field } )\n\t\t\t: field.getValue( { item } );\n\t},\n\tenableSorting: true,\n\tfilterBy: {\n\t\tdefaultOperators: [ OPERATOR_IS_ANY, OPERATOR_IS_NONE ],\n\t\tvalidOperators: [\n\t\t\tOPERATOR_IS,\n\t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OA,KAAK,CAACG,QAAQ,GAClB,IAAAQ,yBAAkB,EAAE;MAAEZ,IAAI;MAAEC;IAAM,CAAE,CAAC,GACrCA,KAAK,CAACE,QAAQ,CAAE;MAAEH;IAAK,CAAE,CAAC;EAC9B,CAAC;EACDa,aAAa,EAAE,IAAI;EACnBC,QAAQ,EAAE;IACTC,gBAAgB,EAAE,CAAEC,0BAAe,EAAEC,2BAAgB,CAAE;IACvDC,cAAc,EAAE,CACfC,sBAAW,EACXC,0BAAe,EACfC,4BAAiB,EACjBC,gCAAqB,EACrBC,+BAAoB;IACpB;IACAP,0BAAe,EACfC,2BAAgB,EAChBO,0BAAe,EACfC,8BAAmB;EAErB;AACD,CAAC","ignoreList":[]}
|
|
@@ -52,6 +52,12 @@ function normalizeLayout(layout) {
|
|
|
52
52
|
isOpened: typeof layout.isOpened === 'boolean' ? layout.isOpened : true
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
+
} else if (layout?.type === 'row') {
|
|
56
|
+
var _layout$alignment;
|
|
57
|
+
normalizedLayout = {
|
|
58
|
+
type: 'row',
|
|
59
|
+
alignment: (_layout$alignment = layout?.alignment) !== null && _layout$alignment !== void 0 ? _layout$alignment : 'center'
|
|
60
|
+
};
|
|
55
61
|
}
|
|
56
62
|
return normalizedLayout;
|
|
57
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_LAYOUT","exports","type","labelPosition","normalizeLayout","layout","normalizedLayout","_layout$labelPosition","_layout$labelPosition2","_layout$openAs","openAs","withHeader","isOpened","normalizeFormFields","form","_form$fields","formLayout","fields","map","field","id","fieldLayout"],"sources":["@wordpress/dataviews/src/normalize-form-fields.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type {\n\tForm,\n\tLayout,\n\tNormalizedLayout,\n\tNormalizedRegularLayout,\n\tNormalizedPanelLayout,\n\tNormalizedCardLayout,\n} from './types';\n\ninterface NormalizedFormField {\n\tid: string;\n\tlayout: Layout;\n}\n\nexport const DEFAULT_LAYOUT: NormalizedLayout = {\n\ttype: 'regular',\n\tlabelPosition: 'top',\n};\n\n/**\n * Normalizes a layout configuration based on its type.\n *\n * @param layout The layout object to normalize.\n * @return The normalized layout object.\n */\nexport function normalizeLayout( layout?: Layout ): NormalizedLayout {\n\tlet normalizedLayout = DEFAULT_LAYOUT;\n\n\tif ( layout?.type === 'regular' ) {\n\t\tnormalizedLayout = {\n\t\t\ttype: 'regular',\n\t\t\tlabelPosition: layout?.labelPosition ?? 'top',\n\t\t} satisfies NormalizedRegularLayout;\n\t} else if ( layout?.type === 'panel' ) {\n\t\tnormalizedLayout = {\n\t\t\ttype: 'panel',\n\t\t\tlabelPosition: layout?.labelPosition ?? 'side',\n\t\t\topenAs: layout?.openAs ?? 'dropdown',\n\t\t} satisfies NormalizedPanelLayout;\n\t} else if ( layout?.type === 'card' ) {\n\t\tif ( layout.withHeader === false ) {\n\t\t\t// Don't let isOpened be false if withHeader is false.\n\t\t\t// Otherwise, the card will not be visible.\n\t\t\tnormalizedLayout = {\n\t\t\t\ttype: 'card',\n\t\t\t\twithHeader: false,\n\t\t\t\tisOpened: true,\n\t\t\t} satisfies NormalizedCardLayout;\n\t\t} else {\n\t\t\tnormalizedLayout = {\n\t\t\t\ttype: 'card',\n\t\t\t\twithHeader: true,\n\t\t\t\tisOpened:\n\t\t\t\t\ttypeof layout.isOpened === 'boolean'\n\t\t\t\t\t\t? layout.isOpened\n\t\t\t\t\t\t: true,\n\t\t\t} satisfies NormalizedCardLayout;\n\t\t}\n\t}\n\n\treturn normalizedLayout;\n}\n\nexport default function normalizeFormFields(\n\tform: Form\n): NormalizedFormField[] {\n\tconst formLayout = normalizeLayout( form?.layout );\n\n\treturn ( form.fields ?? [] ).map( ( field ) => {\n\t\tif ( typeof field === 'string' ) {\n\t\t\treturn {\n\t\t\t\tid: field,\n\t\t\t\tlayout: formLayout,\n\t\t\t};\n\t\t}\n\n\t\tconst fieldLayout = field.layout\n\t\t\t? normalizeLayout( field.layout )\n\t\t\t: formLayout;\n\t\treturn {\n\t\t\t...field,\n\t\t\tlayout: fieldLayout,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;;
|
|
1
|
+
{"version":3,"names":["DEFAULT_LAYOUT","exports","type","labelPosition","normalizeLayout","layout","normalizedLayout","_layout$labelPosition","_layout$labelPosition2","_layout$openAs","openAs","withHeader","isOpened","_layout$alignment","alignment","normalizeFormFields","form","_form$fields","formLayout","fields","map","field","id","fieldLayout"],"sources":["@wordpress/dataviews/src/normalize-form-fields.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type {\n\tForm,\n\tLayout,\n\tNormalizedLayout,\n\tNormalizedRegularLayout,\n\tNormalizedPanelLayout,\n\tNormalizedCardLayout,\n\tNormalizedRowLayout,\n} from './types';\n\ninterface NormalizedFormField {\n\tid: string;\n\tlayout: Layout;\n}\n\nexport const DEFAULT_LAYOUT: NormalizedLayout = {\n\ttype: 'regular',\n\tlabelPosition: 'top',\n};\n\n/**\n * Normalizes a layout configuration based on its type.\n *\n * @param layout The layout object to normalize.\n * @return The normalized layout object.\n */\nexport function normalizeLayout( layout?: Layout ): NormalizedLayout {\n\tlet normalizedLayout = DEFAULT_LAYOUT;\n\n\tif ( layout?.type === 'regular' ) {\n\t\tnormalizedLayout = {\n\t\t\ttype: 'regular',\n\t\t\tlabelPosition: layout?.labelPosition ?? 'top',\n\t\t} satisfies NormalizedRegularLayout;\n\t} else if ( layout?.type === 'panel' ) {\n\t\tnormalizedLayout = {\n\t\t\ttype: 'panel',\n\t\t\tlabelPosition: layout?.labelPosition ?? 'side',\n\t\t\topenAs: layout?.openAs ?? 'dropdown',\n\t\t} satisfies NormalizedPanelLayout;\n\t} else if ( layout?.type === 'card' ) {\n\t\tif ( layout.withHeader === false ) {\n\t\t\t// Don't let isOpened be false if withHeader is false.\n\t\t\t// Otherwise, the card will not be visible.\n\t\t\tnormalizedLayout = {\n\t\t\t\ttype: 'card',\n\t\t\t\twithHeader: false,\n\t\t\t\tisOpened: true,\n\t\t\t} satisfies NormalizedCardLayout;\n\t\t} else {\n\t\t\tnormalizedLayout = {\n\t\t\t\ttype: 'card',\n\t\t\t\twithHeader: true,\n\t\t\t\tisOpened:\n\t\t\t\t\ttypeof layout.isOpened === 'boolean'\n\t\t\t\t\t\t? layout.isOpened\n\t\t\t\t\t\t: true,\n\t\t\t} satisfies NormalizedCardLayout;\n\t\t}\n\t} else if ( layout?.type === 'row' ) {\n\t\tnormalizedLayout = {\n\t\t\ttype: 'row',\n\t\t\talignment: layout?.alignment ?? 'center',\n\t\t} satisfies NormalizedRowLayout;\n\t}\n\n\treturn normalizedLayout;\n}\n\nexport default function normalizeFormFields(\n\tform: Form\n): NormalizedFormField[] {\n\tconst formLayout = normalizeLayout( form?.layout );\n\n\treturn ( form.fields ?? [] ).map( ( field ) => {\n\t\tif ( typeof field === 'string' ) {\n\t\t\treturn {\n\t\t\t\tid: field,\n\t\t\t\tlayout: formLayout,\n\t\t\t};\n\t\t}\n\n\t\tconst fieldLayout = field.layout\n\t\t\t? normalizeLayout( field.layout )\n\t\t\t: formLayout;\n\t\treturn {\n\t\t\t...field,\n\t\t\tlayout: fieldLayout,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;;AAgBO,MAAMA,cAAgC,GAAAC,OAAA,CAAAD,cAAA,GAAG;EAC/CE,IAAI,EAAE,SAAS;EACfC,aAAa,EAAE;AAChB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAAEC,MAAe,EAAqB;EACpE,IAAIC,gBAAgB,GAAGN,cAAc;EAErC,IAAKK,MAAM,EAAEH,IAAI,KAAK,SAAS,EAAG;IAAA,IAAAK,qBAAA;IACjCD,gBAAgB,GAAG;MAClBJ,IAAI,EAAE,SAAS;MACfC,aAAa,GAAAI,qBAAA,GAAEF,MAAM,EAAEF,aAAa,cAAAI,qBAAA,cAAAA,qBAAA,GAAI;IACzC,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A,GAAI,EAAE,EAAGG,GAAG,CAAIC,KAAK,IAAM;IAC9C,IAAK,OAAOA,KAAK,KAAK,QAAQ,EAAG;MAChC,OAAO;QACNC,EAAE,EAAED,KAAK;QACThB,MAAM,EAAEa;MACT,CAAC;IACF;IAEA,MAAMK,WAAW,GAAGF,KAAK,CAAChB,MAAM,GAC7BD,eAAe,CAAEiB,KAAK,CAAChB,MAAO,CAAC,GAC/Ba,UAAU;IACb,OAAO;MACN,GAAGG,KAAK;MACRhB,MAAM,EAAEkB;IACT,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| '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 type View = ViewList | ViewGrid | ViewTable;\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 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 type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n}\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card';\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 Layout = RegularLayout | PanelLayout | CardLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout;\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: Layout;\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: 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\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| '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":[]}
|
package/build/validation.js
CHANGED
|
@@ -28,7 +28,7 @@ function isItemValid(item, fields, form) {
|
|
|
28
28
|
item
|
|
29
29
|
});
|
|
30
30
|
if (field.isValid.required) {
|
|
31
|
-
if (field.type === 'text' && isEmptyNullOrUndefined(value) || field.type === 'email' && isEmptyNullOrUndefined(value) || field.type === 'integer' && isEmptyNullOrUndefined(value) || field.type === undefined && isEmptyNullOrUndefined(value)) {
|
|
31
|
+
if (field.type === 'text' && isEmptyNullOrUndefined(value) || field.type === 'email' && isEmptyNullOrUndefined(value) || field.type === 'url' && isEmptyNullOrUndefined(value) || field.type === 'telephone' && isEmptyNullOrUndefined(value) || field.type === 'integer' && isEmptyNullOrUndefined(value) || field.type === undefined && isEmptyNullOrUndefined(value)) {
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
if (field.type === 'boolean' && value !== true) {
|
package/build/validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_normalizeFields","require","isItemValid","item","fields","form","_fields","normalizeFields","filter","id","includes","isEmptyNullOrUndefined","value","undefined","every","field","getValue","isValid","required","type","custom"],"sources":["@wordpress/dataviews/src/validation.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, Form } from './types';\n\n/**\n * Whether or not the given item's value is valid according to the fields and form config.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return A boolean indicating if the item is valid (true) or not (false).\n */\nexport function isItemValid< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): boolean {\n\tconst _fields = normalizeFields(\n\t\tfields.filter( ( { id } ) => !! form.fields?.includes( id ) )\n\t);\n\n\tconst isEmptyNullOrUndefined = ( value: any ) =>\n\t\t[ undefined, '', null ].includes( value );\n\n\treturn _fields.every( ( field ) => {\n\t\tconst value = field.getValue( { item } );\n\n\t\tif ( field.isValid.required ) {\n\t\t\tif (\n\t\t\t\t( field.type === 'text' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'email' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'integer' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === undefined && isEmptyNullOrUndefined( value ) )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif ( field.type === 'boolean' && value !== true ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\ttypeof field.isValid.custom === 'function' &&\n\t\t\tfield.isValid.custom( item, field ) !== null\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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","require","isItemValid","item","fields","form","_fields","normalizeFields","filter","id","includes","isEmptyNullOrUndefined","value","undefined","every","field","getValue","isValid","required","type","custom"],"sources":["@wordpress/dataviews/src/validation.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, Form } from './types';\n\n/**\n * Whether or not the given item's value is valid according to the fields and form config.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return A boolean indicating if the item is valid (true) or not (false).\n */\nexport function isItemValid< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): boolean {\n\tconst _fields = normalizeFields(\n\t\tfields.filter( ( { id } ) => !! form.fields?.includes( id ) )\n\t);\n\n\tconst isEmptyNullOrUndefined = ( value: any ) =>\n\t\t[ undefined, '', null ].includes( value );\n\n\treturn _fields.every( ( field ) => {\n\t\tconst value = field.getValue( { item } );\n\n\t\tif ( field.isValid.required ) {\n\t\t\tif (\n\t\t\t\t( field.type === 'text' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'email' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'url' && isEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'telephone' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === 'integer' &&\n\t\t\t\t\tisEmptyNullOrUndefined( value ) ) ||\n\t\t\t\t( field.type === undefined && isEmptyNullOrUndefined( value ) )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tif ( field.type === 'boolean' && value !== true ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\ttypeof field.isValid.custom === 'function' &&\n\t\t\tfield.isValid.custom( item, field ) !== null\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAHA;AACA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