@wordpress/fields 0.23.0 → 0.23.1-next.233ccab9b.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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DataForm } from '@wordpress/dataviews';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
title: string;
|
|
4
|
+
component: typeof DataForm;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
export declare const DataFormsPreview: {
|
|
8
|
+
render: ({ type }: {
|
|
9
|
+
type: "regular" | "panel";
|
|
10
|
+
}) => import("react").JSX.Element;
|
|
11
|
+
argTypes: {
|
|
12
|
+
type: {
|
|
13
|
+
control: {
|
|
14
|
+
type: string;
|
|
15
|
+
};
|
|
16
|
+
description: string;
|
|
17
|
+
options: string[];
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
args: {
|
|
21
|
+
type: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare const DataViewsPreview: () => import("react").JSX.Element;
|
|
25
|
+
//# sourceMappingURL=index.story.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.story.d.ts","sourceRoot":"","sources":["../../src/stories/index.story.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAwB,MAAM,sBAAsB,CAAC;;;;;AA4BtE,wBAGE;AAkGF,eAAO,MAAM,gBAAgB;uBA1CU;QAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAA;KAAE;;;;;;;;;;;;;CAsDnE,CAAC;AAEF,eAAO,MAAM,gBAAgB,mCAuC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/fields",
|
|
3
|
-
"version": "0.23.0",
|
|
3
|
+
"version": "0.23.1-next.233ccab9b.0",
|
|
4
4
|
"description": "DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -33,29 +33,29 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/runtime": "7.25.7",
|
|
36
|
-
"@wordpress/api-fetch": "^7.31.0",
|
|
37
|
-
"@wordpress/blob": "^4.31.0",
|
|
38
|
-
"@wordpress/block-editor": "^15.4.0",
|
|
39
|
-
"@wordpress/blocks": "^15.4.0",
|
|
40
|
-
"@wordpress/components": "^30.
|
|
41
|
-
"@wordpress/compose": "^7.31.0",
|
|
42
|
-
"@wordpress/core-data": "^7.31.0",
|
|
43
|
-
"@wordpress/data": "^10.31.0",
|
|
44
|
-
"@wordpress/dataviews": "^9.
|
|
45
|
-
"@wordpress/date": "^5.31.0",
|
|
46
|
-
"@wordpress/element": "^6.31.0",
|
|
47
|
-
"@wordpress/hooks": "^4.31.0",
|
|
48
|
-
"@wordpress/html-entities": "^4.31.0",
|
|
49
|
-
"@wordpress/i18n": "^6.4.0",
|
|
50
|
-
"@wordpress/icons": "^10.31.0",
|
|
51
|
-
"@wordpress/media-utils": "^5.31.0",
|
|
52
|
-
"@wordpress/notices": "^5.31.0",
|
|
53
|
-
"@wordpress/patterns": "^2.31.0",
|
|
54
|
-
"@wordpress/primitives": "^4.31.0",
|
|
55
|
-
"@wordpress/private-apis": "^1.31.0",
|
|
56
|
-
"@wordpress/router": "^1.31.0",
|
|
57
|
-
"@wordpress/url": "^4.31.0",
|
|
58
|
-
"@wordpress/warning": "^3.31.0",
|
|
36
|
+
"@wordpress/api-fetch": "^7.31.1-next.233ccab9b.0",
|
|
37
|
+
"@wordpress/blob": "^4.31.1-next.233ccab9b.0",
|
|
38
|
+
"@wordpress/block-editor": "^15.4.1-next.233ccab9b.0",
|
|
39
|
+
"@wordpress/blocks": "^15.4.1-next.233ccab9b.0",
|
|
40
|
+
"@wordpress/components": "^30.5.1-next.233ccab9b.0",
|
|
41
|
+
"@wordpress/compose": "^7.31.1-next.233ccab9b.0",
|
|
42
|
+
"@wordpress/core-data": "^7.31.1-next.233ccab9b.0",
|
|
43
|
+
"@wordpress/data": "^10.31.1-next.233ccab9b.0",
|
|
44
|
+
"@wordpress/dataviews": "^9.1.1-next.233ccab9b.0",
|
|
45
|
+
"@wordpress/date": "^5.31.1-next.233ccab9b.0",
|
|
46
|
+
"@wordpress/element": "^6.31.1-next.233ccab9b.0",
|
|
47
|
+
"@wordpress/hooks": "^4.31.1-next.233ccab9b.0",
|
|
48
|
+
"@wordpress/html-entities": "^4.31.1-next.233ccab9b.0",
|
|
49
|
+
"@wordpress/i18n": "^6.4.1-next.233ccab9b.0",
|
|
50
|
+
"@wordpress/icons": "^10.31.1-next.233ccab9b.0",
|
|
51
|
+
"@wordpress/media-utils": "^5.31.1-next.233ccab9b.0",
|
|
52
|
+
"@wordpress/notices": "^5.31.1-next.233ccab9b.0",
|
|
53
|
+
"@wordpress/patterns": "^2.31.1-next.233ccab9b.0",
|
|
54
|
+
"@wordpress/primitives": "^4.31.1-next.233ccab9b.0",
|
|
55
|
+
"@wordpress/private-apis": "^1.31.1-next.233ccab9b.0",
|
|
56
|
+
"@wordpress/router": "^1.31.1-next.233ccab9b.0",
|
|
57
|
+
"@wordpress/url": "^4.31.1-next.233ccab9b.0",
|
|
58
|
+
"@wordpress/warning": "^3.31.1-next.233ccab9b.0",
|
|
59
59
|
"change-case": "4.1.2",
|
|
60
60
|
"client-zip": "^2.4.5",
|
|
61
61
|
"clsx": "2.1.1",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "d11f971521e4b39b07124d5c5516890ff98b0e31"
|
|
71
71
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
import { DataForm, DataViews, type Form } from '@wordpress/dataviews';
|
|
6
|
+
import type { Field, View } from '@wordpress/dataviews';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
authorField,
|
|
14
|
+
commentStatusField,
|
|
15
|
+
dateField,
|
|
16
|
+
orderField,
|
|
17
|
+
passwordField,
|
|
18
|
+
slugField,
|
|
19
|
+
statusField,
|
|
20
|
+
titleField,
|
|
21
|
+
} from '../fields';
|
|
22
|
+
|
|
23
|
+
// Fields not yet covered:
|
|
24
|
+
// featuredImageField,
|
|
25
|
+
// pageTitleField,
|
|
26
|
+
// parentField,
|
|
27
|
+
// patternTitleField,
|
|
28
|
+
// templateField,
|
|
29
|
+
// templateTitleField,
|
|
30
|
+
|
|
31
|
+
import type { BasePost, BasePostWithEmbeddedAuthor } from '../types';
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
title: 'Fields/Base Fields',
|
|
35
|
+
component: DataForm,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Sample data for different field types
|
|
39
|
+
const sampleBasePost: BasePost = {
|
|
40
|
+
id: 1,
|
|
41
|
+
title: { rendered: 'Sample Post Title', raw: 'Sample Post Title' },
|
|
42
|
+
content: {
|
|
43
|
+
rendered: '<p>This is sample content.</p>',
|
|
44
|
+
raw: 'This is sample content.',
|
|
45
|
+
},
|
|
46
|
+
type: 'post',
|
|
47
|
+
slug: 'sample-post-title',
|
|
48
|
+
permalink_template: 'http://localhost:8888/%postname%/',
|
|
49
|
+
date: '2024-01-15T10:30:00',
|
|
50
|
+
modified: '2024-01-20T14:45:00',
|
|
51
|
+
status: 'publish',
|
|
52
|
+
comment_status: 'open',
|
|
53
|
+
password: '',
|
|
54
|
+
parent: 0,
|
|
55
|
+
menu_order: 0,
|
|
56
|
+
author: 1,
|
|
57
|
+
featured_media: 123,
|
|
58
|
+
template: 'single',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const samplePostWithAuthor: BasePostWithEmbeddedAuthor = {
|
|
62
|
+
...sampleBasePost,
|
|
63
|
+
_embedded: {
|
|
64
|
+
author: [
|
|
65
|
+
{
|
|
66
|
+
name: 'John Doe',
|
|
67
|
+
avatar_urls: {
|
|
68
|
+
'24': 'https://gravatar.com/avatar?d=retro&s=24',
|
|
69
|
+
'48': 'https://gravatar.com/avatar?d=retro&s=48',
|
|
70
|
+
'96': 'https://gravatar.com/avatar?d=retro&s=96',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Create a showcase of all base fields.
|
|
78
|
+
// This does not include fields that require more complex setups,
|
|
79
|
+
// however this could be extended in the future, by setting up the data
|
|
80
|
+
// stores to contain entities like pages, users, media, etc.
|
|
81
|
+
const showcaseFields: Field< any >[] = [
|
|
82
|
+
titleField,
|
|
83
|
+
slugField,
|
|
84
|
+
statusField,
|
|
85
|
+
dateField,
|
|
86
|
+
authorField,
|
|
87
|
+
commentStatusField,
|
|
88
|
+
passwordField,
|
|
89
|
+
orderField,
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const DataFormsComponent = ( { type }: { type: 'regular' | 'panel' } ) => {
|
|
93
|
+
const [ data, setData ] = useState( samplePostWithAuthor );
|
|
94
|
+
|
|
95
|
+
const handleChange = ( updates: Partial< BasePostWithEmbeddedAuthor > ) => {
|
|
96
|
+
setData( ( prev ) => ( { ...prev, ...updates } ) );
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Form configuration for the showcase.
|
|
100
|
+
const showcaseForm: Form = {
|
|
101
|
+
layout: {
|
|
102
|
+
type,
|
|
103
|
+
},
|
|
104
|
+
fields: [
|
|
105
|
+
'title',
|
|
106
|
+
'slug',
|
|
107
|
+
'status',
|
|
108
|
+
'date',
|
|
109
|
+
'author',
|
|
110
|
+
'comment_status',
|
|
111
|
+
'password',
|
|
112
|
+
'menu_order',
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div style={ { padding: '20px' } }>
|
|
118
|
+
<h2>Base Fields</h2>
|
|
119
|
+
<p>
|
|
120
|
+
This story demonstrates all the base fields from the
|
|
121
|
+
@wordpress/fields package within a DataForm.
|
|
122
|
+
</p>
|
|
123
|
+
|
|
124
|
+
<DataForm
|
|
125
|
+
data={ data }
|
|
126
|
+
fields={ showcaseFields }
|
|
127
|
+
form={ showcaseForm }
|
|
128
|
+
onChange={ handleChange }
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const DataFormsPreview = {
|
|
135
|
+
render: DataFormsComponent,
|
|
136
|
+
argTypes: {
|
|
137
|
+
type: {
|
|
138
|
+
control: { type: 'select' },
|
|
139
|
+
description: 'Choose the layout type.',
|
|
140
|
+
options: [ 'regular', 'panel' ],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
args: {
|
|
144
|
+
type: 'regular',
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const DataViewsPreview = () => {
|
|
149
|
+
const [ view, setView ] = useState< View >( {
|
|
150
|
+
type: 'table',
|
|
151
|
+
fields: showcaseFields.map( ( f ) => f.id ),
|
|
152
|
+
titleField: 'title',
|
|
153
|
+
descriptionField: undefined,
|
|
154
|
+
mediaField: undefined,
|
|
155
|
+
} );
|
|
156
|
+
const [ data ] = useState( [ samplePostWithAuthor ] );
|
|
157
|
+
|
|
158
|
+
const paginationInfo = {
|
|
159
|
+
totalItems: 1,
|
|
160
|
+
totalPages: 1,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const defaultLayouts = {
|
|
164
|
+
table: {},
|
|
165
|
+
list: {},
|
|
166
|
+
grid: {},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<div style={ { padding: '20px' } }>
|
|
171
|
+
<h2>Fields Package DataViews Preview</h2>
|
|
172
|
+
<p>
|
|
173
|
+
This story demonstrates all the base fields from the
|
|
174
|
+
@wordpress/fields package, rendered in a DataViews component,
|
|
175
|
+
allowing preview of view state and layout switching.
|
|
176
|
+
</p>
|
|
177
|
+
<DataViews
|
|
178
|
+
data={ data }
|
|
179
|
+
fields={ showcaseFields }
|
|
180
|
+
view={ view }
|
|
181
|
+
onChangeView={ ( nextView: View ) => setView( nextView ) }
|
|
182
|
+
paginationInfo={ paginationInfo }
|
|
183
|
+
defaultLayouts={ defaultLayouts }
|
|
184
|
+
/>
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
};
|