@wordpress/dataviews 4.4.4 → 4.5.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 +2 -0
- package/README.md +4 -0
- package/build/components/dataform-combined-edit/index.js +67 -0
- package/build/components/dataform-combined-edit/index.js.map +1 -0
- package/build/components/dataviews-view-config/index.js +49 -38
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/dataforms-layouts/get-visible-fields.js +21 -0
- package/build/dataforms-layouts/get-visible-fields.js.map +1 -0
- package/build/dataforms-layouts/panel/index.js +2 -6
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/regular/index.js +2 -6
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/normalize-fields.js +21 -0
- package/build/normalize-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/validation.js.map +1 -1
- package/build-module/components/dataform-combined-edit/index.js +62 -0
- package/build-module/components/dataform-combined-edit/index.js.map +1 -0
- package/build-module/components/dataviews-view-config/index.js +50 -39
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/dataforms-layouts/get-visible-fields.js +14 -0
- package/build-module/dataforms-layouts/get-visible-fields.js.map +1 -0
- package/build-module/dataforms-layouts/panel/index.js +2 -6
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/regular/index.js +2 -6
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/normalize-fields.js +20 -0
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/validation.js.map +1 -1
- package/build-style/style-rtl.css +20 -4
- package/build-style/style.css +20 -4
- package/build-types/components/dataform/stories/index.story.d.ts +23 -0
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataform-combined-edit/index.d.ts +7 -0
- package/build-types/components/dataform-combined-edit/index.d.ts.map +1 -0
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/get-visible-fields.d.ts +3 -0
- package/build-types/dataforms-layouts/get-visible-fields.d.ts.map +1 -0
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
- package/build-types/normalize-fields.d.ts +9 -1
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/types.d.ts +27 -8
- package/build-types/types.d.ts.map +1 -1
- package/build-types/validation.d.ts +1 -1
- package/build-types/validation.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/components/dataform/stories/index.story.tsx +65 -0
- package/src/components/dataform-combined-edit/index.tsx +66 -0
- package/src/components/dataform-combined-edit/style.scss +12 -0
- package/src/components/dataviews-filters/style.scss +0 -1
- package/src/components/dataviews-view-config/index.tsx +52 -40
- package/src/components/dataviews-view-config/style.scss +5 -8
- package/src/dataforms-layouts/get-visible-fields.ts +29 -0
- package/src/dataforms-layouts/panel/index.tsx +8 -7
- package/src/dataforms-layouts/regular/index.tsx +8 -7
- package/src/normalize-fields.ts +33 -1
- package/src/style.scss +1 -0
- package/src/types.ts +29 -9
- package/src/validation.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -8,6 +8,7 @@ import type { ChangeEvent } from 'react';
|
|
|
8
8
|
*/
|
|
9
9
|
import {
|
|
10
10
|
Button,
|
|
11
|
+
__experimentalDropdownContentWrapper as DropdownContentWrapper,
|
|
11
12
|
Dropdown,
|
|
12
13
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
13
14
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
@@ -27,6 +28,7 @@ import { __, _x, sprintf } from '@wordpress/i18n';
|
|
|
27
28
|
import { memo, useContext, useMemo } from '@wordpress/element';
|
|
28
29
|
import { chevronDown, chevronUp, cog, seen, unseen } from '@wordpress/icons';
|
|
29
30
|
import warning from '@wordpress/warning';
|
|
31
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* Internal dependencies
|
|
@@ -55,6 +57,8 @@ interface ViewTypeMenuProps {
|
|
|
55
57
|
defaultLayouts?: SupportedLayouts;
|
|
56
58
|
}
|
|
57
59
|
|
|
60
|
+
const DATAVIEWS_CONFIG_POPOVER_PROPS = { placement: 'bottom-end', offset: 9 };
|
|
61
|
+
|
|
58
62
|
function ViewTypeMenu( {
|
|
59
63
|
defaultLayouts = { list: {}, grid: {}, table: {} },
|
|
60
64
|
}: ViewTypeMenuProps ) {
|
|
@@ -510,7 +514,7 @@ function SettingsSection( {
|
|
|
510
514
|
);
|
|
511
515
|
}
|
|
512
516
|
|
|
513
|
-
function
|
|
517
|
+
function DataviewsViewConfigDropdown( {
|
|
514
518
|
density,
|
|
515
519
|
setDensity,
|
|
516
520
|
}: {
|
|
@@ -518,25 +522,52 @@ function DataviewsViewConfigContent( {
|
|
|
518
522
|
setDensity: React.Dispatch< React.SetStateAction< number > >;
|
|
519
523
|
} ) {
|
|
520
524
|
const { view } = useContext( DataViewsContext );
|
|
525
|
+
const popoverId = useInstanceId(
|
|
526
|
+
_DataViewsViewConfig,
|
|
527
|
+
'dataviews-view-config-dropdown'
|
|
528
|
+
);
|
|
529
|
+
|
|
521
530
|
return (
|
|
522
|
-
<
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
<
|
|
530
|
-
|
|
531
|
-
|
|
531
|
+
<Dropdown
|
|
532
|
+
popoverProps={ {
|
|
533
|
+
...DATAVIEWS_CONFIG_POPOVER_PROPS,
|
|
534
|
+
id: popoverId,
|
|
535
|
+
} }
|
|
536
|
+
renderToggle={ ( { onToggle, isOpen } ) => {
|
|
537
|
+
return (
|
|
538
|
+
<Button
|
|
539
|
+
size="compact"
|
|
540
|
+
icon={ cog }
|
|
541
|
+
label={ _x( 'View options', 'View is used as a noun' ) }
|
|
542
|
+
onClick={ onToggle }
|
|
543
|
+
aria-expanded={ isOpen ? 'true' : 'false' }
|
|
544
|
+
aria-controls={ popoverId }
|
|
532
545
|
/>
|
|
533
|
-
)
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
546
|
+
);
|
|
547
|
+
} }
|
|
548
|
+
renderContent={ () => (
|
|
549
|
+
<DropdownContentWrapper paddingSize="medium">
|
|
550
|
+
<VStack className="dataviews-view-config" spacing={ 6 }>
|
|
551
|
+
<SettingsSection title={ __( 'Appearance' ) }>
|
|
552
|
+
<HStack expanded className="is-divided-in-two">
|
|
553
|
+
<SortFieldControl />
|
|
554
|
+
<SortDirectionControl />
|
|
555
|
+
</HStack>
|
|
556
|
+
{ view.type === LAYOUT_GRID && (
|
|
557
|
+
<DensityPicker
|
|
558
|
+
density={ density }
|
|
559
|
+
setDensity={ setDensity }
|
|
560
|
+
/>
|
|
561
|
+
) }
|
|
562
|
+
<ItemsPerPageControl />
|
|
563
|
+
</SettingsSection>
|
|
564
|
+
<SettingsSection title={ __( 'Properties' ) }>
|
|
565
|
+
<FieldControl />
|
|
566
|
+
</SettingsSection>
|
|
567
|
+
</VStack>
|
|
568
|
+
</DropdownContentWrapper>
|
|
569
|
+
) }
|
|
570
|
+
/>
|
|
540
571
|
);
|
|
541
572
|
}
|
|
542
573
|
|
|
@@ -552,28 +583,9 @@ function _DataViewsViewConfig( {
|
|
|
552
583
|
return (
|
|
553
584
|
<>
|
|
554
585
|
<ViewTypeMenu defaultLayouts={ defaultLayouts } />
|
|
555
|
-
<
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
renderToggle={ ( { onToggle } ) => {
|
|
559
|
-
return (
|
|
560
|
-
<Button
|
|
561
|
-
size="compact"
|
|
562
|
-
icon={ cog }
|
|
563
|
-
label={ _x(
|
|
564
|
-
'View options',
|
|
565
|
-
'View is used as a noun'
|
|
566
|
-
) }
|
|
567
|
-
onClick={ onToggle }
|
|
568
|
-
/>
|
|
569
|
-
);
|
|
570
|
-
} }
|
|
571
|
-
renderContent={ () => (
|
|
572
|
-
<DataviewsViewConfigContent
|
|
573
|
-
density={ density }
|
|
574
|
-
setDensity={ setDensity }
|
|
575
|
-
/>
|
|
576
|
-
) }
|
|
586
|
+
<DataviewsViewConfigDropdown
|
|
587
|
+
density={ density }
|
|
588
|
+
setDensity={ setDensity }
|
|
577
589
|
/>
|
|
578
590
|
</>
|
|
579
591
|
);
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
.dataviews-view-config {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
font-size: $default-font-size;
|
|
8
|
-
line-height: $default-line-height;
|
|
9
|
-
}
|
|
2
|
+
width: 320px;
|
|
3
|
+
/* stylelint-disable-next-line property-no-unknown -- the linter needs to be updated to accepted the container-type property */
|
|
4
|
+
container-type: inline-size;
|
|
5
|
+
font-size: $default-font-size;
|
|
6
|
+
line-height: $default-line-height;
|
|
10
7
|
}
|
|
11
8
|
|
|
12
9
|
.dataviews-view-config__sort-direction .components-toggle-group-control-option-base {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { normalizeCombinedFields } from '../normalize-fields';
|
|
5
|
+
import type {
|
|
6
|
+
Field,
|
|
7
|
+
CombinedFormField,
|
|
8
|
+
NormalizedCombinedFormField,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
export function getVisibleFields< Item >(
|
|
12
|
+
fields: Field< Item >[],
|
|
13
|
+
formFields: string[] = [],
|
|
14
|
+
combinedFields?: CombinedFormField< Item >[]
|
|
15
|
+
): Field< Item >[] {
|
|
16
|
+
const visibleFields: Array<
|
|
17
|
+
Field< Item > | NormalizedCombinedFormField< Item >
|
|
18
|
+
> = [ ...fields ];
|
|
19
|
+
if ( combinedFields ) {
|
|
20
|
+
visibleFields.push(
|
|
21
|
+
...normalizeCombinedFields( combinedFields, fields )
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return formFields
|
|
25
|
+
.map( ( fieldId ) =>
|
|
26
|
+
visibleFields.find( ( { id } ) => id === fieldId )
|
|
27
|
+
)
|
|
28
|
+
.filter( ( field ): field is Field< Item > => !! field );
|
|
29
|
+
}
|
|
@@ -17,7 +17,8 @@ import { closeSmall } from '@wordpress/icons';
|
|
|
17
17
|
* Internal dependencies
|
|
18
18
|
*/
|
|
19
19
|
import { normalizeFields } from '../../normalize-fields';
|
|
20
|
-
import
|
|
20
|
+
import { getVisibleFields } from '../get-visible-fields';
|
|
21
|
+
import type { DataFormProps, NormalizedField } from '../../types';
|
|
21
22
|
|
|
22
23
|
interface FormFieldProps< Item > {
|
|
23
24
|
data: Item;
|
|
@@ -142,13 +143,13 @@ export default function FormPanel< Item >( {
|
|
|
142
143
|
const visibleFields = useMemo(
|
|
143
144
|
() =>
|
|
144
145
|
normalizeFields(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
getVisibleFields< Item >(
|
|
147
|
+
fields,
|
|
148
|
+
form.fields,
|
|
149
|
+
form.combinedFields
|
|
150
|
+
)
|
|
150
151
|
),
|
|
151
|
-
[ fields, form.fields ]
|
|
152
|
+
[ fields, form.fields, form.combinedFields ]
|
|
152
153
|
);
|
|
153
154
|
|
|
154
155
|
return (
|
|
@@ -8,7 +8,8 @@ import { useMemo } from '@wordpress/element';
|
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { normalizeFields } from '../../normalize-fields';
|
|
11
|
-
import
|
|
11
|
+
import { getVisibleFields } from '../get-visible-fields';
|
|
12
|
+
import type { DataFormProps } from '../../types';
|
|
12
13
|
|
|
13
14
|
export default function FormRegular< Item >( {
|
|
14
15
|
data,
|
|
@@ -19,13 +20,13 @@ export default function FormRegular< Item >( {
|
|
|
19
20
|
const visibleFields = useMemo(
|
|
20
21
|
() =>
|
|
21
22
|
normalizeFields(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
getVisibleFields< Item >(
|
|
24
|
+
fields,
|
|
25
|
+
form.fields,
|
|
26
|
+
form.combinedFields
|
|
27
|
+
)
|
|
27
28
|
),
|
|
28
|
-
[ fields, form.fields ]
|
|
29
|
+
[ fields, form.fields, form.combinedFields ]
|
|
29
30
|
);
|
|
30
31
|
|
|
31
32
|
return (
|
package/src/normalize-fields.ts
CHANGED
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import getFieldTypeDefinition from './field-types';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
CombinedFormField,
|
|
7
|
+
Field,
|
|
8
|
+
NormalizedField,
|
|
9
|
+
NormalizedCombinedFormField,
|
|
10
|
+
} from './types';
|
|
6
11
|
import { getControl } from './dataform-controls';
|
|
12
|
+
import DataFormCombinedEdit from './components/dataform-combined-edit';
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
15
|
* Apply default values and normalize the fields config.
|
|
@@ -66,3 +72,29 @@ export function normalizeFields< Item >(
|
|
|
66
72
|
};
|
|
67
73
|
} );
|
|
68
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Apply default values and normalize the fields config.
|
|
78
|
+
*
|
|
79
|
+
* @param combinedFields combined field list.
|
|
80
|
+
* @param fields Fields config.
|
|
81
|
+
* @return Normalized fields config.
|
|
82
|
+
*/
|
|
83
|
+
export function normalizeCombinedFields< Item >(
|
|
84
|
+
combinedFields: CombinedFormField< Item >[],
|
|
85
|
+
fields: Field< Item >[]
|
|
86
|
+
): NormalizedCombinedFormField< Item >[] {
|
|
87
|
+
return combinedFields.map( ( combinedField ) => {
|
|
88
|
+
return {
|
|
89
|
+
...combinedField,
|
|
90
|
+
Edit: DataFormCombinedEdit,
|
|
91
|
+
fields: normalizeFields(
|
|
92
|
+
combinedField.children
|
|
93
|
+
.map( ( fieldId ) =>
|
|
94
|
+
fields.find( ( { id } ) => id === fieldId )
|
|
95
|
+
)
|
|
96
|
+
.filter( ( field ): field is Field< Item > => !! field )
|
|
97
|
+
),
|
|
98
|
+
};
|
|
99
|
+
} );
|
|
100
|
+
}
|
package/src/style.scss
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
@import "./components/dataviews-item-actions/style.scss";
|
|
7
7
|
@import "./components/dataviews-selection-checkbox/style.scss";
|
|
8
8
|
@import "./components/dataviews-view-config/style.scss";
|
|
9
|
+
@import "./components/dataform-combined-edit/style.scss";
|
|
9
10
|
|
|
10
11
|
@import "./dataviews-layouts/grid/style.scss";
|
|
11
12
|
@import "./dataviews-layouts/list/style.scss";
|
package/src/types.ts
CHANGED
|
@@ -174,14 +174,6 @@ export type Fields< Item > = Field< Item >[];
|
|
|
174
174
|
|
|
175
175
|
export type Data< Item > = Item[];
|
|
176
176
|
|
|
177
|
-
/**
|
|
178
|
-
* The form configuration.
|
|
179
|
-
*/
|
|
180
|
-
export type Form = {
|
|
181
|
-
type?: 'regular' | 'panel';
|
|
182
|
-
fields?: string[];
|
|
183
|
-
};
|
|
184
|
-
|
|
185
177
|
export type DataFormControlProps< Item > = {
|
|
186
178
|
data: Item;
|
|
187
179
|
field: NormalizedField< Item >;
|
|
@@ -524,9 +516,37 @@ export interface SupportedLayouts {
|
|
|
524
516
|
table?: Omit< ViewTable, 'type' >;
|
|
525
517
|
}
|
|
526
518
|
|
|
519
|
+
export interface CombinedFormField< Item > extends CombinedField {
|
|
520
|
+
render?: ComponentType< { item: Item } >;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
export interface DataFormCombinedEditProps< Item > {
|
|
524
|
+
field: NormalizedCombinedFormField< Item >;
|
|
525
|
+
data: Item;
|
|
526
|
+
onChange: ( value: Record< string, any > ) => void;
|
|
527
|
+
hideLabelFromVision?: boolean;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export type NormalizedCombinedFormField< Item > = CombinedFormField< Item > & {
|
|
531
|
+
fields: NormalizedField< Item >[];
|
|
532
|
+
Edit?: ComponentType< DataFormCombinedEditProps< Item > >;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* The form configuration.
|
|
537
|
+
*/
|
|
538
|
+
export type Form< Item > = {
|
|
539
|
+
type?: 'regular' | 'panel';
|
|
540
|
+
fields?: string[];
|
|
541
|
+
/**
|
|
542
|
+
* The fields to combine.
|
|
543
|
+
*/
|
|
544
|
+
combinedFields?: CombinedFormField< Item >[];
|
|
545
|
+
};
|
|
546
|
+
|
|
527
547
|
export interface DataFormProps< Item > {
|
|
528
548
|
data: Item;
|
|
529
549
|
fields: Field< Item >[];
|
|
530
|
-
form: Form
|
|
550
|
+
form: Form< Item >;
|
|
531
551
|
onChange: ( value: Record< string, any > ) => void;
|
|
532
552
|
}
|
package/src/validation.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { Field, Form } from './types';
|
|
|
7
7
|
export function isItemValid< Item >(
|
|
8
8
|
item: Item,
|
|
9
9
|
fields: Field< Item >[],
|
|
10
|
-
form: Form
|
|
10
|
+
form: Form< Item >
|
|
11
11
|
): boolean {
|
|
12
12
|
const _fields = normalizeFields(
|
|
13
13
|
fields.filter( ( { id } ) => !! form.fields?.includes( id ) )
|