@wordpress/fields 0.4.0 → 0.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +4 -0
  3. package/build/fields/author/author-view.js +72 -0
  4. package/build/fields/author/author-view.js.map +1 -0
  5. package/build/fields/author/index.js +35 -0
  6. package/build/fields/author/index.js.map +1 -0
  7. package/build/fields/index.js +7 -0
  8. package/build/fields/index.js.map +1 -1
  9. package/build/index.js.map +1 -1
  10. package/build/types.js.map +1 -1
  11. package/build-module/fields/author/author-view.js +64 -0
  12. package/build-module/fields/author/author-view.js.map +1 -0
  13. package/build-module/fields/author/index.js +29 -0
  14. package/build-module/fields/author/index.js.map +1 -0
  15. package/build-module/fields/index.js +1 -0
  16. package/build-module/fields/index.js.map +1 -1
  17. package/build-module/index.js.map +1 -1
  18. package/build-module/types.js.map +1 -1
  19. package/build-style/style-rtl.css +2 -4
  20. package/build-style/style.css +2 -4
  21. package/build-types/fields/author/author-view.d.ts +9 -0
  22. package/build-types/fields/author/author-view.d.ts.map +1 -0
  23. package/build-types/fields/author/index.d.ts +14 -0
  24. package/build-types/fields/author/index.d.ts.map +1 -0
  25. package/build-types/fields/index.d.ts +1 -0
  26. package/build-types/fields/index.d.ts.map +1 -1
  27. package/build-types/index.d.ts +1 -0
  28. package/build-types/index.d.ts.map +1 -1
  29. package/build-types/types.d.ts +11 -0
  30. package/build-types/types.d.ts.map +1 -1
  31. package/package.json +3 -2
  32. package/src/fields/author/author-view.tsx +63 -0
  33. package/src/fields/author/index.tsx +32 -0
  34. package/src/fields/featured-image/style.scss +2 -5
  35. package/src/fields/index.ts +1 -0
  36. package/src/index.ts +1 -0
  37. package/src/types.ts +14 -0
  38. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.5.0 (2024-11-27)
6
+
5
7
  ## 0.4.0 (2024-11-16)
6
8
 
7
9
  ## 0.3.0 (2024-10-30)
package/README.md CHANGED
@@ -14,6 +14,10 @@ npm install @wordpress/fields --save
14
14
 
15
15
  <!-- START TOKEN(Autogenerated API docs) -->
16
16
 
17
+ ### authorField
18
+
19
+ Author field for BasePost.
20
+
17
21
  ### commentStatusField
18
22
 
