@wordpress/fields 0.23.1-next.233ccab9b.0 → 0.24.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 +8 -0
- package/build/actions/duplicate-post.js +1 -2
- package/build/actions/duplicate-post.js.map +1 -1
- package/build/actions/rename-post.js +1 -1
- package/build/actions/rename-post.js.map +1 -1
- package/build/actions/utils.js +9 -9
- package/build/actions/utils.js.map +1 -1
- package/build/fields/comment-status/index.js +2 -1
- package/build/fields/comment-status/index.js.map +1 -1
- package/build/fields/discussion/index.js +42 -0
- package/build/fields/discussion/index.js.map +1 -0
- package/build/fields/index.js +14 -0
- package/build/fields/index.js.map +1 -1
- package/build/fields/ping-status/index.js +64 -0
- package/build/fields/ping-status/index.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build-module/actions/duplicate-post.js +1 -2
- package/build-module/actions/duplicate-post.js.map +1 -1
- package/build-module/actions/rename-post.js +1 -1
- package/build-module/actions/rename-post.js.map +1 -1
- package/build-module/actions/utils.js +9 -9
- package/build-module/actions/utils.js.map +1 -1
- package/build-module/fields/comment-status/index.js +2 -1
- package/build-module/fields/comment-status/index.js.map +1 -1
- package/build-module/fields/discussion/index.js +37 -0
- package/build-module/fields/discussion/index.js.map +1 -0
- package/build-module/fields/index.js +2 -0
- package/build-module/fields/index.js.map +1 -1
- package/build-module/fields/ping-status/index.js +58 -0
- package/build-module/fields/ping-status/index.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-types/actions/duplicate-post.d.ts.map +1 -1
- package/build-types/actions/utils.d.ts +1 -1
- package/build-types/actions/utils.d.ts.map +1 -1
- package/build-types/fields/comment-status/index.d.ts.map +1 -1
- package/build-types/fields/discussion/index.d.ts +14 -0
- package/build-types/fields/discussion/index.d.ts.map +1 -0
- package/build-types/fields/index.d.ts +2 -0
- package/build-types/fields/index.d.ts.map +1 -1
- package/build-types/fields/ping-status/index.d.ts +14 -0
- package/build-types/fields/ping-status/index.d.ts.map +1 -0
- package/build-types/types.d.ts +1 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +25 -25
- package/src/actions/duplicate-post.tsx +1 -2
- package/src/actions/rename-post.tsx +1 -1
- package/src/actions/utils.ts +14 -11
- package/src/fields/comment-status/index.tsx +2 -1
- package/src/fields/discussion/index.tsx +36 -0
- package/src/fields/index.ts +2 -0
- package/src/fields/ping-status/index.tsx +74 -0
- package/src/types.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -47,6 +47,10 @@ Date field for BasePost.
|
|
|
47
47
|
|
|
48
48
|
Delete action for Templates, Patterns and Template Parts.
|
|
49
49
|
|
|
50
|
+
### discussionField
|
|
51
|
+
|
|
52
|
+
Discussion field for BasePost with custom render logic.
|
|
53
|
+
|
|
50
54
|
### duplicatePattern
|
|
51
55
|
|
|
52
56
|
Duplicate action for Pattern.
|
|
@@ -91,6 +95,10 @@ Title for the pattern entity.
|
|
|
91
95
|
|
|
92
96
|
Delete action for PostWithPermissions.
|
|
93
97
|
|
|
98
|
+
### pingStatusField
|
|
99
|
+
|
|
100
|
+
Ping status field for BasePost.
|
|
101
|
+
|
|
94
102
|
### PostType
|
|
95
103
|
|
|
96
104
|
Undocumented declaration.
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _data = require("@wordpress/data");
|
|
8
|
-
var _htmlEntities = require("@wordpress/html-entities");
|
|
9
8
|
var _coreData = require("@wordpress/core-data");
|
|
10
9
|
var _i18n = require("@wordpress/i18n");
|
|
11
10
|
var _notices = require("@wordpress/notices");
|
|
@@ -93,7 +92,7 @@ const duplicatePost = {
|
|
|
93
92
|
});
|
|
94
93
|
createSuccessNotice((0, _i18n.sprintf)(
|
|
95
94
|
// translators: %s: Title of the created post, e.g: "Hello world".
|
|
96
|
-
(0, _i18n.__)('"%s" successfully created.'), (0,
|
|
95
|
+
(0, _i18n.__)('"%s" successfully created.'), (0, _utils.getItemTitle)(newItem)), {
|
|
97
96
|
id: 'duplicate-post-action',
|
|
98
97
|
type: 'snackbar'
|
|
99
98
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_htmlEntities","_coreData","_i18n","_notices","_element","_dataviews","_components","_fields","_utils","_jsxRuntime","fields","titleField","formDuplicateAction","duplicatePost","id","label","_x","isEligible","status","modalFocusOnMount","RenderModal","items","closeModal","onActionPerformed","item","setItem","useState","title","sprintf","getItemTitle","isCreatingPage","setIsCreatingPage","saveEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","createPage","event","preventDefault","isTemplate","type","newItemObject","slug","__","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","throwOnError","decodeEntities","rendered","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","DataForm","data","form","onChange","changes","prev","__experimentalHStack","justify","Button","variant","onClick","__next40pxDefaultSize","isBusy","_default","exports","default"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tdecodeEntities( newItem.title?.rendered || item.title )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],"mappings":";;;;;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,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAmF,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGexF,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_data","require","_coreData","_i18n","_notices","_element","_dataviews","_components","_fields","_utils","_jsxRuntime","fields","titleField","formDuplicateAction","duplicatePost","id","label","_x","isEligible","status","modalFocusOnMount","RenderModal","items","closeModal","onActionPerformed","item","setItem","useState","title","sprintf","getItemTitle","isCreatingPage","setIsCreatingPage","saveEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","createPage","event","preventDefault","isTemplate","type","newItemObject","slug","__","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","throwOnError","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","DataForm","data","form","onChange","changes","prev","__experimentalHStack","justify","Button","variant","onClick","__next40pxDefaultSize","isBusy","_default","exports","default"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAC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GAGetF,aAAa","ignoreList":[]}
|
|
@@ -51,7 +51,7 @@ const renamePost = {
|
|
|
51
51
|
onActionPerformed
|
|
52
52
|
}) => {
|
|
53
53
|
const [item] = items;
|
|
54
|
-
const [title, setTitle] = (0, _element.useState)(() => (0, _utils.getItemTitle)(item));
|
|
54
|
+
const [title, setTitle] = (0, _element.useState)(() => (0, _utils.getItemTitle)(item, ''));
|
|
55
55
|
const {
|
|
56
56
|
editEntityRecord,
|
|
57
57
|
saveEditedEntityRecord
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_coreData","_i18n","_element","_patterns","_components","_notices","_lockUnlock","_utils","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","renamePost","id","label","__","modalFocusOnMount","isEligible","post","status","Object","values","includes","type","permissions","update","isTemplatePart","source","has_theme_file","user","RenderModal","items","closeModal","onActionPerformed","item","title","setTitle","useState","getItemTitle","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","onRename","event","preventDefault","throwOnError","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","__next40pxDefaultSize","value","onChange","required","__experimentalHStack","justify","Button","variant","onClick","_default","exports","default"],"sources":["@wordpress/fields/src/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport { getItemTitle, isTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tmodalFocusOnMount: 'firstContentElement',\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif (\n\t\t\t! [\n\t\t\t\t'wp_template_part',\n\t\t\t\t...Object.values( PATTERN_TYPES ),\n\t\t\t].includes( post.type )\n\t\t) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === 'custom' &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Rename action for PostWithPermissions.\n */\nexport default renamePost;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAA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AAQ,EAAE,MAAM,IAAAC,mBAAY,EAAEJ,
|
|
1
|
+
{"version":3,"names":["_data","require","_coreData","_i18n","_element","_patterns","_components","_notices","_lockUnlock","_utils","_jsxRuntime","PATTERN_TYPES","unlock","patternsPrivateApis","renamePost","id","label","__","modalFocusOnMount","isEligible","post","status","Object","values","includes","type","permissions","update","isTemplatePart","source","has_theme_file","user","RenderModal","items","closeModal","onActionPerformed","item","title","setTitle","useState","getItemTitle","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","onRename","event","preventDefault","throwOnError","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","TextControl","__nextHasNoMarginBottom","__next40pxDefaultSize","value","onChange","required","__experimentalHStack","justify","Button","variant","onClick","_default","exports","default"],"sources":["@wordpress/fields/src/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport { getItemTitle, isTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tmodalFocusOnMount: 'firstContentElement',\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif (\n\t\t\t! [\n\t\t\t\t'wp_template_part',\n\t\t\t\t...Object.values( PATTERN_TYPES ),\n\t\t\t].includes( post.type )\n\t\t) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === 'custom' &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item, '' ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Rename action for PostWithPermissions.\n */\nexport default renamePost;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAOA,IAAAM,QAAA,GAAAN,OAAA;AAMA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AAAuD,IAAAS,WAAA,GAAAT,OAAA;AAvBvD;AACA;AACA;;AAKA;;AAWA;AACA;AACA;;AAMA;AACA,MAAM;EAAEU;AAAc,CA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,WAAA,CAAAkD,IAAA,EAACtD,WAAA,CAAA+D,oBAAM;UAACC,OAAO,EAAC,OAAO;UAAAX,QAAA,gBACtB,IAAAjD,WAAA,CAAA+C,GAAA,EAACnD,WAAA,CAAAiE,MAAM;YACNN,qBAAqB;YACrBO,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGA,CAAA,KAAM;cACfvC,UAAU,GAAG,CAAC;YACf,CAAG;YAAAyB,QAAA,EAED,IAAA1C,QAAE,EAAE,QAAS;UAAC,CACT,CAAC,eACT,IAAAP,WAAA,CAAA+C,GAAA,EAACnD,WAAA,CAAAiE,MAAM;YACNN,qBAAqB;YACrBO,OAAO,EAAC,SAAS;YACjB/C,IAAI,EAAC,QAAQ;YAAAkC,QAAA,EAEX,IAAA1C,QAAE,EAAE,MAAO;UAAC,CACP,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAyD,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGe9D,UAAU","ignoreList":[]}
|
package/build/actions/utils.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.isTemplateOrTemplatePart = isTemplateOrTemplatePart;
|
|
|
9
9
|
exports.isTemplatePart = isTemplatePart;
|
|
10
10
|
exports.isTemplateRemovable = isTemplateRemovable;
|
|
11
11
|
var _htmlEntities = require("@wordpress/html-entities");
|
|
12
|
+
var _i18n = require("@wordpress/i18n");
|
|
12
13
|
/**
|
|
13
14
|
* WordPress dependencies
|
|
14
15
|
*/
|
|
@@ -26,17 +27,16 @@ function isTemplatePart(post) {
|
|
|
26
27
|
function isTemplateOrTemplatePart(p) {
|
|
27
28
|
return p.type === 'wp_template' || p.type === 'wp_template_part';
|
|
28
29
|
}
|
|
29
|
-
function getItemTitle(item) {
|
|
30
|
+
function getItemTitle(item, fallback = (0, _i18n.__)('(no title)')) {
|
|
31
|
+
let title = '';
|
|
30
32
|
if (typeof item.title === 'string') {
|
|
31
|
-
|
|
33
|
+
title = (0, _htmlEntities.decodeEntities)(item.title);
|
|
34
|
+
} else if (item.title && 'rendered' in item.title) {
|
|
35
|
+
title = (0, _htmlEntities.decodeEntities)(item.title.rendered);
|
|
36
|
+
} else if (item.title && 'raw' in item.title) {
|
|
37
|
+
title = (0, _htmlEntities.decodeEntities)(item.title.raw);
|
|
32
38
|
}
|
|
33
|
-
|
|
34
|
-
return (0, _htmlEntities.decodeEntities)(item.title.rendered);
|
|
35
|
-
}
|
|
36
|
-
if (item.title && 'raw' in item.title) {
|
|
37
|
-
return (0, _htmlEntities.decodeEntities)(item.title.raw);
|
|
38
|
-
}
|
|
39
|
-
return '';
|
|
39
|
+
return title || fallback;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_htmlEntities","require","isTemplate","post","type","isTemplatePart","isTemplateOrTemplatePart","p","getItemTitle","item","title","decodeEntities","rendered","raw","isTemplateRemovable","template","source","includes","Boolean","plugin","has_theme_file"],"sources":["@wordpress/fields/src/actions/utils.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport type { Post, TemplatePart, Template } from '../types';\n\nexport function isTemplate( post: Post ): post is Template {\n\treturn post.type === 'wp_template';\n}\n\nexport function isTemplatePart( post: Post ): post is TemplatePart {\n\treturn post.type === 'wp_template_part';\n}\n\nexport function isTemplateOrTemplatePart(\n\tp: Post\n): p is Template | TemplatePart {\n\treturn p.type === 'wp_template' || p.type === 'wp_template_part';\n}\n\nexport function getItemTitle(
|
|
1
|
+
{"version":3,"names":["_htmlEntities","require","_i18n","isTemplate","post","type","isTemplatePart","isTemplateOrTemplatePart","p","getItemTitle","item","fallback","__","title","decodeEntities","rendered","raw","isTemplateRemovable","template","source","includes","Boolean","plugin","has_theme_file"],"sources":["@wordpress/fields/src/actions/utils.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { Post, TemplatePart, Template } from '../types';\n\nexport function isTemplate( post: Post ): post is Template {\n\treturn post.type === 'wp_template';\n}\n\nexport function isTemplatePart( post: Post ): post is TemplatePart {\n\treturn post.type === 'wp_template_part';\n}\n\nexport function isTemplateOrTemplatePart(\n\tp: Post\n): p is Template | TemplatePart {\n\treturn p.type === 'wp_template' || p.type === 'wp_template_part';\n}\n\nexport function getItemTitle(\n\titem: {\n\t\ttitle: string | { rendered: string } | { raw: string };\n\t},\n\tfallback: string = __( '(no title)' )\n) {\n\tlet title = '';\n\tif ( typeof item.title === 'string' ) {\n\t\ttitle = decodeEntities( item.title );\n\t} else if ( item.title && 'rendered' in item.title ) {\n\t\ttitle = decodeEntities( item.title.rendered );\n\t} else if ( item.title && 'raw' in item.title ) {\n\t\ttitle = decodeEntities( item.title.raw );\n\t}\n\treturn title || fallback;\n}\n\n/**\n * Check if a template is removable.\n *\n * @param template The template entity to check.\n * @return Whether the template is removable.\n */\nexport function isTemplateRemovable( template: Template | TemplatePart ) {\n\tif ( ! template ) {\n\t\treturn false;\n\t}\n\t// In patterns list page we map the templates parts to a different object\n\t// than the one returned from the endpoint. This is why we need to check for\n\t// two props whether is custom or has a theme file.\n\treturn (\n\t\t[ template.source, template.source ].includes( 'custom' ) &&\n\t\t! Boolean( template.type === 'wp_template' && template?.plugin ) &&\n\t\t! template.has_theme_file\n\t);\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;;AAGO,SAASE,UAAUA,CAAEC,IAAU,EAAqB;EAC1D,OAAOA,IAAI,CAACC,IAAI,KAAK,aAAa;AACnC;AAEO,SAASC,cAAcA,CAAEF,IAAU,EAAyB;EAClE,OAAOA,IAAI,CAACC,IAAI,KAAK,kBAA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|
17
17
|
id: 'comment_status',
|
|
18
|
-
label: (0, _i18n.__)('
|
|
18
|
+
label: (0, _i18n.__)('Comments'),
|
|
19
19
|
type: 'text',
|
|
20
20
|
Edit: 'radio',
|
|
21
21
|
enableSorting: false,
|
|
22
|
+
enableHiding: false,
|
|
22
23
|
filterBy: false,
|
|
23
24
|
elements: [{
|
|
24
25
|
value: 'open',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","commentStatusField","id","label","__","type","Edit","enableSorting","filterBy","elements","value","description","_default","exports","default"],"sources":["@wordpress/fields/src/fields/comment-status/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 { BasePost } from '../../types';\n\nconst commentStatusField: Field< BasePost > = {\n\tid: 'comment_status',\n\tlabel: __( '
|
|
1
|
+
{"version":3,"names":["_i18n","require","commentStatusField","id","label","__","type","Edit","enableSorting","enableHiding","filterBy","elements","value","description","_default","exports","default"],"sources":["@wordpress/fields/src/fields/comment-status/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 { BasePost } from '../../types';\n\nconst commentStatusField: Field< BasePost > = {\n\tid: 'comment_status',\n\tlabel: __( 'Comments' ),\n\ttype: 'text',\n\tEdit: 'radio',\n\tenableSorting: false,\n\tenableHiding: false,\n\tfilterBy: false,\n\telements: [\n\t\t{\n\t\t\tvalue: 'open',\n\t\t\tlabel: __( 'Open' ),\n\t\t\tdescription: __( 'Visitors can add new comments and replies.' ),\n\t\t},\n\t\t{\n\t\t\tvalue: 'closed',\n\t\t\tlabel: __( 'Closed' ),\n\t\t\tdescription: __(\n\t\t\t\t'Visitors cannot add new comments or replies. Existing comments remain visible.'\n\t\t\t),\n\t\t},\n\t],\n};\n\n/**\n * Comment status field for BasePost.\n */\nexport default commentStatusField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;;AAGA,MAAMC,kBAAqC,GAAG;EAC7CC,EAAE,EAAE,gBAAgB;EACpBC,KAAK,EAAE,IAAAC,QAAE,EAAE,UAAW,CAAC;EACvBC,IAAI,EAAE,MAAM;EACZC,IAAI,EAAE,OAAO;EACbC,aAAa,EAAE,KAAK;EACpBC,YAAY,EAAE,KAAK;EACnBC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,CACT;IACCC,KAAK,EAAE,MAAM;IACbR,KAAK,EAAE,IAAAC,QAAE,EAAE,MAAO,CAAC;IACnBQ,WAAW,EAAE,IAAAR,QAAE,EAAE,4CAA6C;EAC/D,CAAC,EACD;IACCO,KAAK,EAAE,QAAQ;IACfR,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS,CAAC;IACrBQ,WAAW,EAAE,IAAAR,QAAE,EACd,gFACD;EACD,CAAC;AAEH,CAAC;;AAED;AACA;AACA;AAFA,IAAAS,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGed,kBAAkB","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* WordPress dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const discussionField = {
|
|
17
|
+
id: 'discussion',
|
|
18
|
+
label: (0, _i18n.__)('Discussion'),
|
|
19
|
+
type: 'text',
|
|
20
|
+
render: ({
|
|
21
|
+
item
|
|
22
|
+
}) => {
|
|
23
|
+
const commentsOpen = item.comment_status === 'open';
|
|
24
|
+
const pingsOpen = item.ping_status === 'open';
|
|
25
|
+
if (commentsOpen && pingsOpen) {
|
|
26
|
+
return (0, _i18n.__)('Open');
|
|
27
|
+
}
|
|
28
|
+
if (commentsOpen && !pingsOpen) {
|
|
29
|
+
return (0, _i18n.__)('Comments only');
|
|
30
|
+
}
|
|
31
|
+
if (!commentsOpen && pingsOpen) {
|
|
32
|
+
return (0, _i18n.__)('Pings only');
|
|
33
|
+
}
|
|
34
|
+
return (0, _i18n.__)('Closed');
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Discussion field for BasePost with custom render logic.
|
|
40
|
+
*/
|
|
41
|
+
var _default = exports.default = discussionField;
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_i18n","require","discussionField","id","label","__","type","render","item","commentsOpen","comment_status","pingsOpen","ping_status","_default","exports","default"],"sources":["@wordpress/fields/src/fields/discussion/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 { BasePost } from '../../types';\n\nconst discussionField: Field< BasePost > = {\n\tid: 'discussion',\n\tlabel: __( 'Discussion' ),\n\ttype: 'text',\n\trender: ( { item } ) => {\n\t\tconst commentsOpen = item.comment_status === 'open';\n\t\tconst pingsOpen = item.ping_status === 'open';\n\n\t\tif ( commentsOpen && pingsOpen ) {\n\t\t\treturn __( 'Open' );\n\t\t}\n\t\tif ( commentsOpen && ! pingsOpen ) {\n\t\t\treturn __( 'Comments only' );\n\t\t}\n\t\tif ( ! commentsOpen && pingsOpen ) {\n\t\t\treturn __( 'Pings only' );\n\t\t}\n\t\treturn __( 'Closed' );\n\t},\n};\n\n/**\n * Discussion field for BasePost with custom render logic.\n */\nexport default discussionField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;;AAGA,MAAMC,eAAkC,GAAG;EAC1CC,EAAE,EAAE,YAAY;EAChBC,KAAK,EAAE,IAAAC,QAAE,EAAE,YAAa,CAAC;EACzBC,IAAI,EAAE,MAAM;EACZC,MAAM,EAAEA,CAAE;IAAEC;EAAK,CAAC,KAAM;IACvB,MAAMC,YAAY,GAAGD,IAAI,CAACE,cAAc,KAAK,MAAM;IACnD,MAAMC,SAAS,GAAGH,IAAI,CAACI,WAAW,KAAK,MAAM;IAE7C,IAAKH,YAAY,IAAIE,SAAS,EAAG;MAChC,OAAO,IAAAN,QAAE,EAAE,MAAO,CAAC;IACpB;IACA,IAAKI,YAAY,IAAI,CAAEE,SAAS,EAAG;MAClC,OAAO,IAAAN,QAAE,EAAE,eAAgB,CAAC;IAC7B;IACA,IAAK,CAAEI,YAAY,IAAIE,SAAS,EAAG;MAClC,OAAO,IAAAN,QAAE,EAAE,YAAa,CAAC;IAC1B;IACA,OAAO,IAAAA,QAAE,EAAE,QAAS,CAAC;EACtB;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAQ,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeb,eAAe","ignoreList":[]}
|
package/build/fields/index.js
CHANGED
|
@@ -22,6 +22,12 @@ Object.defineProperty(exports, "dateField", {
|
|
|
22
22
|
return _date.default;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
+
Object.defineProperty(exports, "discussionField", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _discussion.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
25
31
|
Object.defineProperty(exports, "featuredImageField", {
|
|
26
32
|
enumerable: true,
|
|
27
33
|
get: function () {
|
|
@@ -58,6 +64,12 @@ Object.defineProperty(exports, "patternTitleField", {
|
|
|
58
64
|
return _patternTitle.default;
|
|
59
65
|
}
|
|
60
66
|
});
|
|
67
|
+
Object.defineProperty(exports, "pingStatusField", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _pingStatus.default;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
61
73
|
Object.defineProperty(exports, "slugField", {
|
|
62
74
|
enumerable: true,
|
|
63
75
|
get: function () {
|
|
@@ -100,6 +112,8 @@ var _parent = _interopRequireDefault(require("./parent"));
|
|
|
100
112
|
var _password = _interopRequireDefault(require("./password"));
|
|
101
113
|
var _status = _interopRequireDefault(require("./status"));
|
|
102
114
|
var _commentStatus = _interopRequireDefault(require("./comment-status"));
|
|
115
|
+
var _pingStatus = _interopRequireDefault(require("./ping-status"));
|
|
116
|
+
var _discussion = _interopRequireDefault(require("./discussion"));
|
|
103
117
|
var _date = _interopRequireDefault(require("./date"));
|
|
104
118
|
var _author = _interopRequireDefault(require("./author"));
|
|
105
119
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_slug","_interopRequireDefault","require","_title","_pageTitle","_templateTitle","_patternTitle","_order","_featuredImage","_template","_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 pageTitleField } from './page-title';\nexport { default as templateTitleField } from './template-title';\nexport { default as patternTitleField } from './pattern-title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as templateField } from './template';\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":"
|
|
1
|
+
{"version":3,"names":["_slug","_interopRequireDefault","require","_title","_pageTitle","_templateTitle","_patternTitle","_order","_featuredImage","_template","_parent","_password","_status","_commentStatus","_pingStatus","_discussion","_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 pageTitleField } from './page-title';\nexport { default as templateTitleField } from './template-title';\nexport { default as patternTitleField } from './pattern-title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as templateField } from './template';\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 pingStatusField } from './ping-status';\nexport { default as discussionField } from './discussion';\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,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,aAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,cAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,OAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,SAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,OAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,cAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY,WAAA,GAAAb,sBAAA,CAAAC,OAAA;AACA,IAAAa,WAAA,GAAAd,sBAAA,CAAAC,OAAA;AACA,IAAAc,KAAA,GAAAf,sBAAA,CAAAC,OAAA;AACA,IAAAe,OAAA,GAAAhB,sBAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 _components = require("@wordpress/components");
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function PingStatusEdit({
|
|
19
|
+
data,
|
|
20
|
+
onChange
|
|
21
|
+
}) {
|
|
22
|
+
var _data$ping_status;
|
|
23
|
+
const pingStatus = (_data$ping_status = data?.ping_status) !== null && _data$ping_status !== void 0 ? _data$ping_status : 'open';
|
|
24
|
+
const onTogglePingback = checked => {
|
|
25
|
+
onChange({
|
|
26
|
+
...data,
|
|
27
|
+
ping_status: checked ? 'open' : 'closed'
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CheckboxControl, {
|
|
31
|
+
__nextHasNoMarginBottom: true,
|
|
32
|
+
label: (0, _i18n.__)('Enable pingbacks & trackbacks'),
|
|
33
|
+
checked: pingStatus === 'open',
|
|
34
|
+
onChange: onTogglePingback,
|
|
35
|
+
help: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ExternalLink, {
|
|
36
|
+
href: (0, _i18n.__)('https://wordpress.org/documentation/article/trackbacks-and-pingbacks/'),
|
|
37
|
+
children: (0, _i18n.__)('Learn more about pingbacks & trackbacks')
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const pingStatusField = {
|
|
42
|
+
id: 'ping_status',
|
|
43
|
+
label: (0, _i18n.__)('Trackbacks & Pingbacks'),
|
|
44
|
+
type: 'text',
|
|
45
|
+
Edit: PingStatusEdit,
|
|
46
|
+
enableSorting: false,
|
|
47
|
+
enableHiding: false,
|
|
48
|
+
filterBy: false,
|
|
49
|
+
elements: [{
|
|
50
|
+
value: 'open',
|
|
51
|
+
label: (0, _i18n.__)('Allow'),
|
|
52
|
+
description: (0, _i18n.__)('Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.')
|
|
53
|
+
}, {
|
|
54
|
+
value: 'closed',
|
|
55
|
+
label: (0, _i18n.__)("Don't allow"),
|
|
56
|
+
description: (0, _i18n.__)("Don't allow link notifications from other blogs (pingbacks and trackbacks) on new articles.")
|
|
57
|
+
}]
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Ping status field for BasePost.
|
|
62
|
+
*/
|
|
63
|
+
var _default = exports.default = pingStatusField;
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_i18n","require","_components","_jsxRuntime","PingStatusEdit","data","onChange","_data$ping_status","pingStatus","ping_status","onTogglePingback","checked","jsx","CheckboxControl","__nextHasNoMarginBottom","label","__","help","ExternalLink","href","children","pingStatusField","id","type","Edit","enableSorting","enableHiding","filterBy","elements","value","description","_default","exports","default"],"sources":["@wordpress/fields/src/fields/ping-status/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { DataFormControlProps, Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\nimport { CheckboxControl, ExternalLink } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\n\nfunction PingStatusEdit( {\n\tdata,\n\tonChange,\n}: DataFormControlProps< BasePost > ) {\n\tconst pingStatus = data?.ping_status ?? 'open';\n\n\tconst onTogglePingback = ( checked: boolean ) => {\n\t\tonChange( {\n\t\t\t...data,\n\t\t\tping_status: checked ? 'open' : 'closed',\n\t\t} );\n\t};\n\n\treturn (\n\t\t<CheckboxControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ __( 'Enable pingbacks & trackbacks' ) }\n\t\t\tchecked={ pingStatus === 'open' }\n\t\t\tonChange={ onTogglePingback }\n\t\t\thelp={\n\t\t\t\t<ExternalLink\n\t\t\t\t\thref={ __(\n\t\t\t\t\t\t'https://wordpress.org/documentation/article/trackbacks-and-pingbacks/'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Learn more about pingbacks & trackbacks' ) }\n\t\t\t\t</ExternalLink>\n\t\t\t}\n\t\t/>\n\t);\n}\n\nconst pingStatusField: Field< BasePost > = {\n\tid: 'ping_status',\n\tlabel: __( 'Trackbacks & Pingbacks' ),\n\ttype: 'text',\n\tEdit: PingStatusEdit,\n\tenableSorting: false,\n\tenableHiding: false,\n\tfilterBy: false,\n\telements: [\n\t\t{\n\t\t\tvalue: 'open',\n\t\t\tlabel: __( 'Allow' ),\n\t\t\tdescription: __(\n\t\t\t\t'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.'\n\t\t\t),\n\t\t},\n\t\t{\n\t\t\tvalue: 'closed',\n\t\t\tlabel: __( \"Don't allow\" ),\n\t\t\tdescription: __(\n\t\t\t\t\"Don't allow link notifications from other blogs (pingbacks and trackbacks) on new articles.\"\n\t\t\t),\n\t\t},\n\t],\n};\n\n/**\n * Ping status field for BasePost.\n */\nexport default pingStatusField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAAsE,IAAAE,WAAA,GAAAF,OAAA;AALtE;AACA;AACA;;AAKA;AACA;AACA;;AAGA,SAASG,cAAcA,CAAE;EACxBC,IAAI;EACJC;AACiC,CAAC,EAAG;EAAA,IAAAC,iBAAA;EACrC,MAAMC,UAAU,IAAAD,iBAAA,GAAGF,IAAI,EAAEI,WAAW,cAAAF,iBAAA,cAAAA,iBAAA,GAAI,MAAM;EAE9C,MAAMG,gBAAgB,GAAKC,OAAgB,IAAM;IAChDL,QAAQ,CAAE;MACT,GAAGD,IAAI;MACPI,WAAW,EAAEE,OAAO,GAAG,MAAM,GAAG;IACjC,CAAE,CAAC;EACJ,CAAC;EAED,oBACC,IAAAR,WAAA,CAAAS,GAAA,EAACV,WAAA,CAAAW,eAAe;IACfC,uBAAuB;IACvBC,KAAK,EAAG,IAAAC,QAAE,EAAE,+BAAgC,CAAG;IAC/CL,OAAO,EAAGH,UAAU,KAAK,MAAQ;IACjCF,QAAQ,EAAGI,gBAAkB;IAC7BO,IAAI,eACH,IAAAd,WAAA,CAAAS,GAAA,EAACV,WAAA,CAAAgB,YAAY;MACZC,IAAI,EAAG,IAAAH,QAAE,EACR,uEACD,CAAG;MAAAI,QAAA,EAED,IAAAJ,QAAE,EAAE,yCAA0C;IAAC,CACpC;EACd,CACD,CAAC;AAEJ;AAEA,MAAMK,eAAkC,GAAG;EAC1CC,EAAE,EAAE,aAAa;EACjBP,KAAK,EAAE,IAAAC,QAAE,EAAE,wBAAyB,CAAC;EACrCO,IAAI,EAAE,MAAM;EACZC,IAAI,EAAEpB,cAAc;EACpBqB,aAAa,EAAE,KAAK;EACpBC,YAAY,EAAE,KAAK;EACnBC,QAAQ,EAAE,KAAK;EACfC,QAAQ,EAAE,CACT;IACCC,KAAK,EAAE,MAAM;IACbd,KAAK,EAAE,IAAAC,QAAE,EAAE,OAAQ,CAAC;IACpBc,WAAW,EAAE,IAAAd,QAAE,EACd,uFACD;EACD,CAAC,EACD;IACCa,KAAK,EAAE,QAAQ;IACfd,KAAK,EAAE,IAAAC,QAAE,EAAE,aAAc,CAAC;IAC1Bc,WAAW,EAAE,IAAAd,QAAE,EACd,6FACD;EACD,CAAC;AAEH,CAAC;;AAED;AACA;AACA;AAFA,IAAAe,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeZ,eAAe","ignoreList":[]}
|
package/build/types.js.map
CHANGED
|
@@ -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\ninterface Author {\n\tname: string;\n\tavatar_urls: Record< string, string >;\n}\n\ninterface EmbeddedAuthor {\n\tauthor: Author[];\n}\n\n/**\n * BasePost interface used for all post types.\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\tauthor?: string;\n\t\tthumbnail?: string;\n\t\tcomments?: string;\n\t\teditor?: 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\n/**\n * BasePost interface used for all post types.\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\tauthor?: string;\n\t\tthumbnail?: string;\n\t\tcomments?: string;\n\t\teditor?: boolean;\n\t\ttrackbacks?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useDispatch } from '@wordpress/data';
|
|
5
|
-
import { decodeEntities } from '@wordpress/html-entities';
|
|
6
5
|
import { store as coreStore } from '@wordpress/core-data';
|
|
7
6
|
import { __, sprintf, _x } from '@wordpress/i18n';
|
|
8
7
|
import { store as noticesStore } from '@wordpress/notices';
|
|
@@ -85,7 +84,7 @@ const duplicatePost = {
|
|
|
85
84
|
});
|
|
86
85
|
createSuccessNotice(sprintf(
|
|
87
86
|
// translators: %s: Title of the created post, e.g: "Hello world".
|
|
88
|
-
__('"%s" successfully created.'),
|
|
87
|
+
__('"%s" successfully created.'), getItemTitle(newItem)), {
|
|
89
88
|
id: 'duplicate-post-action',
|
|
90
89
|
type: 'snackbar'
|
|
91
90
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","decodeEntities","store","coreStore","__","sprintf","_x","noticesStore","useState","DataForm","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","titleField","getItemTitle","jsx","_jsx","jsxs","_jsxs","fields","formDuplicateAction","duplicatePost","id","label","isEligible","status","modalFocusOnMount","RenderModal","items","closeModal","onActionPerformed","item","setItem","title","isCreatingPage","setIsCreatingPage","saveEntityRecord","createSuccessNotice","createErrorNotice","createPage","event","preventDefault","isTemplate","type","newItemObject","slug","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","throwOnError","rendered","error","typedError","errorMessage","message","code","onSubmit","children","spacing","data","form","onChange","changes","prev","justify","variant","onClick","__next40pxDefaultSize","isBusy"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tdecodeEntities( newItem.title?.rendered || item.title )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,EAAEC,EAAE,QAAQ,iBAAiB;AACjD,SAASJ,KAAK,IAAIK,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,SACCC,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AyC,QAAA,eAC5B9D,KAAA,CAACN,MAAM;QAACqE,OAAO,EAAG,CAAG;QAAAD,QAAA,gBACpBhE,IAAA,CAACT,QAAQ;UACR2E,IAAI,EAAGnD,IAAM;UACbZ,MAAM,EAAGA,MAAQ;UACjBgE,IAAI,EAAG/D,mBAAqB;UAC5BgE,QAAQ,EAAKC,OAAO,IACnBrD,OAAO,CAAIsD,IAAI,KAAQ;YACtB,GAAGA,IAAI;YACP,GAAGD;UACJ,CAAC,CAAG;QACJ,CACD,CAAC,eACFnE,KAAA,CAACR,MAAM;UAACuE,OAAO,EAAG,CAAG;UAACM,OAAO,EAAC,KAAK;UAAAP,QAAA,gBAClChE,IAAA,CAACR,MAAM;YACNgF,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAG5D,UAAY;YACtB6D,qBAAqB;YAAAV,QAAA,EAEnB9E,EAAE,CAAE,QAAS;UAAC,CACT,CAAC,eACTc,IAAA,CAACR,MAAM;YACNgF,OAAO,EAAC,SAAS;YACjB7C,IAAI,EAAC,QAAQ;YACbgD,MAAM,EAAGzD,cAAgB;YACzB,iBAAgBA,cAAgB;YAChCwD,qBAAqB;YAAAV,QAAA,EAEnB5E,EAAE,CAAE,WAAW,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAeiB,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useDispatch","store","coreStore","__","sprintf","_x","noticesStore","useState","DataForm","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","titleField","getItemTitle","jsx","_jsx","jsxs","_jsxs","fields","formDuplicateAction","duplicatePost","id","label","isEligible","status","modalFocusOnMount","RenderModal","items","closeModal","onActionPerformed","item","setItem","title","isCreatingPage","setIsCreatingPage","saveEntityRecord","createSuccessNotice","createErrorNotice","createPage","event","preventDefault","isTemplate","type","newItemObject","slug","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","throwOnError","error","typedError","errorMessage","message","code","onSubmit","children","spacing","data","form","onChange","changes","prev","justify","variant","onClick","__next40pxDefaultSize","isBusy"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,EAAEC,OAAO,EAAEC,EAAE,QAAQ,iBAAiB;AACjD,SAASJ,KAAK,IAAIK,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,SACCC,MAAM,EACNC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAG9B;AACA;AACA;AACA,SAASC,UAAU,QAAQ,WAAW;AAEtC,SAASC,YAAY,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAEvC,MAAMC,MAAM,GAAG,CAAEN,UAAU,CAAE;AAC7B,MAAMO,mBAAmB,GAAG;EAC3BD,MAAM,EAAE,CAAE,OAAO;AAClB,CAAC;AAED,MAAME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UAAAP,QAAA,gBAClC/D,IAAA,CAACR,MAAM;YACN+E,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAG3D,UAAY;YACtB4D,qBAAqB;YAAAV,QAAA,EAEnB7E,EAAE,CAAE,QAAS;UAAC,CACT,CAAC,eACTc,IAAA,CAACR,MAAM;YACN+E,OAAO,EAAC,SAAS;YACjB5C,IAAI,EAAC,QAAQ;YACb+C,MAAM,EAAGxD,cAAgB;YACzB,iBAAgBA,cAAgB;YAChCuD,qBAAqB;YAAAV,QAAA,EAEnB3E,EAAE,CAAE,WAAW,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAeiB,aAAa","ignoreList":[]}
|
|
@@ -44,7 +44,7 @@ const renamePost = {
|
|
|
44
44
|
onActionPerformed
|
|
45
45
|
}) => {
|
|
46
46
|
const [item] = items;
|
|
47
|
-
const [title, setTitle] = useState(() => getItemTitle(item));
|
|
47
|
+
const [title, setTitle] = useState(() => getItemTitle(item, ''));
|
|
48
48
|
const {
|
|
49
49
|
editEntityRecord,
|
|
50
50
|
saveEditedEntityRecord
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","store","coreStore","__","useState","privateApis","patternsPrivateApis","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","noticesStore","unlock","getItemTitle","isTemplatePart","jsx","_jsx","jsxs","_jsxs","PATTERN_TYPES","renamePost","id","label","modalFocusOnMount","isEligible","post","status","Object","values","includes","type","permissions","update","source","has_theme_file","user","RenderModal","items","closeModal","onActionPerformed","item","title","setTitle","editEntityRecord","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onRename","event","preventDefault","throwOnError","error","typedError","errorMessage","message","code","onSubmit","children","spacing","__nextHasNoMarginBottom","__next40pxDefaultSize","value","onChange","required","justify","variant","onClick"],"sources":["@wordpress/fields/src/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport { getItemTitle, isTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tmodalFocusOnMount: 'firstContentElement',\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif (\n\t\t\t! [\n\t\t\t\t'wp_template_part',\n\t\t\t\t...Object.values( PATTERN_TYPES ),\n\t\t\t].includes( post.type )\n\t\t) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === 'custom' &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Rename action for PostWithPermissions.\n */\nexport default renamePost;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C;AACA,SAASC,WAAW,IAAIC,mBAAmB,QAAQ,qBAAqB;AACxE,SACCC,MAAM,EACNC,WAAW,EACXC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAE9B,SAASX,KAAK,IAAIY,YAAY,QAAQ,oBAAoB;;AAE1D;AACA;AACA;;AAEA,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,YAAY,EAAEC,cAAc,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAGvD;AACA,MAAM;EAAEC;AAAc,CAAC,GAAGP,MAAM,CAAER,mBAAoB,CAAC;AAEvD,MAAMgB,UAAyC,GAAG;EACjDC,EAAE,EAAE,aAAa;EACjBC,KAAK,EAAErB,EAAE,CAAE,QAAS,CAAC;EACrBsB,iBAAiB,EAAE,qBAAqB;EACxCC,UAAUA,CAAEC,IAAI,EAAG;IAClB,IAAKA,IAAI,CAACC,MAAM,KAAK,OAAO,EAAG;MAC9B,OAAO,KAAK;IACb;IACA;IACA,IACC,CAAE,CACD,kBAAkB,EAClB,GAAGC,MAAM,CAACC,MAAM,CAAET,aAAc,CAAC,CACjC,CAACU,QAAQ,CAAEJ,IAAI,CAACK,IAAK,CAAC,EACtB;MACD,OAAOL,IAAI,CAACM,WAAW,EAAEC,MAAM;IAChC;IAEA,IAAKlB,cAAc,CAAEW,IAAK,CAAC,EAAG;MAC7B,OACCA,IAAI,CAACQ,MAAM,KAAK,QAAQ,IACxB,CAAER,IAAI,EAAES,cAAc,IACtBT,IAAI,CAACM,WAAW,EAAEC,MAAM;IAE1B;IAEA,OAAOP,IAAI,CAACK,IAAI,KAAKX,aAAa,CAACgB,IAAI,IAAIV,IAAI,CAACM,WAAW,EAAEC,MAAM;EACpE,CAAC;EACDI,WAAW,EAAEA,CAAE;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAkB,CAAC,KAAM;IAC5D,MAAM,CAAEC,IAAI,CAAE,GAAGH,KAAK;IACtB,MAAM,CAAEI,KAAK,EAAEC,QAAQ,CAAE,GAAGxC,QAAQ,CAAE,MAAMW,YAAY,CAAE2B,
|
|
1
|
+
{"version":3,"names":["useDispatch","store","coreStore","__","useState","privateApis","patternsPrivateApis","Button","TextControl","__experimentalHStack","HStack","__experimentalVStack","VStack","noticesStore","unlock","getItemTitle","isTemplatePart","jsx","_jsx","jsxs","_jsxs","PATTERN_TYPES","renamePost","id","label","modalFocusOnMount","isEligible","post","status","Object","values","includes","type","permissions","update","source","has_theme_file","user","RenderModal","items","closeModal","onActionPerformed","item","title","setTitle","editEntityRecord","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onRename","event","preventDefault","throwOnError","error","typedError","errorMessage","message","code","onSubmit","children","spacing","__nextHasNoMarginBottom","__next40pxDefaultSize","value","onChange","required","justify","variant","onClick"],"sources":["@wordpress/fields/src/actions/rename-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\n// @ts-ignore\nimport { privateApis as patternsPrivateApis } from '@wordpress/patterns';\nimport {\n\tButton,\n\tTextControl,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\n\nimport { unlock } from '../lock-unlock';\nimport { getItemTitle, isTemplatePart } from './utils';\nimport type { CoreDataError, PostWithPermissions } from '../types';\n\n// Patterns.\nconst { PATTERN_TYPES } = unlock( patternsPrivateApis );\n\nconst renamePost: Action< PostWithPermissions > = {\n\tid: 'rename-post',\n\tlabel: __( 'Rename' ),\n\tmodalFocusOnMount: 'firstContentElement',\n\tisEligible( post ) {\n\t\tif ( post.status === 'trash' ) {\n\t\t\treturn false;\n\t\t}\n\t\t// Templates, template parts and patterns have special checks for renaming.\n\t\tif (\n\t\t\t! [\n\t\t\t\t'wp_template_part',\n\t\t\t\t...Object.values( PATTERN_TYPES ),\n\t\t\t].includes( post.type )\n\t\t) {\n\t\t\treturn post.permissions?.update;\n\t\t}\n\n\t\tif ( isTemplatePart( post ) ) {\n\t\t\treturn (\n\t\t\t\tpost.source === 'custom' &&\n\t\t\t\t! post?.has_theme_file &&\n\t\t\t\tpost.permissions?.update\n\t\t\t);\n\t\t}\n\n\t\treturn post.type === PATTERN_TYPES.user && post.permissions?.update;\n\t},\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item ] = items;\n\t\tconst [ title, setTitle ] = useState( () => getItemTitle( item, '' ) );\n\t\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\t\tuseDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function onRename( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\t\t\ttry {\n\t\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\ttitle,\n\t\t\t\t} );\n\t\t\t\t// Update state before saving rerenders the list.\n\t\t\t\tsetTitle( '' );\n\t\t\t\tcloseModal?.();\n\t\t\t\t// Persist edited entity.\n\t\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t} );\n\t\t\t\tcreateSuccessNotice( __( 'Name updated' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t\tonActionPerformed?.( items );\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while updating the name' );\n\t\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ onRename }>\n\t\t\t\t<VStack spacing=\"5\">\n\t\t\t\t\t<TextControl\n\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\trequired\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>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,GACtDH,UAAU,CAACE,OAAO,GAClBrD,EAAE,CAAE,2CAA4C,CAAC;QACrD6C,iBAAiB,CAAEO,YAAY,EAAE;UAAEvB,IAAI,EAAE;QAAW,CAAE,CAAC;MACxD;IACD;IAEA,oBACCd,IAAA;MAAMwC,QAAQ,EAAGT,QAAU;MAAAU,QAAA,eAC1BvC,KAAA,CAACR,MAAM;QAACgD,OAAO,EAAC,GAAG;QAAAD,QAAA,gBAClBzC,IAAA,CAACV,WAAW;UACXqD,uBAAuB;UACvBC,qBAAqB;UACrBtC,KAAK,EAAGrB,EAAE,CAAE,MAAO,CAAG;UACtB4D,KAAK,EAAGpB,KAAO;UACfqB,QAAQ,EAAGpB,QAAU;UACrBqB,QAAQ;QAAA,CACR,CAAC,eACF7C,KAAA,CAACV,MAAM;UAACwD,OAAO,EAAC,OAAO;UAAAP,QAAA,gBACtBzC,IAAA,CAACX,MAAM;YACNuD,qBAAqB;YACrBK,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGA,CAAA,KAAM;cACf5B,UAAU,GAAG,CAAC;YACf,CAAG;YAAAmB,QAAA,EAEDxD,EAAE,CAAE,QAAS;UAAC,CACT,CAAC,eACTe,IAAA,CAACX,MAAM;YACNuD,qBAAqB;YACrBK,OAAO,EAAC,SAAS;YACjBnC,IAAI,EAAC,QAAQ;YAAA2B,QAAA,EAEXxD,EAAE,CAAE,MAAO;UAAC,CACP,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AACA,eAAemB,UAAU","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
@@ -16,17 +17,16 @@ export function isTemplatePart(post) {
|
|
|
16
17
|
export function isTemplateOrTemplatePart(p) {
|
|
17
18
|
return p.type === 'wp_template' || p.type === 'wp_template_part';
|
|
18
19
|
}
|
|
19
|
-
export function getItemTitle(item) {
|
|
20
|
+
export function getItemTitle(item, fallback = __('(no title)')) {
|
|
21
|
+
let title = '';
|
|
20
22
|
if (typeof item.title === 'string') {
|
|
21
|
-
|
|
23
|
+
title = decodeEntities(item.title);
|
|
24
|
+
} else if (item.title && 'rendered' in item.title) {
|
|
25
|
+
title = decodeEntities(item.title.rendered);
|
|
26
|
+
} else if (item.title && 'raw' in item.title) {
|
|
27
|
+
title = decodeEntities(item.title.raw);
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
return decodeEntities(item.title.rendered);
|
|
25
|
-
}
|
|
26
|
-
if (item.title && 'raw' in item.title) {
|
|
27
|
-
return decodeEntities(item.title.raw);
|
|
28
|
-
}
|
|
29
|
-
return '';
|
|
29
|
+
return title || fallback;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|