@wordpress/fields 0.0.2
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 +5 -0
- package/LICENSE.md +788 -0
- package/README.md +73 -0
- package/build/actions/base-post/duplicate-post.js +146 -0
- package/build/actions/base-post/duplicate-post.js.map +1 -0
- package/build/actions/base-post/duplicate-post.native.js +9 -0
- package/build/actions/base-post/duplicate-post.native.js.map +1 -0
- package/build/actions/base-post/index.js +42 -0
- package/build/actions/base-post/index.js.map +1 -0
- package/build/actions/base-post/reorder-page.js +116 -0
- package/build/actions/base-post/reorder-page.js.map +1 -0
- package/build/actions/base-post/reorder-page.native.js +9 -0
- package/build/actions/base-post/reorder-page.native.js.map +1 -0
- package/build/actions/base-post/view-post.js +36 -0
- package/build/actions/base-post/view-post.js.map +1 -0
- package/build/actions/common/index.js +21 -0
- package/build/actions/common/index.js.map +1 -0
- package/build/actions/common/permanently-delete-post.js +109 -0
- package/build/actions/common/permanently-delete-post.js.map +1 -0
- package/build/actions/common/view-post-revisions.js +49 -0
- package/build/actions/common/view-post-revisions.js.map +1 -0
- package/build/actions/index.js +39 -0
- package/build/actions/index.js.map +1 -0
- package/build/actions/pattern/duplicate-pattern.js +48 -0
- package/build/actions/pattern/duplicate-pattern.js.map +1 -0
- package/build/actions/pattern/export-pattern.js +57 -0
- package/build/actions/pattern/export-pattern.js.map +1 -0
- package/build/actions/pattern/export-pattern.native.js +9 -0
- package/build/actions/pattern/export-pattern.native.js.map +1 -0
- package/build/actions/pattern/index.js +28 -0
- package/build/actions/pattern/index.js.map +1 -0
- package/build/actions/utils.js +65 -0
- package/build/actions/utils.js.map +1 -0
- package/build/fields/index.js +21 -0
- package/build/fields/index.js.map +1 -0
- package/build/fields/order/index.js +23 -0
- package/build/fields/order/index.js.map +1 -0
- package/build/fields/title/index.js +27 -0
- package/build/fields/title/index.js.map +1 -0
- package/build/index.js +28 -0
- package/build/index.js.map +1 -0
- package/build/index.native.js +28 -0
- package/build/index.native.js.map +1 -0
- package/build/lock-unlock.js +18 -0
- package/build/lock-unlock.js.map +1 -0
- package/build/types.js +6 -0
- package/build/types.js.map +1 -0
- package/build/wordpress-editor.d.js +2 -0
- package/build/wordpress-editor.d.js.map +1 -0
- package/build-module/actions/base-post/duplicate-post.js +139 -0
- package/build-module/actions/base-post/duplicate-post.js.map +1 -0
- package/build-module/actions/base-post/duplicate-post.native.js +3 -0
- package/build-module/actions/base-post/duplicate-post.native.js.map +1 -0
- package/build-module/actions/base-post/index.js +6 -0
- package/build-module/actions/base-post/index.js.map +1 -0
- package/build-module/actions/base-post/reorder-page.js +111 -0
- package/build-module/actions/base-post/reorder-page.js.map +1 -0
- package/build-module/actions/base-post/reorder-page.native.js +3 -0
- package/build-module/actions/base-post/reorder-page.native.js.map +1 -0
- package/build-module/actions/base-post/view-post.js +30 -0
- package/build-module/actions/base-post/view-post.js.map +1 -0
- package/build-module/actions/common/index.js +3 -0
- package/build-module/actions/common/index.js.map +1 -0
- package/build-module/actions/common/permanently-delete-post.js +102 -0
- package/build-module/actions/common/permanently-delete-post.js.map +1 -0
- package/build-module/actions/common/view-post-revisions.js +43 -0
- package/build-module/actions/common/view-post-revisions.js.map +1 -0
- package/build-module/actions/index.js +4 -0
- package/build-module/actions/index.js.map +1 -0
- package/build-module/actions/pattern/duplicate-pattern.js +39 -0
- package/build-module/actions/pattern/duplicate-pattern.js.map +1 -0
- package/build-module/actions/pattern/export-pattern.js +51 -0
- package/build-module/actions/pattern/export-pattern.js.map +1 -0
- package/build-module/actions/pattern/export-pattern.native.js +3 -0
- package/build-module/actions/pattern/export-pattern.native.js.map +1 -0
- package/build-module/actions/pattern/index.js +4 -0
- package/build-module/actions/pattern/index.js.map +1 -0
- package/build-module/actions/utils.js +54 -0
- package/build-module/actions/utils.js.map +1 -0
- package/build-module/fields/index.js +3 -0
- package/build-module/fields/index.js.map +1 -0
- package/build-module/fields/order/index.js +17 -0
- package/build-module/fields/order/index.js.map +1 -0
- package/build-module/fields/title/index.js +22 -0
- package/build-module/fields/title/index.js.map +1 -0
- package/build-module/index.js +3 -0
- package/build-module/index.js.map +1 -0
- package/build-module/index.native.js +3 -0
- package/build-module/index.native.js.map +1 -0
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/types.js +2 -0
- package/build-module/types.js.map +1 -0
- package/build-module/wordpress-editor.d.js +2 -0
- package/build-module/wordpress-editor.d.js.map +1 -0
- package/build-types/actions/base-post/duplicate-post.d.ts +5 -0
- package/build-types/actions/base-post/duplicate-post.d.ts.map +1 -0
- package/build-types/actions/base-post/duplicate-post.native.d.ts +3 -0
- package/build-types/actions/base-post/duplicate-post.native.d.ts.map +1 -0
- package/build-types/actions/base-post/index.d.ts +6 -0
- package/build-types/actions/base-post/index.d.ts.map +1 -0
- package/build-types/actions/base-post/reorder-page.d.ts +8 -0
- package/build-types/actions/base-post/reorder-page.d.ts.map +1 -0
- package/build-types/actions/base-post/reorder-page.native.d.ts +3 -0
- package/build-types/actions/base-post/reorder-page.native.d.ts.map +1 -0
- package/build-types/actions/base-post/view-post.d.ts +8 -0
- package/build-types/actions/base-post/view-post.d.ts.map +1 -0
- package/build-types/actions/common/index.d.ts +3 -0
- package/build-types/actions/common/index.d.ts.map +1 -0
- package/build-types/actions/common/permanently-delete-post.d.ts +5 -0
- package/build-types/actions/common/permanently-delete-post.d.ts.map +1 -0
- package/build-types/actions/common/view-post-revisions.d.ts +8 -0
- package/build-types/actions/common/view-post-revisions.d.ts.map +1 -0
- package/build-types/actions/index.d.ts +4 -0
- package/build-types/actions/index.d.ts.map +1 -0
- package/build-types/actions/pattern/duplicate-pattern.d.ts +5 -0
- package/build-types/actions/pattern/duplicate-pattern.d.ts.map +1 -0
- package/build-types/actions/pattern/export-pattern.d.ts +8 -0
- package/build-types/actions/pattern/export-pattern.d.ts.map +1 -0
- package/build-types/actions/pattern/export-pattern.native.d.ts +3 -0
- package/build-types/actions/pattern/export-pattern.native.d.ts.map +1 -0
- package/build-types/actions/pattern/index.d.ts +4 -0
- package/build-types/actions/pattern/index.d.ts.map +1 -0
- package/build-types/actions/utils.d.ts +23 -0
- package/build-types/actions/utils.d.ts.map +1 -0
- package/build-types/fields/index.d.ts +3 -0
- package/build-types/fields/index.d.ts.map +1 -0
- package/build-types/fields/order/index.d.ts +11 -0
- package/build-types/fields/order/index.d.ts.map +1 -0
- package/build-types/fields/title/index.d.ts +11 -0
- package/build-types/fields/title/index.d.ts.map +1 -0
- package/build-types/index.d.ts +3 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/index.native.d.ts +3 -0
- package/build-types/index.native.d.ts.map +1 -0
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/types.d.ts +92 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +63 -0
- package/src/actions/base-post/duplicate-post.native.tsx +3 -0
- package/src/actions/base-post/duplicate-post.tsx +174 -0
- package/src/actions/base-post/index.ts +5 -0
- package/src/actions/base-post/reorder-page.native.tsx +3 -0
- package/src/actions/base-post/reorder-page.tsx +125 -0
- package/src/actions/base-post/view-post.tsx +30 -0
- package/src/actions/common/index.ts +2 -0
- package/src/actions/common/permanently-delete-post.tsx +118 -0
- package/src/actions/common/view-post-revisions.tsx +47 -0
- package/src/actions/index.ts +3 -0
- package/src/actions/pattern/duplicate-pattern.tsx +40 -0
- package/src/actions/pattern/export-pattern.native.tsx +3 -0
- package/src/actions/pattern/export-pattern.tsx +76 -0
- package/src/actions/pattern/index.ts +3 -0
- package/src/actions/utils.ts +66 -0
- package/src/fields/index.ts +2 -0
- package/src/fields/order/index.ts +18 -0
- package/src/fields/title/index.ts +21 -0
- package/src/index.native.ts +2 -0
- package/src/index.ts +2 -0
- package/src/lock-unlock.ts +9 -0
- package/src/types.ts +85 -0
- package/src/wordpress-editor.d.ts +1 -0
- package/tsconfig.json +29 -0
- package/tsconfig.tsbuildinfo +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Fields
|
|
2
|
+
|
|
3
|
+
This package provides core elements for the DataView library, designed to simplify the creation and management of data display elements in WordPress.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the module
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @wordpress/fields --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
<!-- START TOKEN(Autogenerated API docs) -->
|
|
16
|
+
|
|
17
|
+
### duplicatePattern
|
|
18
|
+
|
|
19
|
+
Undocumented declaration.
|
|
20
|
+
|
|
21
|
+
### duplicatePost
|
|
22
|
+
|
|
23
|
+
Undocumented declaration.
|
|
24
|
+
|
|
25
|
+
### duplicatePostNative
|
|
26
|
+
|
|
27
|
+
Undocumented declaration.
|
|
28
|
+
|
|
29
|
+
### exportPattern
|
|
30
|
+
|
|
31
|
+
Undocumented declaration.
|
|
32
|
+
|
|
33
|
+
### exportPatternNative
|
|
34
|
+
|
|
35
|
+
Undocumented declaration.
|
|
36
|
+
|
|
37
|
+
### orderField
|
|
38
|
+
|
|
39
|
+
Undocumented declaration.
|
|
40
|
+
|
|
41
|
+
### permanentlyDeletePost
|
|
42
|
+
|
|
43
|
+
Undocumented declaration.
|
|
44
|
+
|
|
45
|
+
### reorderPage
|
|
46
|
+
|
|
47
|
+
Undocumented declaration.
|
|
48
|
+
|
|
49
|
+
### reorderPageNative
|
|
50
|
+
|
|
51
|
+
Undocumented declaration.
|
|
52
|
+
|
|
53
|
+
### titleField
|
|
54
|
+
|
|
55
|
+
Undocumented declaration.
|
|
56
|
+
|
|
57
|
+
### viewPost
|
|
58
|
+
|
|
59
|
+
Undocumented declaration.
|
|
60
|
+
|
|
61
|
+
### viewPostRevisions
|
|
62
|
+
|
|
63
|
+
Undocumented declaration.
|
|
64
|
+
|
|
65
|
+
<!-- END TOKEN(Autogenerated API docs) -->
|
|
66
|
+
|
|
67
|
+
## Contributing to this package
|
|
68
|
+
|
|
69
|
+
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
|
70
|
+
|
|
71
|
+
To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
|
|
72
|
+
|
|
73
|
+
<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _data = require("@wordpress/data");
|
|
8
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
9
|
+
var _coreData = require("@wordpress/core-data");
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
var _notices = require("@wordpress/notices");
|
|
12
|
+
var _element = require("@wordpress/element");
|
|
13
|
+
var _dataviews = require("@wordpress/dataviews");
|
|
14
|
+
var _components = require("@wordpress/components");
|
|
15
|
+
var _fields = require("../../fields");
|
|
16
|
+
var _utils = require("../utils");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
/**
|
|
19
|
+
* WordPress dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Internal dependencies
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const fields = [_fields.titleField];
|
|
27
|
+
const formDuplicateAction = {
|
|
28
|
+
fields: ['title']
|
|
29
|
+
};
|
|
30
|
+
const duplicatePost = {
|
|
31
|
+
id: 'duplicate-post',
|
|
32
|
+
label: (0, _i18n._x)('Duplicate', 'action label'),
|
|
33
|
+
isEligible({
|
|
34
|
+
status
|
|
35
|
+
}) {
|
|
36
|
+
return status !== 'trash';
|
|
37
|
+
},
|
|
38
|
+
RenderModal: ({
|
|
39
|
+
items,
|
|
40
|
+
closeModal,
|
|
41
|
+
onActionPerformed
|
|
42
|
+
}) => {
|
|
43
|
+
const [item, setItem] = (0, _element.useState)({
|
|
44
|
+
...items[0],
|
|
45
|
+
title: (0, _i18n.sprintf)( /* translators: %s: Existing template title */
|
|
46
|
+
(0, _i18n.__)('%s (Copy)'), (0, _utils.getItemTitle)(items[0]))
|
|
47
|
+
});
|
|
48
|
+
const [isCreatingPage, setIsCreatingPage] = (0, _element.useState)(false);
|
|
49
|
+
const {
|
|
50
|
+
saveEntityRecord
|
|
51
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
52
|
+
const {
|
|
53
|
+
createSuccessNotice,
|
|
54
|
+
createErrorNotice
|
|
55
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
56
|
+
async function createPage(event) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
if (isCreatingPage) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const newItemOject = {
|
|
62
|
+
status: 'draft',
|
|
63
|
+
title: item.title,
|
|
64
|
+
slug: item.title || (0, _i18n.__)('No title'),
|
|
65
|
+
comment_status: item.comment_status,
|
|
66
|
+
content: typeof item.content === 'string' ? item.content : item.content.raw,
|
|
67
|
+
excerpt: typeof item.excerpt === 'string' ? item.excerpt : item.excerpt?.raw,
|
|
68
|
+
meta: item.meta,
|
|
69
|
+
parent: item.parent,
|
|
70
|
+
password: item.password,
|
|
71
|
+
template: item.template,
|
|
72
|
+
format: item.format,
|
|
73
|
+
featured_media: item.featured_media,
|
|
74
|
+
menu_order: item.menu_order,
|
|
75
|
+
ping_status: item.ping_status
|
|
76
|
+
};
|
|
77
|
+
const assignablePropertiesPrefix = 'wp:action-assign-';
|
|
78
|
+
// Get all the properties that the current user is able to assign normally author, categories, tags,
|
|
79
|
+
// and custom taxonomies.
|
|
80
|
+
const assignableProperties = Object.keys(item?._links || {}).filter(property => property.startsWith(assignablePropertiesPrefix)).map(property => property.slice(assignablePropertiesPrefix.length));
|
|
81
|
+
assignableProperties.forEach(property => {
|
|
82
|
+
if (item.hasOwnProperty(property)) {
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
newItemOject[property] = item[property];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
setIsCreatingPage(true);
|
|
88
|
+
try {
|
|
89
|
+
const newItem = await saveEntityRecord('postType', item.type, newItemOject, {
|
|
90
|
+
throwOnError: true
|
|
91
|
+
});
|
|
92
|
+
createSuccessNotice((0, _i18n.sprintf)(
|
|
93
|
+
// translators: %s: Title of the created template e.g: "Category".
|
|
94
|
+
(0, _i18n.__)('"%s" successfully created.'), (0, _htmlEntities.decodeEntities)(newItem.title?.rendered || item.title)), {
|
|
95
|
+
id: 'duplicate-post-action',
|
|
96
|
+
type: 'snackbar'
|
|
97
|
+
});
|
|
98
|
+
if (onActionPerformed) {
|
|
99
|
+
onActionPerformed([newItem]);
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const typedError = error;
|
|
103
|
+
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : (0, _i18n.__)('An error occurred while duplicating the page.');
|
|
104
|
+
createErrorNotice(errorMessage, {
|
|
105
|
+
type: 'snackbar'
|
|
106
|
+
});
|
|
107
|
+
} finally {
|
|
108
|
+
setIsCreatingPage(false);
|
|
109
|
+
closeModal?.();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
113
|
+
onSubmit: createPage,
|
|
114
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
115
|
+
spacing: 3,
|
|
116
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviews.DataForm, {
|
|
117
|
+
data: item,
|
|
118
|
+
fields: fields,
|
|
119
|
+
form: formDuplicateAction,
|
|
120
|
+
onChange: changes => setItem(prev => ({
|
|
121
|
+
...prev,
|
|
122
|
+
...changes
|
|
123
|
+
}))
|
|
124
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
125
|
+
spacing: 2,
|
|
126
|
+
justify: "end",
|
|
127
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
128
|
+
variant: "tertiary",
|
|
129
|
+
onClick: closeModal,
|
|
130
|
+
__next40pxDefaultSize: true,
|
|
131
|
+
children: (0, _i18n.__)('Cancel')
|
|
132
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
133
|
+
variant: "primary",
|
|
134
|
+
type: "submit",
|
|
135
|
+
isBusy: isCreatingPage,
|
|
136
|
+
"aria-disabled": isCreatingPage,
|
|
137
|
+
__next40pxDefaultSize: true,
|
|
138
|
+
children: (0, _i18n._x)('Duplicate', 'action label')
|
|
139
|
+
})]
|
|
140
|
+
})]
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var _default = exports.default = duplicatePost;
|
|
146
|
+
//# sourceMappingURL=duplicate-post.js.map
|
|
@@ -0,0 +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","RenderModal","items","closeModal","onActionPerformed","item","setItem","useState","title","sprintf","__","getItemTitle","isCreatingPage","setIsCreatingPage","saveEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","createPage","event","preventDefault","newItemOject","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","type","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/base-post/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\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 template title */\n\t\t\t\t__( '%s (Copy)' ),\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 newItemOject = {\n\t\t\t\tstatus: 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: 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\tnewItemOject[ 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,\n\t\t\t\t\tnewItemOject,\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 template e.g: \"Category\".\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\nexport default duplicatePost;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAUA,IAAAQ,OAAA,GAAAR,OAAA;AAEA,IAAAS,MAAA,GAAAT,OAAA;AAAwC,IAAAU,WAAA,GAAAV,OAAA;AAtBxC;AACA;AACA;;AAeA;AACA;AACA;;AAKA,MAAMW,MAAM,GAAG,CAAEC,kBAAU,CAAE;AAC7B,MAAMC,mBAAmB,GAAG;EAC3BF,MAAM,EAAE,CAAE,OAAO;AAClB,CAAC;AAED,MAAMG,aAAiC,GAAG;EACzCC,EAAE,EAAE,gBAAgB;EACpBC,KAAK,EAAE,IAAAC,QAAE,EAAE,WAAW,EAAE,cAAe,CAAC;EACxCC,UAAUA,CAAE;IAAEC;EAAO,CAAC,EAAG;IACxB,OAAOA,MAAM,KAAK,OAAO;EAC1B,CAAC;EACDC,WAAW,EAAEA,CAAE;IAAEC,KAAK;IAAEC,UAAU;IAAEC;EAAkB,CAAC,KAAM;IAC5D,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAA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EAAC,QAAQ;YACb2B,MAAM,EAAGlE,cAAgB;YACzB,iBAAgBA,cAAgB;YAChCiE,qBAAqB;YAAAf,QAAA,EAEnB,IAAAhE,QAAE,EAAE,WAAW,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;AAAC,IAAAiF,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEatF,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["duplicatePost","undefined","_default","exports","default"],"sources":["@wordpress/fields/src/actions/base-post/duplicate-post.native.tsx"],"sourcesContent":["const duplicatePost = undefined;\n\nexport default duplicatePost;\n"],"mappings":";;;;;;AAAA,MAAMA,aAAa,GAAGC,SAAS;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEjBJ,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "duplicatePost", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _duplicatePost.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "duplicatePostNative", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _duplicatePost2.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "reorderPage", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _reorderPage.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "reorderPageNative", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _reorderPage2.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "viewPost", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _viewPost.default;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
var _viewPost = _interopRequireDefault(require("./view-post"));
|
|
38
|
+
var _reorderPage = _interopRequireDefault(require("./reorder-page"));
|
|
39
|
+
var _reorderPage2 = _interopRequireDefault(require("./reorder-page.native"));
|
|
40
|
+
var _duplicatePost = _interopRequireDefault(require("./duplicate-post"));
|
|
41
|
+
var _duplicatePost2 = _interopRequireDefault(require("./duplicate-post.native"));
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_viewPost","_interopRequireDefault","require","_reorderPage","_reorderPage2","_duplicatePost","_duplicatePost2"],"sources":["@wordpress/fields/src/actions/base-post/index.ts"],"sourcesContent":["export { default as viewPost } from './view-post';\nexport { default as reorderPage } from './reorder-page';\nexport { default as reorderPageNative } from './reorder-page.native';\nexport { default as duplicatePost } from './duplicate-post';\nexport { default as duplicatePostNative } from './duplicate-post.native';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _data = require("@wordpress/data");
|
|
8
|
+
var _coreData = require("@wordpress/core-data");
|
|
9
|
+
var _i18n = require("@wordpress/i18n");
|
|
10
|
+
var _notices = require("@wordpress/notices");
|
|
11
|
+
var _element = require("@wordpress/element");
|
|
12
|
+
var _dataviews = require("@wordpress/dataviews");
|
|
13
|
+
var _components = require("@wordpress/components");
|
|
14
|
+
var _fields = require("../../fields");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const fields = [_fields.orderField];
|
|
25
|
+
const formOrderAction = {
|
|
26
|
+
fields: ['menu_order']
|
|
27
|
+
};
|
|
28
|
+
function ReorderModal({
|
|
29
|
+
items,
|
|
30
|
+
closeModal,
|
|
31
|
+
onActionPerformed
|
|
32
|
+
}) {
|
|
33
|
+
const [item, setItem] = (0, _element.useState)(items[0]);
|
|
34
|
+
const orderInput = item.menu_order;
|
|
35
|
+
const {
|
|
36
|
+
editEntityRecord,
|
|
37
|
+
saveEditedEntityRecord
|
|
38
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
39
|
+
const {
|
|
40
|
+
createSuccessNotice,
|
|
41
|
+
createErrorNotice
|
|
42
|
+
} = (0, _data.useDispatch)(_notices.store);
|
|
43
|
+
async function onOrder(event) {
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
if (!(0, _dataviews.isItemValid)(item, fields, formOrderAction)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
await editEntityRecord('postType', item.type, item.id, {
|
|
50
|
+
menu_order: orderInput
|
|
51
|
+
});
|
|
52
|
+
closeModal?.();
|
|
53
|
+
// Persist edited entity.
|
|
54
|
+
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
55
|
+
throwOnError: true
|
|
56
|
+
});
|
|
57
|
+
createSuccessNotice((0, _i18n.__)('Order updated.'), {
|
|
58
|
+
type: 'snackbar'
|
|
59
|
+
});
|
|
60
|
+
onActionPerformed?.(items);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const typedError = error;
|
|
63
|
+
const errorMessage = typedError.message && typedError.code !== 'unknown_error' ? typedError.message : (0, _i18n.__)('An error occurred while updating the order');
|
|
64
|
+
createErrorNotice(errorMessage, {
|
|
65
|
+
type: 'snackbar'
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const isSaveDisabled = !(0, _dataviews.isItemValid)(item, fields, formOrderAction);
|
|
70
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
71
|
+
onSubmit: onOrder,
|
|
72
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
73
|
+
spacing: "5",
|
|
74
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
75
|
+
children: (0, _i18n.__)('Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.')
|
|
76
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviews.DataForm, {
|
|
77
|
+
data: item,
|
|
78
|
+
fields: fields,
|
|
79
|
+
form: formOrderAction,
|
|
80
|
+
onChange: changes => setItem({
|
|
81
|
+
...item,
|
|
82
|
+
...changes
|
|
83
|
+
})
|
|
84
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
85
|
+
justify: "right",
|
|
86
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
87
|
+
__next40pxDefaultSize: true,
|
|
88
|
+
variant: "tertiary",
|
|
89
|
+
onClick: () => {
|
|
90
|
+
closeModal?.();
|
|
91
|
+
},
|
|
92
|
+
children: (0, _i18n.__)('Cancel')
|
|
93
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
94
|
+
__next40pxDefaultSize: true,
|
|
95
|
+
variant: "primary",
|
|
96
|
+
type: "submit",
|
|
97
|
+
accessibleWhenDisabled: true,
|
|
98
|
+
disabled: isSaveDisabled,
|
|
99
|
+
children: (0, _i18n.__)('Save')
|
|
100
|
+
})]
|
|
101
|
+
})]
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const reorderPage = {
|
|
106
|
+
id: 'order-pages',
|
|
107
|
+
label: (0, _i18n.__)('Order'),
|
|
108
|
+
isEligible({
|
|
109
|
+
status
|
|
110
|
+
}) {
|
|
111
|
+
return status !== 'trash';
|
|
112
|
+
},
|
|
113
|
+
RenderModal: ReorderModal
|
|
114
|
+
};
|
|
115
|
+
var _default = exports.default = reorderPage;
|
|
116
|
+
//# sourceMappingURL=reorder-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_coreData","_i18n","_notices","_element","_dataviews","_components","_fields","_jsxRuntime","fields","orderField","formOrderAction","ReorderModal","items","closeModal","onActionPerformed","item","setItem","useState","orderInput","menu_order","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","onOrder","event","preventDefault","isItemValid","type","id","throwOnError","__","error","typedError","errorMessage","message","code","isSaveDisabled","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","DataForm","data","form","onChange","changes","__experimentalHStack","justify","Button","__next40pxDefaultSize","variant","onClick","accessibleWhenDisabled","disabled","reorderPage","label","isEligible","status","RenderModal","_default","exports","default"],"sources":["@wordpress/fields/src/actions/base-post/reorder-page.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm, isItemValid } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action, RenderModalProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../../types';\nimport { orderField } from '../../fields';\n\nconst fields = [ orderField ];\nconst formOrderAction = {\n\tfields: [ 'menu_order' ],\n};\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst orderInput = item.menu_order;\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tasync function onOrder( event: React.FormEvent ) {\n\t\tevent.preventDefault();\n\n\t\tif ( ! isItemValid( item, fields, formOrderAction ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tmenu_order: orderInput,\n\t\t\t} );\n\t\t\tcloseModal?.();\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tcreateSuccessNotice( __( 'Order updated.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tonActionPerformed?.( items );\n\t\t} catch ( error ) {\n\t\t\tconst typedError = error as CoreDataError;\n\t\t\tconst errorMessage =\n\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t? typedError.message\n\t\t\t\t\t: __( 'An error occurred while updating the order' );\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\tconst isSaveDisabled = ! isItemValid( item, fields, formOrderAction );\n\treturn (\n\t\t<form onSubmit={ onOrder }>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<div>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ item }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ formOrderAction }\n\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\tsetItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal?.();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tdisabled={ isSaveDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nconst reorderPage: Action< BasePost > = {\n\tid: 'order-pages',\n\tlabel: __( 'Order' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tRenderModal: ReorderModal,\n};\n\nexport default reorderPage;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA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ED,IAAAT,QAAE,EAAE,QAAS;QAAC,CACT,CAAC,eACT,IAAA3B,WAAA,CAAAkC,GAAA,EAACpC,WAAA,CAAAiD,MAAM;UACNC,qBAAqB;UACrBC,OAAO,EAAC,SAAS;UACjBzB,IAAI,EAAC,QAAQ;UACb2B,sBAAsB;UACtBC,QAAQ,EAAGnB,cAAgB;UAAAG,QAAA,EAEzB,IAAAT,QAAE,EAAE,MAAO;QAAC,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET;AAEA,MAAM0B,WAA+B,GAAG;EACvC5B,EAAE,EAAE,aAAa;EACjB6B,KAAK,EAAE,IAAA3B,QAAE,EAAE,OAAQ,CAAC;EACpB4B,UAAUA,CAAE;IAAEC;EAAO,CAAC,EAAG;IACxB,OAAOA,MAAM,KAAK,OAAO;EAC1B,CAAC;EACDC,WAAW,EAAErD;AACd,CAAC;AAAC,IAAAsD,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaP,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reorderPage","undefined","_default","exports","default"],"sources":["@wordpress/fields/src/actions/base-post/reorder-page.native.tsx"],"sourcesContent":["const reorderPage = undefined;\n\nexport default reorderPage;\n"],"mappings":";;;;;;AAAA,MAAMA,WAAW,GAAGC,SAAS;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEfJ,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _icons = require("@wordpress/icons");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
/**
|
|
10
|
+
* WordPress dependencies
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const viewPost = {
|
|
18
|
+
id: 'view-post',
|
|
19
|
+
label: (0, _i18n._x)('View', 'verb'),
|
|
20
|
+
isPrimary: true,
|
|
21
|
+
icon: _icons.external,
|
|
22
|
+
isEligible(post) {
|
|
23
|
+
return post.status !== 'trash';
|
|
24
|
+
},
|
|
25
|
+
callback(posts, {
|
|
26
|
+
onActionPerformed
|
|
27
|
+
}) {
|
|
28
|
+
const post = posts[0];
|
|
29
|
+
window.open(post?.link, '_blank');
|
|
30
|
+
if (onActionPerformed) {
|
|
31
|
+
onActionPerformed(posts);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var _default = exports.default = viewPost;
|
|
36
|
+
//# sourceMappingURL=view-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_icons","require","_i18n","viewPost","id","label","_x","isPrimary","icon","external","isEligible","post","status","callback","posts","onActionPerformed","window","open","link","_default","exports","default"],"sources":["@wordpress/fields/src/actions/base-post/view-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { external } from '@wordpress/icons';\nimport { _x } from '@wordpress/i18n';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\n\nconst viewPost: Action< BasePost > = {\n\tid: 'view-post',\n\tlabel: _x( 'View', 'verb' ),\n\tisPrimary: true,\n\ticon: external,\n\tisEligible( post ) {\n\t\treturn post.status !== 'trash';\n\t},\n\tcallback( posts, { onActionPerformed } ) {\n\t\tconst post = posts[ 0 ];\n\t\twindow.open( post?.link, '_blank' );\n\t\tif ( onActionPerformed ) {\n\t\t\tonActionPerformed( posts );\n\t\t}\n\t},\n};\n\nexport default viewPost;\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,MAAME,QAA4B,GAAG;EACpCC,EAAE,EAAE,WAAW;EACfC,KAAK,EAAE,IAAAC,QAAE,EAAE,MAAM,EAAE,MAAO,CAAC;EAC3BC,SAAS,EAAE,IAAI;EACfC,IAAI,EAAEC,eAAQ;EACdC,UAAUA,CAAEC,IAAI,EAAG;IAClB,OAAOA,IAAI,CAACC,MAAM,KAAK,OAAO;EAC/B,CAAC;EACDC,QAAQA,CAAEC,KAAK,EAAE;IAAEC;EAAkB,CAAC,EAAG;IACxC,MAAMJ,IAAI,GAAGG,KAAK,CAAE,CAAC,CAAE;IACvBE,MAAM,CAACC,IAAI,CAAEN,IAAI,EAAEO,IAAI,EAAE,QAAS,CAAC;IACnC,IAAKH,iBAAiB,EAAG;MACxBA,iBAAiB,CAAED,KAAM,CAAC;IAC3B;EACD;AACD,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEalB,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "permanentlyDeletePost", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _permanentlyDeletePost.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "viewPostRevisions", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _viewPostRevisions.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var _viewPostRevisions = _interopRequireDefault(require("./view-post-revisions"));
|
|
20
|
+
var _permanentlyDeletePost = _interopRequireDefault(require("./permanently-delete-post"));
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_viewPostRevisions","_interopRequireDefault","require","_permanentlyDeletePost"],"sources":["@wordpress/fields/src/actions/common/index.ts"],"sourcesContent":["export { default as viewPostRevisions } from './view-post-revisions';\nexport { default as permanentlyDeletePost } from './permanently-delete-post';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAF,sBAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _coreData = require("@wordpress/core-data");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _notices = require("@wordpress/notices");
|
|
10
|
+
var _icons = require("@wordpress/icons");
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
/**
|
|
13
|
+
* WordPress dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const permanentlyDeletePost = {
|
|
21
|
+
id: 'permanently-delete',
|
|
22
|
+
label: (0, _i18n.__)('Permanently delete'),
|
|
23
|
+
supportsBulk: true,
|
|
24
|
+
icon: _icons.trash,
|
|
25
|
+
isEligible(item) {
|
|
26
|
+
if ((0, _utils.isTemplateOrTemplatePart)(item) || item.type === 'wp_block') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const {
|
|
30
|
+
status,
|
|
31
|
+
permissions
|
|
32
|
+
} = item;
|
|
33
|
+
return status === 'trash' && permissions?.delete;
|
|
34
|
+
},
|
|
35
|
+
async callback(posts, {
|
|
36
|
+
registry,
|
|
37
|
+
onActionPerformed
|
|
38
|
+
}) {
|
|
39
|
+
const {
|
|
40
|
+
createSuccessNotice,
|
|
41
|
+
createErrorNotice
|
|
42
|
+
} = registry.dispatch(_notices.store);
|
|
43
|
+
const {
|
|
44
|
+
deleteEntityRecord
|
|
45
|
+
} = registry.dispatch(_coreData.store);
|
|
46
|
+
const promiseResult = await Promise.allSettled(posts.map(post => {
|
|
47
|
+
return deleteEntityRecord('postType', post.type, post.id, {
|
|
48
|
+
force: true
|
|
49
|
+
}, {
|
|
50
|
+
throwOnError: true
|
|
51
|
+
});
|
|
52
|
+
}));
|
|
53
|
+
// If all the promises were fulfilled with success.
|
|
54
|
+
if (promiseResult.every(({
|
|
55
|
+
status
|
|
56
|
+
}) => status === 'fulfilled')) {
|
|
57
|
+
let successMessage;
|
|
58
|
+
if (promiseResult.length === 1) {
|
|
59
|
+
successMessage = (0, _i18n.sprintf)( /* translators: The posts's title. */
|
|
60
|
+
(0, _i18n.__)('"%s" permanently deleted.'), (0, _utils.getItemTitle)(posts[0]));
|
|
61
|
+
} else {
|
|
62
|
+
successMessage = (0, _i18n.__)('The items were permanently deleted.');
|
|
63
|
+
}
|
|
64
|
+
createSuccessNotice(successMessage, {
|
|
65
|
+
type: 'snackbar',
|
|
66
|
+
id: 'permanently-delete-post-action'
|
|
67
|
+
});
|
|
68
|
+
onActionPerformed?.(posts);
|
|
69
|
+
} else {
|
|
70
|
+
// If there was at lease one failure.
|
|
71
|
+
let errorMessage;
|
|
72
|
+
// If we were trying to permanently delete a single post.
|
|
73
|
+
if (promiseResult.length === 1) {
|
|
74
|
+
const typedError = promiseResult[0];
|
|
75
|
+
if (typedError.reason?.message) {
|
|
76
|
+
errorMessage = typedError.reason.message;
|
|
77
|
+
} else {
|
|
78
|
+
errorMessage = (0, _i18n.__)('An error occurred while permanently deleting the item.');
|
|
79
|
+
}
|
|
80
|
+
// If we were trying to permanently delete multiple posts
|
|
81
|
+
} else {
|
|
82
|
+
const errorMessages = new Set();
|
|
83
|
+
const failedPromises = promiseResult.filter(({
|
|
84
|
+
status
|
|
85
|
+
}) => status === 'rejected');
|
|
86
|
+
for (const failedPromise of failedPromises) {
|
|
87
|
+
const typedError = failedPromise;
|
|
88
|
+
if (typedError.reason?.message) {
|
|
89
|
+
errorMessages.add(typedError.reason.message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (errorMessages.size === 0) {
|
|
93
|
+
errorMessage = (0, _i18n.__)('An error occurred while permanently deleting the items.');
|
|
94
|
+
} else if (errorMessages.size === 1) {
|
|
95
|
+
errorMessage = (0, _i18n.sprintf)( /* translators: %s: an error message */
|
|
96
|
+
(0, _i18n.__)('An error occurred while permanently deleting the items: %s'), [...errorMessages][0]);
|
|
97
|
+
} else {
|
|
98
|
+
errorMessage = (0, _i18n.sprintf)( /* translators: %s: a list of comma separated error messages */
|
|
99
|
+
(0, _i18n.__)('Some errors occurred while permanently deleting the items: %s'), [...errorMessages].join(','));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
createErrorNotice(errorMessage, {
|
|
103
|
+
type: 'snackbar'
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var _default = exports.default = permanentlyDeletePost;
|
|
109
|
+
//# sourceMappingURL=permanently-delete-post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_coreData","require","_i18n","_notices","_icons","_utils","permanentlyDeletePost","id","label","__","supportsBulk","icon","trash","isEligible","item","isTemplateOrTemplatePart","type","status","permissions","delete","callback","posts","registry","onActionPerformed","createSuccessNotice","createErrorNotice","dispatch","noticesStore","deleteEntityRecord","coreStore","promiseResult","Promise","allSettled","map","post","force","throwOnError","every","successMessage","length","sprintf","getItemTitle","errorMessage","typedError","reason","message","errorMessages","Set","failedPromises","filter","failedPromise","add","size","join","_default","exports","default"],"sources":["@wordpress/fields/src/actions/common/permanently-delete-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport type { Action } from '@wordpress/dataviews';\nimport { trash } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { getItemTitle, isTemplateOrTemplatePart } from '../utils';\nimport type { CoreDataError, PostWithPermissions } from '../../types';\n\nconst permanentlyDeletePost: Action< PostWithPermissions > = {\n\tid: 'permanently-delete',\n\tlabel: __( 'Permanently delete' ),\n\tsupportsBulk: true,\n\ticon: trash,\n\tisEligible( item ) {\n\t\tif ( isTemplateOrTemplatePart( item ) || item.type === 'wp_block' ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst { status, permissions } = item;\n\t\treturn status === 'trash' && permissions?.delete;\n\t},\n\tasync callback( posts, { registry, onActionPerformed } ) {\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tregistry.dispatch( noticesStore );\n\t\tconst { deleteEntityRecord } = registry.dispatch( coreStore );\n\t\tconst promiseResult = await Promise.allSettled(\n\t\t\tposts.map( ( post ) => {\n\t\t\t\treturn deleteEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpost.type,\n\t\t\t\t\tpost.id,\n\t\t\t\t\t{ force: true },\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\t\t\t} )\n\t\t);\n\t\t// If all the promises were fulfilled with success.\n\t\tif ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {\n\t\t\tlet successMessage;\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tsuccessMessage = sprintf(\n\t\t\t\t\t/* translators: The posts's title. */\n\t\t\t\t\t__( '\"%s\" permanently deleted.' ),\n\t\t\t\t\tgetItemTitle( posts[ 0 ] )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tsuccessMessage = __( 'The items were permanently deleted.' );\n\t\t\t}\n\t\t\tcreateSuccessNotice( successMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t\tid: 'permanently-delete-post-action',\n\t\t\t} );\n\t\t\tonActionPerformed?.( posts );\n\t\t} else {\n\t\t\t// If there was at lease one failure.\n\t\t\tlet errorMessage;\n\t\t\t// If we were trying to permanently delete a single post.\n\t\t\tif ( promiseResult.length === 1 ) {\n\t\t\t\tconst typedError = promiseResult[ 0 ] as {\n\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t};\n\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\terrorMessage = typedError.reason.message;\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the item.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// If we were trying to permanently delete multiple posts\n\t\t\t} else {\n\t\t\t\tconst errorMessages = new Set();\n\t\t\t\tconst failedPromises = promiseResult.filter(\n\t\t\t\t\t( { status } ) => status === 'rejected'\n\t\t\t\t);\n\t\t\t\tfor ( const failedPromise of failedPromises ) {\n\t\t\t\t\tconst typedError = failedPromise as {\n\t\t\t\t\t\treason?: CoreDataError;\n\t\t\t\t\t};\n\t\t\t\t\tif ( typedError.reason?.message ) {\n\t\t\t\t\t\terrorMessages.add( typedError.reason.message );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif ( errorMessages.size === 0 ) {\n\t\t\t\t\terrorMessage = __(\n\t\t\t\t\t\t'An error occurred while permanently deleting the items.'\n\t\t\t\t\t);\n\t\t\t\t} else if ( errorMessages.size === 1 ) {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: an error message */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'An error occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ][ 0 ]\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\terrorMessage = sprintf(\n\t\t\t\t\t\t/* translators: %s: a list of comma separated error messages */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Some errors occurred while permanently deleting the items: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\t[ ...errorMessages ].join( ',' )\n\t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