@wordpress/core-commands 1.32.0 → 1.32.1-next.47f435fc9.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/build/admin-navigation-commands.js +59 -40
- package/build/admin-navigation-commands.js.map +7 -1
- package/build/index.js +45 -56
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -15
- package/build/lock-unlock.js.map +7 -1
- package/build/private-apis.js +33 -17
- package/build/private-apis.js.map +7 -1
- package/build/site-editor-navigation-commands.js +294 -266
- package/build/site-editor-navigation-commands.js.map +7 -1
- package/build/utils/order-entity-records-by-search.js +27 -7
- package/build/utils/order-entity-records-by-search.js.map +7 -1
- package/build-module/admin-navigation-commands.js +34 -31
- package/build-module/admin-navigation-commands.js.map +7 -1
- package/build-module/index.js +22 -44
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/private-apis.js +8 -8
- package/build-module/private-apis.js.map +7 -1
- package/build-module/site-editor-navigation-commands.js +256 -235
- package/build-module/site-editor-navigation-commands.js.map +7 -1
- package/build-module/utils/order-entity-records-by-search.js +5 -2
- package/build-module/utils/order-entity-records-by-search.js.map +7 -1
- package/package.json +22 -16
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} = unlock(routerPrivateApis);
|
|
1
|
+
import { useCommandLoader } from "@wordpress/commands";
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { useMemo, useEffect, useState } from "@wordpress/element";
|
|
4
|
+
import { useSelect } from "@wordpress/data";
|
|
5
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
6
|
+
import {
|
|
7
|
+
post,
|
|
8
|
+
page,
|
|
9
|
+
layout,
|
|
10
|
+
symbol,
|
|
11
|
+
symbolFilled,
|
|
12
|
+
styles,
|
|
13
|
+
navigation,
|
|
14
|
+
brush
|
|
15
|
+
} from "@wordpress/icons";
|
|
16
|
+
import { privateApis as routerPrivateApis } from "@wordpress/router";
|
|
17
|
+
import { addQueryArgs, getPath } from "@wordpress/url";
|
|
18
|
+
import { useDebounce } from "@wordpress/compose";
|
|
19
|
+
import { decodeEntities } from "@wordpress/html-entities";
|
|
20
|
+
import { unlock } from "./lock-unlock";
|
|
21
|
+
import { orderEntityRecordsBySearch } from "./utils/order-entity-records-by-search";
|
|
22
|
+
const { useHistory } = unlock(routerPrivateApis);
|
|
23
23
|
const icons = {
|
|
24
24
|
post,
|
|
25
25
|
page,
|
|
@@ -28,7 +28,7 @@ const icons = {
|
|
|
28
28
|
wp_template_part: symbolFilled
|
|
29
29
|
};
|
|
30
30
|
function useDebouncedValue(value) {
|
|
31
|
-
const [debouncedValue, setDebouncedValue] = useState(
|
|
31
|
+
const [debouncedValue, setDebouncedValue] = useState("");
|
|
32
32
|
const debounced = useDebounce(setDebouncedValue, 250);
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
debounced(value);
|
|
@@ -36,80 +36,94 @@ function useDebouncedValue(value) {
|
|
|
36
36
|
}, [debounced, value]);
|
|
37
37
|
return debouncedValue;
|
|
38
38
|
}
|
|
39
|
-
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
|
|
40
|
-
search
|
|
41
|
-
}) {
|
|
39
|
+
const getNavigationCommandLoaderPerPostType = (postType) => function useNavigationCommandLoader({ search }) {
|
|
42
40
|
const history = useHistory();
|
|
43
|
-
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
const { isBlockBasedTheme, canCreateTemplate } = useSelect(
|
|
42
|
+
(select) => {
|
|
43
|
+
return {
|
|
44
|
+
isBlockBasedTheme: select(coreStore).getCurrentTheme()?.is_block_theme,
|
|
45
|
+
canCreateTemplate: select(coreStore).canUser("create", {
|
|
46
|
+
kind: "postType",
|
|
47
|
+
name: "wp_template"
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
[]
|
|
52
|
+
);
|
|
55
53
|
const delayedSearch = useDebouncedValue(search);
|
|
56
|
-
const {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
const { records, isLoading } = useSelect(
|
|
55
|
+
(select) => {
|
|
56
|
+
if (!delayedSearch) {
|
|
57
|
+
return {
|
|
58
|
+
isLoading: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const query = {
|
|
62
|
+
search: delayedSearch,
|
|
63
|
+
per_page: 10,
|
|
64
|
+
orderby: "relevance",
|
|
65
|
+
status: [
|
|
66
|
+
"publish",
|
|
67
|
+
"future",
|
|
68
|
+
"draft",
|
|
69
|
+
"pending",
|
|
70
|
+
"private"
|
|
71
|
+
]
|
|
72
|
+
};
|
|
61
73
|
return {
|
|
62
|
-
|
|
74
|
+
records: select(coreStore).getEntityRecords(
|
|
75
|
+
"postType",
|
|
76
|
+
postType,
|
|
77
|
+
query
|
|
78
|
+
),
|
|
79
|
+
isLoading: !select(coreStore).hasFinishedResolution(
|
|
80
|
+
"getEntityRecords",
|
|
81
|
+
["postType", postType, query]
|
|
82
|
+
)
|
|
63
83
|
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
per_page: 10,
|
|
68
|
-
orderby: 'relevance',
|
|
69
|
-
status: ['publish', 'future', 'draft', 'pending', 'private']
|
|
70
|
-
};
|
|
71
|
-
return {
|
|
72
|
-
records: select(coreStore).getEntityRecords('postType', postType, query),
|
|
73
|
-
isLoading: !select(coreStore).hasFinishedResolution('getEntityRecords', ['postType', postType, query])
|
|
74
|
-
};
|
|
75
|
-
}, [delayedSearch]);
|
|
84
|
+
},
|
|
85
|
+
[delayedSearch]
|
|
86
|
+
);
|
|
76
87
|
const commands = useMemo(() => {
|
|
77
|
-
return (records
|
|
88
|
+
return (records ?? []).map((record) => {
|
|
78
89
|
const command = {
|
|
79
|
-
name: postType +
|
|
80
|
-
searchLabel: record.title?.rendered +
|
|
81
|
-
label: record.title?.rendered ? decodeEntities(record.title?.rendered) : __(
|
|
90
|
+
name: postType + "-" + record.id,
|
|
91
|
+
searchLabel: record.title?.rendered + " " + record.id,
|
|
92
|
+
label: record.title?.rendered ? decodeEntities(record.title?.rendered) : __("(no title)"),
|
|
82
93
|
icon: icons[postType]
|
|
83
94
|
};
|
|
84
|
-
if (!canCreateTemplate || postType ===
|
|
95
|
+
if (!canCreateTemplate || postType === "post" || postType === "page" && !isBlockBasedTheme) {
|
|
85
96
|
return {
|
|
86
97
|
...command,
|
|
87
|
-
callback: ({
|
|
88
|
-
close
|
|
89
|
-
}) => {
|
|
98
|
+
callback: ({ close }) => {
|
|
90
99
|
const args = {
|
|
91
100
|
post: record.id,
|
|
92
|
-
action:
|
|
101
|
+
action: "edit"
|
|
93
102
|
};
|
|
94
|
-
const targetUrl = addQueryArgs(
|
|
103
|
+
const targetUrl = addQueryArgs("post.php", args);
|
|
95
104
|
document.location = targetUrl;
|
|
96
105
|
close();
|
|
97
106
|
}
|
|
98
107
|
};
|
|
99
108
|
}
|
|
100
|
-
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
109
|
+
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
110
|
+
"site-editor.php"
|
|
111
|
+
);
|
|
101
112
|
return {
|
|
102
113
|
...command,
|
|
103
|
-
callback: ({
|
|
104
|
-
close
|
|
105
|
-
}) => {
|
|
114
|
+
callback: ({ close }) => {
|
|
106
115
|
if (isSiteEditor) {
|
|
107
|
-
history.navigate(
|
|
116
|
+
history.navigate(
|
|
117
|
+
`/${postType}/${record.id}?canvas=edit`
|
|
118
|
+
);
|
|
108
119
|
} else {
|
|
109
|
-
document.location = addQueryArgs(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
document.location = addQueryArgs(
|
|
121
|
+
"site-editor.php",
|
|
122
|
+
{
|
|
123
|
+
p: `/${postType}/${record.id}`,
|
|
124
|
+
canvas: "edit"
|
|
125
|
+
}
|
|
126
|
+
);
|
|
113
127
|
}
|
|
114
128
|
close();
|
|
115
129
|
}
|
|
@@ -121,89 +135,87 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
121
135
|
isLoading
|
|
122
136
|
};
|
|
123
137
|
};
|
|
124
|
-
const getNavigationCommandLoaderPerTemplate = templateType => function useNavigationCommandLoader({
|
|
125
|
-
search
|
|
126
|
-
}) {
|
|
138
|
+
const getNavigationCommandLoaderPerTemplate = (templateType) => function useNavigationCommandLoader({ search }) {
|
|
127
139
|
const history = useHistory();
|
|
128
|
-
const {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} = useSelect(select => {
|
|
144
|
-
const {
|
|
145
|
-
getEntityRecords
|
|
146
|
-
} = select(coreStore);
|
|
147
|
-
const query = {
|
|
148
|
-
per_page: -1
|
|
149
|
-
};
|
|
140
|
+
const { isBlockBasedTheme, canCreateTemplate } = useSelect(
|
|
141
|
+
(select) => {
|
|
142
|
+
return {
|
|
143
|
+
isBlockBasedTheme: select(coreStore).getCurrentTheme()?.is_block_theme,
|
|
144
|
+
canCreateTemplate: select(coreStore).canUser("read", {
|
|
145
|
+
kind: "postType",
|
|
146
|
+
name: templateType
|
|
147
|
+
})
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
[]
|
|
151
|
+
);
|
|
152
|
+
const { records, isLoading } = useSelect((select) => {
|
|
153
|
+
const { getEntityRecords } = select(coreStore);
|
|
154
|
+
const query = { per_page: -1 };
|
|
150
155
|
return {
|
|
151
|
-
records: getEntityRecords(
|
|
152
|
-
isLoading: !select(coreStore).hasFinishedResolution(
|
|
156
|
+
records: getEntityRecords("postType", templateType, query),
|
|
157
|
+
isLoading: !select(coreStore).hasFinishedResolution(
|
|
158
|
+
"getEntityRecords",
|
|
159
|
+
["postType", templateType, query]
|
|
160
|
+
)
|
|
153
161
|
};
|
|
154
162
|
}, []);
|
|
155
|
-
|
|
156
|
-
/*
|
|
157
|
-
* wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
|
|
158
|
-
* We need to sort the results based on the search query to avoid removing relevant
|
|
159
|
-
* records below using .slice().
|
|
160
|
-
*/
|
|
161
163
|
const orderedRecords = useMemo(() => {
|
|
162
164
|
return orderEntityRecordsBySearch(records, search).slice(0, 10);
|
|
163
165
|
}, [records, search]);
|
|
164
166
|
const commands = useMemo(() => {
|
|
165
|
-
if (!canCreateTemplate || !isBlockBasedTheme && !templateType ===
|
|
167
|
+
if (!canCreateTemplate || !isBlockBasedTheme && !templateType === "wp_template_part") {
|
|
166
168
|
return [];
|
|
167
169
|
}
|
|
168
|
-
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
170
|
+
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
171
|
+
"site-editor.php"
|
|
172
|
+
);
|
|
169
173
|
const result = [];
|
|
170
|
-
result.push(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
close
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
174
|
+
result.push(
|
|
175
|
+
...orderedRecords.map((record) => {
|
|
176
|
+
return {
|
|
177
|
+
name: templateType + "-" + record.id,
|
|
178
|
+
searchLabel: record.title?.rendered + " " + record.id,
|
|
179
|
+
label: record.title?.rendered ? record.title?.rendered : __("(no title)"),
|
|
180
|
+
icon: icons[templateType],
|
|
181
|
+
callback: ({ close }) => {
|
|
182
|
+
if (isSiteEditor) {
|
|
183
|
+
history.navigate(
|
|
184
|
+
`/${templateType}/${record.id}?canvas=edit`
|
|
185
|
+
);
|
|
186
|
+
} else {
|
|
187
|
+
document.location = addQueryArgs(
|
|
188
|
+
"site-editor.php",
|
|
189
|
+
{
|
|
190
|
+
p: `/${templateType}/${record.id}`,
|
|
191
|
+
canvas: "edit"
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
close();
|
|
186
196
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (orderedRecords?.length > 0 && templateType === 'wp_template_part') {
|
|
197
|
+
};
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
if (orderedRecords?.length > 0 && templateType === "wp_template_part") {
|
|
192
201
|
result.push({
|
|
193
|
-
name:
|
|
194
|
-
label: __(
|
|
202
|
+
name: "core/edit-site/open-template-parts",
|
|
203
|
+
label: __("Go to: Template parts"),
|
|
195
204
|
icon: symbolFilled,
|
|
196
|
-
callback: ({
|
|
197
|
-
close
|
|
198
|
-
}) => {
|
|
205
|
+
callback: ({ close }) => {
|
|
199
206
|
if (isSiteEditor) {
|
|
200
|
-
history.navigate(
|
|
207
|
+
history.navigate(
|
|
208
|
+
"/pattern?postType=wp_template_part&categoryId=all-parts"
|
|
209
|
+
);
|
|
201
210
|
} else {
|
|
202
|
-
document.location = addQueryArgs(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
document.location = addQueryArgs(
|
|
212
|
+
"site-editor.php",
|
|
213
|
+
{
|
|
214
|
+
p: "/pattern",
|
|
215
|
+
postType: "wp_template_part",
|
|
216
|
+
categoryId: "all-parts"
|
|
217
|
+
}
|
|
218
|
+
);
|
|
207
219
|
}
|
|
208
220
|
close();
|
|
209
221
|
}
|
|
@@ -218,75 +230,75 @@ const getNavigationCommandLoaderPerTemplate = templateType => function useNaviga
|
|
|
218
230
|
};
|
|
219
231
|
const getSiteEditorBasicNavigationCommands = () => function useSiteEditorBasicNavigationCommands() {
|
|
220
232
|
const history = useHistory();
|
|
221
|
-
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
canCreatePatterns
|
|
226
|
-
} = useSelect(select => {
|
|
233
|
+
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
234
|
+
"site-editor.php"
|
|
235
|
+
);
|
|
236
|
+
const { isBlockBasedTheme, canCreateTemplate, canCreatePatterns } = useSelect((select) => {
|
|
227
237
|
return {
|
|
228
238
|
isBlockBasedTheme: select(coreStore).getCurrentTheme()?.is_block_theme,
|
|
229
|
-
canCreateTemplate: select(coreStore).canUser(
|
|
230
|
-
kind:
|
|
231
|
-
name:
|
|
239
|
+
canCreateTemplate: select(coreStore).canUser("create", {
|
|
240
|
+
kind: "postType",
|
|
241
|
+
name: "wp_template"
|
|
232
242
|
}),
|
|
233
|
-
canCreatePatterns: select(coreStore).canUser(
|
|
234
|
-
kind:
|
|
235
|
-
name:
|
|
243
|
+
canCreatePatterns: select(coreStore).canUser("create", {
|
|
244
|
+
kind: "postType",
|
|
245
|
+
name: "wp_block"
|
|
236
246
|
})
|
|
237
247
|
};
|
|
238
248
|
}, []);
|
|
239
249
|
const commands = useMemo(() => {
|
|
240
250
|
const result = [];
|
|
241
251
|
if (canCreateTemplate && isBlockBasedTheme) {
|
|
242
|
-
// Go to Styles command
|
|
243
252
|
result.push({
|
|
244
|
-
name:
|
|
245
|
-
label: __(
|
|
253
|
+
name: "core/edit-site/open-styles",
|
|
254
|
+
label: __("Go to: Styles"),
|
|
246
255
|
icon: styles,
|
|
247
|
-
callback: ({
|
|
248
|
-
close
|
|
249
|
-
}) => {
|
|
256
|
+
callback: ({ close }) => {
|
|
250
257
|
if (isSiteEditor) {
|
|
251
|
-
history.navigate(
|
|
258
|
+
history.navigate("/styles");
|
|
252
259
|
} else {
|
|
253
|
-
document.location = addQueryArgs(
|
|
254
|
-
|
|
255
|
-
|
|
260
|
+
document.location = addQueryArgs(
|
|
261
|
+
"site-editor.php",
|
|
262
|
+
{
|
|
263
|
+
p: "/styles"
|
|
264
|
+
}
|
|
265
|
+
);
|
|
256
266
|
}
|
|
257
267
|
close();
|
|
258
268
|
}
|
|
259
269
|
});
|
|
260
270
|
result.push({
|
|
261
|
-
name:
|
|
262
|
-
label: __(
|
|
271
|
+
name: "core/edit-site/open-navigation",
|
|
272
|
+
label: __("Go to: Navigation"),
|
|
263
273
|
icon: navigation,
|
|
264
|
-
callback: ({
|
|
265
|
-
close
|
|
266
|
-
}) => {
|
|
274
|
+
callback: ({ close }) => {
|
|
267
275
|
if (isSiteEditor) {
|
|
268
|
-
history.navigate(
|
|
276
|
+
history.navigate("/navigation");
|
|
269
277
|
} else {
|
|
270
|
-
document.location = addQueryArgs(
|
|
271
|
-
|
|
272
|
-
|
|
278
|
+
document.location = addQueryArgs(
|
|
279
|
+
"site-editor.php",
|
|
280
|
+
{
|
|
281
|
+
p: "/navigation"
|
|
282
|
+
}
|
|
283
|
+
);
|
|
273
284
|
}
|
|
274
285
|
close();
|
|
275
286
|
}
|
|
276
287
|
});
|
|
277
288
|
result.push({
|
|
278
|
-
name:
|
|
279
|
-
label: __(
|
|
289
|
+
name: "core/edit-site/open-templates",
|
|
290
|
+
label: __("Go to: Templates"),
|
|
280
291
|
icon: layout,
|
|
281
|
-
callback: ({
|
|
282
|
-
close
|
|
283
|
-
}) => {
|
|
292
|
+
callback: ({ close }) => {
|
|
284
293
|
if (isSiteEditor) {
|
|
285
|
-
history.navigate(
|
|
294
|
+
history.navigate("/template");
|
|
286
295
|
} else {
|
|
287
|
-
document.location = addQueryArgs(
|
|
288
|
-
|
|
289
|
-
|
|
296
|
+
document.location = addQueryArgs(
|
|
297
|
+
"site-editor.php",
|
|
298
|
+
{
|
|
299
|
+
p: "/template"
|
|
300
|
+
}
|
|
301
|
+
);
|
|
290
302
|
}
|
|
291
303
|
close();
|
|
292
304
|
}
|
|
@@ -294,30 +306,36 @@ const getSiteEditorBasicNavigationCommands = () => function useSiteEditorBasicNa
|
|
|
294
306
|
}
|
|
295
307
|
if (canCreatePatterns) {
|
|
296
308
|
result.push({
|
|
297
|
-
name:
|
|
298
|
-
label: __(
|
|
309
|
+
name: "core/edit-site/open-patterns",
|
|
310
|
+
label: __("Go to: Patterns"),
|
|
299
311
|
icon: symbol,
|
|
300
|
-
callback: ({
|
|
301
|
-
close
|
|
302
|
-
}) => {
|
|
312
|
+
callback: ({ close }) => {
|
|
303
313
|
if (canCreateTemplate) {
|
|
304
314
|
if (isSiteEditor) {
|
|
305
|
-
history.navigate(
|
|
315
|
+
history.navigate("/pattern");
|
|
306
316
|
} else {
|
|
307
|
-
document.location = addQueryArgs(
|
|
308
|
-
|
|
309
|
-
|
|
317
|
+
document.location = addQueryArgs(
|
|
318
|
+
"site-editor.php",
|
|
319
|
+
{
|
|
320
|
+
p: "/pattern"
|
|
321
|
+
}
|
|
322
|
+
);
|
|
310
323
|
}
|
|
311
324
|
close();
|
|
312
325
|
} else {
|
|
313
|
-
|
|
314
|
-
document.location.href = 'edit.php?post_type=wp_block';
|
|
326
|
+
document.location.href = "edit.php?post_type=wp_block";
|
|
315
327
|
}
|
|
316
328
|
}
|
|
317
329
|
});
|
|
318
330
|
}
|
|
319
331
|
return result;
|
|
320
|
-
}, [
|
|
332
|
+
}, [
|
|
333
|
+
history,
|
|
334
|
+
isSiteEditor,
|
|
335
|
+
canCreateTemplate,
|
|
336
|
+
canCreatePatterns,
|
|
337
|
+
isBlockBasedTheme
|
|
338
|
+
]);
|
|
321
339
|
return {
|
|
322
340
|
commands,
|
|
323
341
|
isLoading: false
|
|
@@ -325,77 +343,80 @@ const getSiteEditorBasicNavigationCommands = () => function useSiteEditorBasicNa
|
|
|
325
343
|
};
|
|
326
344
|
const getGlobalStylesOpenCssCommands = () => function useGlobalStylesOpenCssCommands() {
|
|
327
345
|
const history = useHistory();
|
|
328
|
-
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
} = useSelect(select => {
|
|
332
|
-
const {
|
|
333
|
-
getEntityRecord,
|
|
334
|
-
__experimentalGetCurrentGlobalStylesId
|
|
335
|
-
} = select(coreStore);
|
|
346
|
+
const isSiteEditor = getPath(window.location.href)?.includes(
|
|
347
|
+
"site-editor.php"
|
|
348
|
+
);
|
|
349
|
+
const { canEditCSS } = useSelect((select) => {
|
|
350
|
+
const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = select(coreStore);
|
|
336
351
|
const globalStylesId = __experimentalGetCurrentGlobalStylesId();
|
|
337
|
-
const globalStyles = globalStylesId ? getEntityRecord(
|
|
352
|
+
const globalStyles = globalStylesId ? getEntityRecord("root", "globalStyles", globalStylesId) : void 0;
|
|
338
353
|
return {
|
|
339
|
-
canEditCSS: !!globalStyles?._links?.[
|
|
354
|
+
canEditCSS: !!globalStyles?._links?.["wp:action-edit-css"]
|
|
340
355
|
};
|
|
341
356
|
}, []);
|
|
342
357
|
const commands = useMemo(() => {
|
|
343
358
|
if (!canEditCSS) {
|
|
344
359
|
return [];
|
|
345
360
|
}
|
|
346
|
-
return [
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
close
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
+
return [
|
|
362
|
+
{
|
|
363
|
+
name: "core/open-styles-css",
|
|
364
|
+
label: __("Open custom CSS"),
|
|
365
|
+
icon: brush,
|
|
366
|
+
callback: ({ close }) => {
|
|
367
|
+
close();
|
|
368
|
+
if (isSiteEditor) {
|
|
369
|
+
history.navigate("/styles?section=/css");
|
|
370
|
+
} else {
|
|
371
|
+
document.location = addQueryArgs(
|
|
372
|
+
"site-editor.php",
|
|
373
|
+
{
|
|
374
|
+
p: "/styles",
|
|
375
|
+
section: "/css"
|
|
376
|
+
}
|
|
377
|
+
);
|
|
378
|
+
}
|
|
361
379
|
}
|
|
362
380
|
}
|
|
363
|
-
|
|
381
|
+
];
|
|
364
382
|
}, [history, canEditCSS, isSiteEditor]);
|
|
365
383
|
return {
|
|
366
384
|
isLoading: false,
|
|
367
385
|
commands
|
|
368
386
|
};
|
|
369
387
|
};
|
|
370
|
-
|
|
388
|
+
function useSiteEditorNavigationCommands() {
|
|
371
389
|
useCommandLoader({
|
|
372
|
-
name:
|
|
373
|
-
hook: getNavigationCommandLoaderPerPostType(
|
|
390
|
+
name: "core/edit-site/navigate-pages",
|
|
391
|
+
hook: getNavigationCommandLoaderPerPostType("page")
|
|
374
392
|
});
|
|
375
393
|
useCommandLoader({
|
|
376
|
-
name:
|
|
377
|
-
hook: getNavigationCommandLoaderPerPostType(
|
|
394
|
+
name: "core/edit-site/navigate-posts",
|
|
395
|
+
hook: getNavigationCommandLoaderPerPostType("post")
|
|
378
396
|
});
|
|
379
397
|
useCommandLoader({
|
|
380
|
-
name:
|
|
381
|
-
hook: getNavigationCommandLoaderPerTemplate(
|
|
398
|
+
name: "core/edit-site/navigate-templates",
|
|
399
|
+
hook: getNavigationCommandLoaderPerTemplate("wp_template")
|
|
382
400
|
});
|
|
383
401
|
useCommandLoader({
|
|
384
|
-
name:
|
|
385
|
-
hook: getNavigationCommandLoaderPerTemplate(
|
|
402
|
+
name: "core/edit-site/navigate-templates",
|
|
403
|
+
hook: getNavigationCommandLoaderPerTemplate("wp_registered_template")
|
|
386
404
|
});
|
|
387
405
|
useCommandLoader({
|
|
388
|
-
name:
|
|
389
|
-
hook: getNavigationCommandLoaderPerTemplate(
|
|
406
|
+
name: "core/edit-site/navigate-template-parts",
|
|
407
|
+
hook: getNavigationCommandLoaderPerTemplate("wp_template_part")
|
|
390
408
|
});
|
|
391
409
|
useCommandLoader({
|
|
392
|
-
name:
|
|
410
|
+
name: "core/edit-site/basic-navigation",
|
|
393
411
|
hook: getSiteEditorBasicNavigationCommands(),
|
|
394
|
-
context:
|
|
412
|
+
context: "site-editor"
|
|
395
413
|
});
|
|
396
414
|
useCommandLoader({
|
|
397
|
-
name:
|
|
415
|
+
name: "core/edit-site/global-styles-css",
|
|
398
416
|
hook: getGlobalStylesOpenCssCommands()
|
|
399
417
|
});
|
|
400
418
|
}
|
|
401
|
-
|
|
419
|
+
export {
|
|
420
|
+
useSiteEditorNavigationCommands
|
|
421
|
+
};
|
|
422
|
+
//# sourceMappingURL=site-editor-navigation-commands.js.map
|