1 | import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
2 | import _createClass from "@babel/runtime/helpers/esm/createClass";
|
3 | import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
4 | import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
5 | import _inherits from "@babel/runtime/helpers/esm/inherits";
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import { Component } from '@wordpress/element';
|
11 | import { withSelect } from '@wordpress/data';
|
12 | import { addQueryArgs } from '@wordpress/url';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export function getPostEditURL(postId) {
|
22 | return addQueryArgs('post.php', {
|
23 | post: postId,
|
24 | action: 'edit'
|
25 | });
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | export function getPostTrashedURL(postId, postType) {
|
37 | return addQueryArgs('edit.php', {
|
38 | trashed: 1,
|
39 | post_type: postType,
|
40 | ids: postId
|
41 | });
|
42 | }
|
43 | export var BrowserURL =
|
44 |
|
45 | function (_Component) {
|
46 | _inherits(BrowserURL, _Component);
|
47 |
|
48 | function BrowserURL() {
|
49 | var _this;
|
50 |
|
51 | _classCallCheck(this, BrowserURL);
|
52 |
|
53 | _this = _possibleConstructorReturn(this, _getPrototypeOf(BrowserURL).apply(this, arguments));
|
54 | _this.state = {
|
55 | historyId: null
|
56 | };
|
57 | return _this;
|
58 | }
|
59 |
|
60 | _createClass(BrowserURL, [{
|
61 | key: "componentDidUpdate",
|
62 | value: function componentDidUpdate(prevProps) {
|
63 | var _this$props = this.props,
|
64 | postId = _this$props.postId,
|
65 | postStatus = _this$props.postStatus,
|
66 | postType = _this$props.postType;
|
67 | var historyId = this.state.historyId;
|
68 |
|
69 | if (postStatus === 'trash') {
|
70 | this.setTrashURL(postId, postType);
|
71 | return;
|
72 | }
|
73 |
|
74 | if ((postId !== prevProps.postId || postId !== historyId) && postStatus !== 'auto-draft') {
|
75 | this.setBrowserURL(postId);
|
76 | }
|
77 | }
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | }, {
|
86 | key: "setTrashURL",
|
87 | value: function setTrashURL(postId, postType) {
|
88 | window.location.href = getPostTrashedURL(postId, postType);
|
89 | }
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | }, {
|
101 | key: "setBrowserURL",
|
102 | value: function setBrowserURL(postId) {
|
103 | window.history.replaceState({
|
104 | id: postId
|
105 | }, 'Post ' + postId, getPostEditURL(postId));
|
106 | this.setState(function () {
|
107 | return {
|
108 | historyId: postId
|
109 | };
|
110 | });
|
111 | }
|
112 | }, {
|
113 | key: "render",
|
114 | value: function render() {
|
115 | return null;
|
116 | }
|
117 | }]);
|
118 |
|
119 | return BrowserURL;
|
120 | }(Component);
|
121 | export default withSelect(function (select) {
|
122 | var _select = select('core/editor'),
|
123 | getCurrentPost = _select.getCurrentPost;
|
124 |
|
125 | var _getCurrentPost = getCurrentPost(),
|
126 | id = _getCurrentPost.id,
|
127 | status = _getCurrentPost.status,
|
128 | type = _getCurrentPost.type;
|
129 |
|
130 | return {
|
131 | postId: id,
|
132 | postStatus: status,
|
133 | postType: type
|
134 | };
|
135 | })(BrowserURL);
|
136 |
|
\ | No newline at end of file |