19
23
  Comment status field for BasePost.
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _clsx = _interopRequireDefault(require("clsx"));
9
+ var _i18n = require("@wordpress/i18n");
10
+ var _element = require("@wordpress/element");
11
+ var _icons = require("@wordpress/icons");
12
+ var _components = require("@wordpress/components");
13
+ var _data = require("@wordpress/data");
14
+ var _coreData = require("@wordpress/core-data");
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ /**
17
+ * External dependencies
18
+ */
19
+
20
+ /**
21
+ * WordPress dependencies
22
+ */
23
+
24
+ /**
25
+ * Internal dependencies
26
+ */
27
+
28
+ function AuthorView({
29
+ item
30
+ }) {
31
+ const {
32
+ text,
33
+ imageUrl
34
+ } = (0, _data.useSelect)(select => {
35
+ const {
36
+ getEntityRecord
37
+ } = select(_coreData.store);
38
+ let user;
39
+ if (!!item.author) {
40
+ user = getEntityRecord('root', 'user', item.author);
41
+ }
42
+ return {
43
+ imageUrl: user?.avatar_urls?.[48],
44
+ text: user?.name
45
+ };
46
+ }, [item]);
47
+ const [isImageLoaded, setIsImageLoaded] = (0, _element.useState)(false);
48
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
49
+ alignment: "left",
50
+ spacing: 0,
51
+ children: [!!imageUrl && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
52
+ className: (0, _clsx.default)('page-templates-author-field__avatar', {
53
+ 'is-loaded': isImageLoaded
54
+ }),
55
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
56
+ onLoad: () => setIsImageLoaded(true),
57
+ alt: (0, _i18n.__)('Author avatar'),
58
+ src: imageUrl
59
+ })
60
+ }), !imageUrl && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
61
+ className: "page-templates-author-field__icon",
62
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
63
+ icon: _icons.commentAuthorAvatar
64
+ })
65
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
66
+ className: "page-templates-author-field__name",
67
+ children: text
68
+ })]
69
+ });
70
+ }
71
+ var _default = exports.default = AuthorView;
72
+ //# sourceMappingURL=author-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_clsx","_interopRequireDefault","require","_i18n","_element","_icons","_components","_data","_coreData","_jsxRuntime","AuthorView","item","text","imageUrl","useSelect","select","getEntityRecord","coreStore","user","author","avatar_urls","name","isImageLoaded","setIsImageLoaded","useState","jsxs","__experimentalHStack","alignment","spacing","children","jsx","className","clsx","onLoad","alt","__","src","Icon","icon","authorIcon","_default","exports","default"],"sources":["@wordpress/fields/src/fields/author/author-view.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport { __experimentalHStack as HStack, Icon } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { User } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\n\nfunction AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) {\n\tconst { text, imageUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\t\t\tlet user: User | undefined;\n\t\t\tif ( !! item.author ) {\n\t\t\t\tuser = getEntityRecord( 'root', 'user', item.author );\n\t\t\t}\n\t\t\treturn {\n\t\t\t\timageUrl: user?.avatar_urls?.[ 48 ],\n\t\t\t\ttext: user?.name,\n\t\t\t};\n\t\t},\n\t\t[ item ]\n\t);\n\tconst [ isImageLoaded, setIsImageLoaded ] = useState( false );\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ !! imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'page-templates-author-field__avatar', {\n\t\t\t\t\t\t'is-loaded': isImageLoaded,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tonLoad={ () => setIsImageLoaded( true ) }\n\t\t\t\t\t\talt={ __( 'Author avatar' ) }\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"page-templates-author-field__icon\">\n\t\t\t\t\t<Icon icon={ authorIcon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"page-templates-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n\nexport default AuthorView;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAA0D,IAAAO,WAAA,GAAAP,OAAA;AAb1D;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAGA,SAASQ,UAAUA,CAAE;EAAEC;AAA2C,CAAC,EAAG;EACrE,MAAM;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAG,IAAAC,eAAS,EACjCC,MAA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AAF,QAAA,EAAGjB;IAAI,CAAQ,CAAC;EAAA,CAC5D,CAAC;AAEX;AAAC,IAAA4B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEchC,UAAU","ignoreList":[]}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _i18n = require("@wordpress/i18n");
9
+ var _authorView = _interopRequireDefault(require("./author-view"));
10
+ /**
11
+ * WordPress dependencies
12
+ */
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+
18
+ const authorField = {
19
+ label: (0, _i18n.__)('Author'),
20
+ id: 'author',
21
+ type: 'integer',
22
+ elements: [],
23
+ render: _authorView.default,
24
+ sort: (a, b, direction) => {
25
+ const nameA = a._embedded?.author?.[0]?.name || '';
26
+ const nameB = b._embedded?.author?.[0]?.name || '';
27
+ return direction === 'asc' ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
28
+ }
29
+ };
30
+
31
+ /**
32
+ * Author field for BasePost.
33
+ */
34
+ var _default = exports.default = authorField;
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_i18n","require","_authorView","_interopRequireDefault","authorField","label","__","id","type","elements","render","AuthorView","sort","a","b","direction","nameA","_embedded","author","name","nameB","localeCompare","_default","exports","default"],"sources":["@wordpress/fields/src/fields/author/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\telements: [],\n\trender: AuthorView,\n\tsort: ( a, b, direction ) => {\n\t\tconst nameA = a._embedded?.author?.[ 0 ]?.name || '';\n\t\tconst nameB = b._embedded?.author?.[ 0 ]?.name || '';\n\n\t\treturn direction === 'asc'\n\t\t\t? nameA.localeCompare( nameB )\n\t\t\t: nameB.localeCompare( nameA );\n\t},\n};\n\n/**\n * Author field for BasePost.\n */\nexport default authorField;\n"],"mappings":";;;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA,MAAMG,WAAgD,GAAG;EACxDC,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS,CAAC;EACrBC,EAAE,EAAE,QAAQ;EACZC,IAAI,EAAE,SAAS;EACfC,QAAQ,EAAE,EAAE;EACZC,MAAM,EAAEC,mBAAU;EAClBC,IAAI,EAAEA,CAAEC,CAAC,EAAEC,CAAC,EAAEC,SAAS,KAAM;IAC5B,MAAMC,KAAK,GAAGH,CAAC,CAACI,SAAS,EAAEC,MAAM,GAAI,CAAC,CAAE,EAAEC,IAAI,IAAI,EAAE;IACpD,MAAMC,KAAK,GAAGN,CAAC,CAACG,SAAS,EAAEC,MAAM,GAAI,CAAC,CAAE,EAAEC,IAAI,IAAI,EAAE;IAEpD,OAAOJ,SAAS,KAAK,KAAK,GACvBC,KAAK,CAACK,aAAa,CAAED,KAAM,CAAC,GAC5BA,KAAK,CAACC,aAAa,CAAEL,KAAM,CAAC;EAChC;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAM,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGepB,WAAW","ignoreList":[]}
@@ -4,6 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ Object.defineProperty(exports, "authorField", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _author.default;
11
+ }
12
+ });
7
13
  Object.defineProperty(exports, "commentStatusField", {
8
14
  enumerable: true,
9
15
  get: function () {
@@ -67,4 +73,5 @@ var _password = _interopRequireDefault(require("./password"));
67
73
  var _status = _interopRequireDefault(require("./status"));
68
74
  var _commentStatus = _interopRequireDefault(require("./comment-status"));
69
75
  var _date = _interopRequireDefault(require("./date"));
76
+ var _author = _interopRequireDefault(require("./author"));
70
77
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_slug","_interopRequireDefault","require","_title","_order","_featuredImage","_parent","_password","_status","_commentStatus","_date"],"sources":["@wordpress/fields/src/fields/index.ts"],"sourcesContent":["export { default as slugField } from './slug';\nexport { default as titleField } from './title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as parentField } from './parent';\nexport { default as passwordField } from './password';\nexport { default as statusField } from './status';\nexport { default as commentStatusField } from './comment-status';\nexport { default as dateField } from './date';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,SAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,KAAA,GAAAT,sBAAA,CAAAC,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_slug","_interopRequireDefault","require","_title","_order","_featuredImage","_parent","_password","_status","_commentStatus","_date","_author"],"sources":["@wordpress/fields/src/fields/index.ts"],"sourcesContent":["export { default as slugField } from './slug';\nexport { default as titleField } from './title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as parentField } from './parent';\nexport { default as passwordField } from './password';\nexport { default as statusField } from './status';\nexport { default as commentStatusField } from './comment-status';\nexport { default as dateField } from './date';\nexport { default as authorField } from './author';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,SAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,KAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,OAAA,GAAAV,sBAAA,CAAAC,OAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["_fields","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_actions"],"sources":["@wordpress/fields/src/index.ts"],"sourcesContent":["export * from './fields';\nexport * from './actions';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,QAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,QAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,QAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_fields","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_actions"],"sources":["@wordpress/fields/src/index.ts"],"sourcesContent":["export * from './fields';\nexport * from './actions';\nexport type * from './types';\n"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,QAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,QAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,QAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,QAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\ninterface Author {\n\tname: string;\n\tavatar_urls: Record< string, string >;\n}\n\ninterface EmbeddedAuthor {\n\tauthor: Author[];\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n\tauthor?: number;\n}\n\nexport interface BasePostWithEmbeddedAuthor extends BasePost {\n\t_embedded: EmbeddedAuthor;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import clsx from 'clsx';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { __ } from '@wordpress/i18n';
10
+ import { useState } from '@wordpress/element';
11
+ import { commentAuthorAvatar as authorIcon } from '@wordpress/icons';
12
+ import { __experimentalHStack as HStack, Icon } from '@wordpress/components';
13
+ import { useSelect } from '@wordpress/data';
14
+ import { store as coreStore } from '@wordpress/core-data';
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
+ function AuthorView({
21
+ item
22
+ }) {
23
+ const {
24
+ text,
25
+ imageUrl
26
+ } = useSelect(select => {
27
+ const {
28
+ getEntityRecord
29
+ } = select(coreStore);
30
+ let user;
31
+ if (!!item.author) {
32
+ user = getEntityRecord('root', 'user', item.author);
33
+ }
34
+ return {
35
+ imageUrl: user?.avatar_urls?.[48],
36
+ text: user?.name
37
+ };
38
+ }, [item]);
39
+ const [isImageLoaded, setIsImageLoaded] = useState(false);
40
+ return /*#__PURE__*/_jsxs(HStack, {
41
+ alignment: "left",
42
+ spacing: 0,
43
+ children: [!!imageUrl && /*#__PURE__*/_jsx("div", {
44
+ className: clsx('page-templates-author-field__avatar', {
45
+ 'is-loaded': isImageLoaded
46
+ }),
47
+ children: /*#__PURE__*/_jsx("img", {
48
+ onLoad: () => setIsImageLoaded(true),
49
+ alt: __('Author avatar'),
50
+ src: imageUrl
51
+ })
52
+ }), !imageUrl && /*#__PURE__*/_jsx("div", {
53
+ className: "page-templates-author-field__icon",
54
+ children: /*#__PURE__*/_jsx(Icon, {
55
+ icon: authorIcon
56
+ })
57
+ }), /*#__PURE__*/_jsx("span", {
58
+ className: "page-templates-author-field__name",
59
+ children: text
60
+ })]
61
+ });
62
+ }
63
+ export default AuthorView;
64
+ //# sourceMappingURL=author-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["clsx","__","useState","commentAuthorAvatar","authorIcon","__experimentalHStack","HStack","Icon","useSelect","store","coreStore","jsx","_jsx","jsxs","_jsxs","AuthorView","item","text","imageUrl","select","getEntityRecord","user","author","avatar_urls","name","isImageLoaded","setIsImageLoaded","alignment","spacing","children","className","onLoad","alt","src","icon"],"sources":["@wordpress/fields/src/fields/author/author-view.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport { __experimentalHStack as HStack, Icon } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { User } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\n\nfunction AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) {\n\tconst { text, imageUrl } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord } = select( coreStore );\n\t\t\tlet user: User | undefined;\n\t\t\tif ( !! item.author ) {\n\t\t\t\tuser = getEntityRecord( 'root', 'user', item.author );\n\t\t\t}\n\t\t\treturn {\n\t\t\t\timageUrl: user?.avatar_urls?.[ 48 ],\n\t\t\t\ttext: user?.name,\n\t\t\t};\n\t\t},\n\t\t[ item ]\n\t);\n\tconst [ isImageLoaded, setIsImageLoaded ] = useState( false );\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ !! imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'page-templates-author-field__avatar', {\n\t\t\t\t\t\t'is-loaded': isImageLoaded,\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tonLoad={ () => setIsImageLoaded( true ) }\n\t\t\t\t\t\talt={ __( 'Author avatar' ) }\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"page-templates-author-field__icon\">\n\t\t\t\t\t<Icon icon={ authorIcon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"page-templates-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n\nexport default AuthorView;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,mBAAmB,IAAIC,UAAU,QAAQ,kBAAkB;AACpE,SAASC,oBAAoB,IAAIC,MAAM,EAAEC,IAAI,QAAQ,uBAAuB;AAC5E,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;;AAGzD;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAKA,SAASC,UAAUA,CAAE;EAAEC;AAA2C,CAAC,EAAG;EACrE,MAAM;IAAEC,IAAI;IAAEC;EAAS,CAAC,GAAGV,SAAS,CACjCW,MAAM,IAAM;IACb,MAAM;MAAEC;IAAgB,CAAC,GAAGD,MAAM,CAAET,SAAU,CAAC;IAC/C,IAAIW,IAAsB;IAC1B,IAAK,CAAC,CAAEL,IAAI,CAACM,MAAM,EAAG;MACrBD,IAAI,GAAGD,eAAe,CAAE,MAAM,EAAE,MAAM,EAAEJ,IAAI,CAACM,MAAO,CAAC;IACtD;IACA,OAAO;MACNJ,QAAQ,EAAEG,IAAI,EAAEE,WAAW,GAAI,EAAE,CAAE;MACnCN,IAAI,EAAEI,IAAI,EAAEG;IACb,CAAC;EACF,CAAC,EACD,CAAER,IAAI,CACP,CAAC;EACD,MAAM,CAAES,aAAa,EAAEC,gBAAgB,CAAE,GAAGxB,QAAQ,CAAE,KAAM,CAAC;EAC7D,oBACCY,KAAA,CAACR,MAAM;IAACqB,SAAS,EAAC,MAAM;IAACC,OAAO,EAAG,CAAG;IAAAC,QAAA,GACnC,CAAC,CAAEX,QAAQ,iBACZN,IAAA;MACCkB,SAAS,EAAG9B,IAAI,CAAE,qCAAqC,EAAE;QACxD,WAAW,EAAEyB;MACd,CAAE,CAAG;MAAAI,QAAA,eAELjB,IAAA;QACCmB,MAAM,EAAGA,CAAA,KAAML,gBAAgB,CAAE,IAAK,CAAG;QACzCM,GAAG,EAAG/B,EAAE,CAAE,eAAgB,CAAG;QAC7BgC,GAAG,EAAGf;MAAU,CAChB;IAAC,CACE,CACL,EACC,CAAEA,QAAQ,iBACXN,IAAA;MAAKkB,SAAS,EAAC,mCAAmC;MAAAD,QAAA,eACjDjB,IAAA,CAACL,IAAI;QAAC2B,IAAI,EAAG9B;MAAY,CAAE;IAAC,CACxB,CACL,eACDQ,IAAA;MAAMkB,SAAS,EAAC,mCAAmC;MAAAD,QAAA,EAAGZ;IAAI,CAAQ,CAAC;EAAA,CAC5D,CAAC;AAEX;AAEA,eAAeF,UAAU","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+
11
+ import AuthorView from './author-view';
12
+ const authorField = {
13
+ label: __('Author'),
14
+ id: 'author',
15
+ type: 'integer',
16
+ elements: [],
17
+ render: AuthorView,
18
+ sort: (a, b, direction) => {
19
+ const nameA = a._embedded?.author?.[0]?.name || '';
20
+ const nameB = b._embedded?.author?.[0]?.name || '';
21
+ return direction === 'asc' ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA);
22
+ }
23
+ };
24
+
25
+ /**
26
+ * Author field for BasePost.
27
+ */
28
+ export default authorField;
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__","AuthorView","authorField","label","id","type","elements","render","sort","a","b","direction","nameA","_embedded","author","name","nameB","localeCompare"],"sources":["@wordpress/fields/src/fields/author/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePostWithEmbeddedAuthor } from '../../types';\nimport AuthorView from './author-view';\n\nconst authorField: Field< BasePostWithEmbeddedAuthor > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\telements: [],\n\trender: AuthorView,\n\tsort: ( a, b, direction ) => {\n\t\tconst nameA = a._embedded?.author?.[ 0 ]?.name || '';\n\t\tconst nameB = b._embedded?.author?.[ 0 ]?.name || '';\n\n\t\treturn direction === 'asc'\n\t\t\t? nameA.localeCompare( nameB )\n\t\t\t: nameB.localeCompare( nameA );\n\t},\n};\n\n/**\n * Author field for BasePost.\n */\nexport default authorField;\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;;AAEA,OAAOC,UAAU,MAAM,eAAe;AAEtC,MAAMC,WAAgD,GAAG;EACxDC,KAAK,EAAEH,EAAE,CAAE,QAAS,CAAC;EACrBI,EAAE,EAAE,QAAQ;EACZC,IAAI,EAAE,SAAS;EACfC,QAAQ,EAAE,EAAE;EACZC,MAAM,EAAEN,UAAU;EAClBO,IAAI,EAAEA,CAAEC,CAAC,EAAEC,CAAC,EAAEC,SAAS,KAAM;IAC5B,MAAMC,KAAK,GAAGH,CAAC,CAACI,SAAS,EAAEC,MAAM,GAAI,CAAC,CAAE,EAAEC,IAAI,IAAI,EAAE;IACpD,MAAMC,KAAK,GAAGN,CAAC,CAACG,SAAS,EAAEC,MAAM,GAAI,CAAC,CAAE,EAAEC,IAAI,IAAI,EAAE;IAEpD,OAAOJ,SAAS,KAAK,KAAK,GACvBC,KAAK,CAACK,aAAa,CAAED,KAAM,CAAC,GAC5BA,KAAK,CAACC,aAAa,CAAEL,KAAM,CAAC;EAChC;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAeV,WAAW","ignoreList":[]}
@@ -7,4 +7,5 @@ export { default as passwordField } from './password';
7
7
  export { default as statusField } from './status';
8
8
  export { default as commentStatusField } from './comment-status';
9
9
  export { default as dateField } from './date';
10
+ export { default as authorField } from './author';
10
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["default","slugField","titleField","orderField","featuredImageField","parentField","passwordField","statusField","commentStatusField","dateField"],"sources":["@wordpress/fields/src/fields/index.ts"],"sourcesContent":["export { default as slugField } from './slug';\nexport { default as titleField } from './title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as parentField } from './parent';\nexport { default as passwordField } from './password';\nexport { default as statusField } from './status';\nexport { default as commentStatusField } from './comment-status';\nexport { default as dateField } from './date';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,SAAS,QAAQ,QAAQ;AAC7C,SAASD,OAAO,IAAIE,UAAU,QAAQ,SAAS;AAC/C,SAASF,OAAO,IAAIG,UAAU,QAAQ,SAAS;AAC/C,SAASH,OAAO,IAAII,kBAAkB,QAAQ,kBAAkB;AAChE,SAASJ,OAAO,IAAIK,WAAW,QAAQ,UAAU;AACjD,SAASL,OAAO,IAAIM,aAAa,QAAQ,YAAY;AACrD,SAASN,OAAO,IAAIO,WAAW,QAAQ,UAAU;AACjD,SAASP,OAAO,IAAIQ,kBAAkB,QAAQ,kBAAkB;AAChE,SAASR,OAAO,IAAIS,SAAS,QAAQ,QAAQ","ignoreList":[]}
1
+ {"version":3,"names":["default","slugField","titleField","orderField","featuredImageField","parentField","passwordField","statusField","commentStatusField","dateField","authorField"],"sources":["@wordpress/fields/src/fields/index.ts"],"sourcesContent":["export { default as slugField } from './slug';\nexport { default as titleField } from './title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as parentField } from './parent';\nexport { default as passwordField } from './password';\nexport { default as statusField } from './status';\nexport { default as commentStatusField } from './comment-status';\nexport { default as dateField } from './date';\nexport { default as authorField } from './author';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,SAAS,QAAQ,QAAQ;AAC7C,SAASD,OAAO,IAAIE,UAAU,QAAQ,SAAS;AAC/C,SAASF,OAAO,IAAIG,UAAU,QAAQ,SAAS;AAC/C,SAASH,OAAO,IAAII,kBAAkB,QAAQ,kBAAkB;AAChE,SAASJ,OAAO,IAAIK,WAAW,QAAQ,UAAU;AACjD,SAASL,OAAO,IAAIM,aAAa,QAAQ,YAAY;AACrD,SAASN,OAAO,IAAIO,WAAW,QAAQ,UAAU;AACjD,SAASP,OAAO,IAAIQ,kBAAkB,QAAQ,kBAAkB;AAChE,SAASR,OAAO,IAAIS,SAAS,QAAQ,QAAQ;AAC7C,SAAST,OAAO,IAAIU,WAAW,QAAQ,UAAU","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["@wordpress/fields/src/index.ts"],"sourcesContent":["export * from './fields';\nexport * from './actions';\n"],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,WAAW","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["@wordpress/fields/src/index.ts"],"sourcesContent":["export * from './fields';\nexport * from './actions';\nexport type * from './types';\n"],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,WAAW","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["@wordpress/fields/src/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'publish'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\ninterface Author {\n\tname: string;\n\tavatar_urls: Record< string, string >;\n}\n\ninterface EmbeddedAuthor {\n\tauthor: Author[];\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n\tslug?: string;\n\tpermalink_template?: string;\n\tdate?: string;\n\tmodified?: string;\n\tauthor?: number;\n}\n\nexport interface BasePostWithEmbeddedAuthor extends BasePost {\n\t_embedded: EmbeddedAuthor;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n\tplugin?: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
@@ -203,11 +203,9 @@ fieldset.fields-controls__featured-image .fields-controls__featured-image-remove
203
203
  height: 16px;
204
204
  }
205
205
 
206
- .dataviews-view-table__cell-content-wrapper .fields-controls__featured-image-image {
207
- width: 32px;
208
- height: 32px;
209
- }
206
+ .dataviews-view-table__cell-content-wrapper .fields-controls__featured-image-image,
210
207
  .dataviews-view-table__cell-content-wrapper .fields-controls__featured-image-placeholder {
211
208
  width: 32px;
212
209
  height: 32px;
210
+ display: block;
213
211
  }
@@ -203,11 +203,9 @@ fieldset.fields-controls__featured-image .fields-controls__featured-image-remove
203
203
  height: 16px;
204
204
  }
205
205
 
206
- .dataviews-view-table__cell-content-wrapper .fields-controls__featured-image-image {
207
- width: 32px;
208
- height: 32px;
209
- }
206
+ .dataviews-view-table__cell-content-wrapper .fields-controls__featured-image-image,
210
207
  .dataviews-view-table__cell-content-wrapper .fields-controls__featured-image-placeholder {
211
208
  width: 32px;
212
209
  height: 32px;
210
+ display: block;
213
211
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { BasePostWithEmbeddedAuthor } from '../../types';
5
+ declare function AuthorView({ item }: {
6
+ item: BasePostWithEmbeddedAuthor;
7
+ }): import("react").JSX.Element;
8
+ export default AuthorView;
9
+ //# sourceMappingURL=author-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"author-view.d.ts","sourceRoot":"","sources":["../../../src/fields/author/author-view.tsx"],"names":[],"mappings":"AAgBA;;GAEG;AACH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAE9D,iBAAS,UAAU,CAAE,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,0BAA0B,CAAA;CAAE,+BAuClE;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+ import type { BasePostWithEmbeddedAuthor } from '../../types';
9
+ declare const authorField: Field<BasePostWithEmbeddedAuthor>;
10
+ /**
11
+ * Author field for BasePost.
12
+ */
13
+ export default authorField;
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fields/author/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD;;GAEG;AACH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAG9D,QAAA,MAAM,WAAW,EAAE,KAAK,CAAE,0BAA0B,CAcnD,CAAC;AAEF;;GAEG;AACH,eAAe,WAAW,CAAC"}
@@ -7,4 +7,5 @@ export { default as passwordField } from './password';
7
7
  export { default as statusField } from './status';
8
8
  export { default as commentStatusField } from './comment-status';
9
9
  export { default as dateField } from './date';
10
+ export { default as authorField } from './author';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fields/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,UAAU,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from './fields';
2
2
  export * from './actions';
3
+ export type * from './types';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,mBAAmB,SAAS,CAAC"}
@@ -28,6 +28,13 @@ interface Links {
28
28
  href: string;
29
29
  }[] | undefined;
30
30
  }
31
+ interface Author {
32
+ name: string;
33
+ avatar_urls: Record<string, string>;
34
+ }
35
+ interface EmbeddedAuthor {
36
+ author: Author[];
37
+ }
31
38
  export interface BasePost extends CommonPost {
32
39
  comment_status?: 'open' | 'closed';
33
40
  excerpt?: string | {
@@ -47,6 +54,10 @@ export interface BasePost extends CommonPost {
47
54
  permalink_template?: string;
48
55
  date?: string;
49
56
  modified?: string;
57
+ author?: number;
58
+ }
59
+ export interface BasePostWithEmbeddedAuthor extends BasePost {
60
+ _embedded: EmbeddedAuthor;
50
61
  }
51
62
  export interface Template extends CommonPost {
52
63
  type: 'wp_template';
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GACZ,SAAS,GACT,OAAO,GACP,SAAS,GACT,SAAS,GACT,QAAQ,GACR,YAAY,GACZ,OAAO,CAAC;AAEX,MAAM,WAAW,UAAU;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD,OAAO,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,CAAC;CACf;AAED,UAAU,KAAK;IACd,qBAAqB,CAAC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G,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhE,MAAM,MAAM,mBAAmB,GAAG,IAAI,GAAG;IACxC,WAAW,EAAE;QACZ,MAAM,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE,OAAO,CAAC;KAChB,CAAC;CACF,CAAC;AAEF,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE;QACV,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,SAAS,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC;CACF;AAGD,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/fields",
3
- "version": "0.4.0",
3
+ "version": "0.5.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",
@@ -57,6 +57,7 @@
57
57
  "@wordpress/warning": "*",
58
58
  "change-case": "4.1.2",
59
59
  "client-zip": "^2.4.5",
60
+ "clsx": "2.1.1",
60
61
  "remove-accents": "^0.5.0"
61
62
  },
62
63
  "peerDependencies": {
@@ -65,5 +66,5 @@
65
66
  "publishConfig": {
66
67
  "access": "public"
67
68
  },
68
- "gitHead": "510540d99f3d222a96f08d3d7b66c9e7a726f705"
69
+ "gitHead": "cce81c13739c2a8b53d91df90c4f037cb68c2665"
69
70
  }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import clsx from 'clsx';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { __ } from '@wordpress/i18n';
10
+ import { useState } from '@wordpress/element';
11
+ import { commentAuthorAvatar as authorIcon } from '@wordpress/icons';
12
+ import { __experimentalHStack as HStack, Icon } from '@wordpress/components';
13
+ import { useSelect } from '@wordpress/data';
14
+ import { store as coreStore } from '@wordpress/core-data';
15
+ import type { User } from '@wordpress/core-data';
16
+
17
+ /**
18
+ * Internal dependencies
19
+ */
20
+ import type { BasePostWithEmbeddedAuthor } from '../../types';
21
+
22
+ function AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) {
23
+ const { text, imageUrl } = useSelect(
24
+ ( select ) => {
25
+ const { getEntityRecord } = select( coreStore );
26
+ let user: User | undefined;
27
+ if ( !! item.author ) {
28
+ user = getEntityRecord( 'root', 'user', item.author );
29
+ }
30
+ return {
31
+ imageUrl: user?.avatar_urls?.[ 48 ],
32
+ text: user?.name,
33
+ };
34
+ },
35
+ [ item ]
36
+ );
37
+ const [ isImageLoaded, setIsImageLoaded ] = useState( false );
38
+ return (
39
+ <HStack alignment="left" spacing={ 0 }>
40
+ { !! imageUrl && (
41
+ <div
42
+ className={ clsx( 'page-templates-author-field__avatar', {
43
+ 'is-loaded': isImageLoaded,
44
+ } ) }
45
+ >
46
+ <img
47
+ onLoad={ () => setIsImageLoaded( true ) }
48
+ alt={ __( 'Author avatar' ) }
49
+ src={ imageUrl }
50
+ />
51
+ </div>
52
+ ) }
53
+ { ! imageUrl && (
54
+ <div className="page-templates-author-field__icon">
55
+ <Icon icon={ authorIcon } />
56
+ </div>
57
+ ) }
58
+ <span className="page-templates-author-field__name">{ text }</span>
59
+ </HStack>
60
+ );
61
+ }
62
+
63
+ export default AuthorView;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { BasePostWithEmbeddedAuthor } from '../../types';
11
+ import AuthorView from './author-view';
12
+
13
+ const authorField: Field< BasePostWithEmbeddedAuthor > = {
14
+ label: __( 'Author' ),
15
+ id: 'author',
16
+ type: 'integer',
17
+ elements: [],
18
+ render: AuthorView,
19
+ sort: ( a, b, direction ) => {
20
+ const nameA = a._embedded?.author?.[ 0 ]?.name || '';
21
+ const nameB = b._embedded?.author?.[ 0 ]?.name || '';
22
+
23
+ return direction === 'asc'
24
+ ? nameA.localeCompare( nameB )
25
+ : nameB.localeCompare( nameA );
26
+ },
27
+ };
28
+
29
+ /**
30
+ * Author field for BasePost.
31
+ */
32
+ export default authorField;
@@ -83,13 +83,10 @@ fieldset.fields-controls__featured-image {
83
83
  }
84
84
 
85
85
  .dataviews-view-table__cell-content-wrapper {
86
- .fields-controls__featured-image-image {
87
- width: 32px;
88
- height: 32px;
89
- }
90
-
86
+ .fields-controls__featured-image-image,
91
87
  .fields-controls__featured-image-placeholder {
92
88
  width: 32px;
93
89
  height: 32px;
90
+ display: block;
94
91
  }
95
92
  }
@@ -7,3 +7,4 @@ export { default as passwordField } from './password';
7
7
  export { default as statusField } from './status';
8
8
  export { default as commentStatusField } from './comment-status';
9
9
  export { default as dateField } from './date';
10
+ export { default as authorField } from './author';
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './fields';
2
2
  export * from './actions';
3
+ export type * from './types';