@elementor/editor-site-navigation 0.19.10 → 0.20.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 +22 -0
- package/dist/index.js +142 -68
- package/dist/index.mjs +134 -58
- package/package.json +3 -2
- package/src/api/post.ts +1 -1
- package/src/api/settings.ts +5 -9
- package/src/api/user.ts +20 -0
- package/src/components/panel/actions-menu/actions/__tests__/delete.test.tsx +8 -0
- package/src/components/panel/actions-menu/actions/__tests__/set-home.test.tsx +52 -0
- package/src/components/panel/actions-menu/actions/__tests__/view.test.tsx +4 -0
- package/src/components/panel/actions-menu/actions/delete.tsx +4 -1
- package/src/components/panel/actions-menu/actions/duplicate.tsx +5 -1
- package/src/components/panel/actions-menu/actions/rename.tsx +1 -0
- package/src/components/panel/actions-menu/actions/set-home.tsx +9 -1
- package/src/components/panel/add-new-button.tsx +3 -0
- package/src/components/panel/posts-list/__tests__/post-list-item.test.tsx +20 -0
- package/src/components/panel/posts-list/__tests__/posts-collapsible-list.test.tsx +13 -7
- package/src/components/panel/posts-list/list-items/list-item-rename.tsx +17 -6
- package/src/components/panel/posts-list/list-items/list-item-view.tsx +52 -29
- package/src/components/panel/posts-list/posts-collapsible-list.tsx +1 -4
- package/src/components/shared/page-title-and-status.tsx +2 -3
- package/src/components/top-bar/__tests__/add-new-page.test.tsx +36 -0
- package/src/components/top-bar/__tests__/recently-edited.test.tsx +69 -1
- package/src/components/top-bar/create-post-list-item.tsx +3 -1
- package/src/components/top-bar/post-list-item.tsx +1 -0
- package/src/components/top-bar/recently-edited.tsx +1 -10
- package/src/hooks/__tests__/use-homepage.test.ts +1 -1
- package/src/hooks/__tests__/use-posts.test.ts +1 -1
- package/src/hooks/use-rename-active-document.ts +23 -0
- package/src/hooks/use-user.ts +11 -0
- package/src/types.ts +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.20.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.19.11...@elementor/editor-site-navigation@0.20.0) (2024-01-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **editor-site-navigation:** add permission based UI disabling [ED-13216] ([#152](https://github.com/elementor/elementor-packages/issues/152)) ([45f3e99](https://github.com/elementor/elementor-packages/commit/45f3e9955149045487ce21db9006c703e7777006))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.19.11](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.19.10...@elementor/editor-site-navigation@0.19.11) (2024-01-04)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **editor-site-navigation:** fix state between title on pages panel and recent pages [ED-13273] ([#151](https://github.com/elementor/elementor-packages/issues/151)) ([dd9aeff](https://github.com/elementor/elementor-packages/commit/dd9aeff9adebef5322c43c12f7f7bd48269a7885))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [0.19.10](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.19.9...@elementor/editor-site-navigation@0.19.10) (2024-01-02)
|
|
7
29
|
|
|
8
30
|
|
package/dist/index.js
CHANGED
|
@@ -153,6 +153,7 @@ function PostListItem({ post, closePopup, ...props }) {
|
|
|
153
153
|
return /* @__PURE__ */ React3.createElement(
|
|
154
154
|
import_ui3.MenuItem,
|
|
155
155
|
{
|
|
156
|
+
disabled: !post.user_can.edit,
|
|
156
157
|
onClick: async () => {
|
|
157
158
|
closePopup();
|
|
158
159
|
await navigateToDocument(post.id);
|
|
@@ -208,12 +209,41 @@ async function addNewPage() {
|
|
|
208
209
|
var import_icons3 = require("@elementor/icons");
|
|
209
210
|
var import_i18n = require("@wordpress/i18n");
|
|
210
211
|
var import_editor_documents2 = require("@elementor/editor-documents");
|
|
212
|
+
|
|
213
|
+
// src/hooks/use-user.ts
|
|
214
|
+
var import_query2 = require("@elementor/query");
|
|
215
|
+
|
|
216
|
+
// src/api/user.ts
|
|
217
|
+
var import_api_fetch3 = __toESM(require("@wordpress/api-fetch"));
|
|
218
|
+
var getUser = () => {
|
|
219
|
+
const baseUri = "/wp/v2/users/me";
|
|
220
|
+
const keys = ["capabilities"];
|
|
221
|
+
const queryParams = new URLSearchParams({
|
|
222
|
+
_fields: keys.join(","),
|
|
223
|
+
context: "edit"
|
|
224
|
+
});
|
|
225
|
+
const uri = baseUri + "?" + queryParams.toString();
|
|
226
|
+
return (0, import_api_fetch3.default)({ path: uri });
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// src/hooks/use-user.ts
|
|
230
|
+
var userQueryKey = () => ["site-navigation", "user"];
|
|
231
|
+
function useUser() {
|
|
232
|
+
return (0, import_query2.useQuery)({
|
|
233
|
+
queryKey: userQueryKey(),
|
|
234
|
+
queryFn: () => getUser()
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/components/top-bar/create-post-list-item.tsx
|
|
211
239
|
function CreatePostListItem({ closePopup, ...props }) {
|
|
212
240
|
const { create, isLoading } = useCreatePage();
|
|
213
241
|
const navigateToDocument = (0, import_editor_documents2.__useNavigateToDocument)();
|
|
242
|
+
const { data: user } = useUser();
|
|
214
243
|
return /* @__PURE__ */ React4.createElement(
|
|
215
244
|
import_ui4.MenuItem,
|
|
216
245
|
{
|
|
246
|
+
disabled: isLoading || !user?.capabilities?.edit_pages,
|
|
217
247
|
onClick: async () => {
|
|
218
248
|
const { id } = await create();
|
|
219
249
|
closePopup();
|
|
@@ -249,14 +279,7 @@ function RecentlyEdited() {
|
|
|
249
279
|
variant: "popover",
|
|
250
280
|
popupId: "elementor-v2-top-bar-recently-edited"
|
|
251
281
|
});
|
|
252
|
-
const
|
|
253
|
-
if (!document2) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
return data?.find((post) => post.id === document2.id);
|
|
257
|
-
};
|
|
258
|
-
const currentDocumentFromRecentPosts = getCurrentDocumentFromRecentPosts();
|
|
259
|
-
const documentTitle = useReverseHtmlEntities(currentDocumentFromRecentPosts ? currentDocumentFromRecentPosts.title : document2?.title);
|
|
282
|
+
const documentTitle = useReverseHtmlEntities(document2?.title);
|
|
260
283
|
if (!document2) {
|
|
261
284
|
return null;
|
|
262
285
|
}
|
|
@@ -321,10 +344,10 @@ var import_icons15 = require("@elementor/icons");
|
|
|
321
344
|
var import_ui15 = require("@elementor/ui");
|
|
322
345
|
|
|
323
346
|
// src/hooks/use-posts.ts
|
|
324
|
-
var
|
|
347
|
+
var import_query3 = require("@elementor/query");
|
|
325
348
|
|
|
326
349
|
// src/api/post.ts
|
|
327
|
-
var
|
|
350
|
+
var import_api_fetch4 = __toESM(require("@wordpress/api-fetch"));
|
|
328
351
|
var import_i18n3 = require("@wordpress/i18n");
|
|
329
352
|
var postTypesMap = {
|
|
330
353
|
page: {
|
|
@@ -337,7 +360,7 @@ var postTypesMap = {
|
|
|
337
360
|
};
|
|
338
361
|
var getRequest2 = (postTypeSlug) => {
|
|
339
362
|
const baseUri = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
|
|
340
|
-
const keys = ["id", "type", "title", "link", "status"];
|
|
363
|
+
const keys = ["id", "type", "title", "link", "status", "user_can"];
|
|
341
364
|
const queryParams = new URLSearchParams({
|
|
342
365
|
status: "any",
|
|
343
366
|
per_page: "-1",
|
|
@@ -345,11 +368,11 @@ var getRequest2 = (postTypeSlug) => {
|
|
|
345
368
|
_fields: keys.join(",")
|
|
346
369
|
});
|
|
347
370
|
const uri = baseUri + "?" + queryParams.toString();
|
|
348
|
-
return (0,
|
|
371
|
+
return (0, import_api_fetch4.default)({ path: uri });
|
|
349
372
|
};
|
|
350
373
|
var createRequest = (postTypeSlug, newPost) => {
|
|
351
374
|
const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
|
|
352
|
-
return (0,
|
|
375
|
+
return (0, import_api_fetch4.default)({
|
|
353
376
|
path,
|
|
354
377
|
method: "POST",
|
|
355
378
|
data: newPost
|
|
@@ -358,7 +381,7 @@ var createRequest = (postTypeSlug, newPost) => {
|
|
|
358
381
|
var updateRequest = (postTypeSlug, updatedPost) => {
|
|
359
382
|
const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
|
|
360
383
|
const { id, ...data } = updatedPost;
|
|
361
|
-
return (0,
|
|
384
|
+
return (0, import_api_fetch4.default)({
|
|
362
385
|
path: `${path}/${id}`,
|
|
363
386
|
method: "POST",
|
|
364
387
|
data
|
|
@@ -366,14 +389,14 @@ var updateRequest = (postTypeSlug, updatedPost) => {
|
|
|
366
389
|
};
|
|
367
390
|
var deleteRequest = (postTypeSlug, postId) => {
|
|
368
391
|
const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
|
|
369
|
-
return (0,
|
|
392
|
+
return (0, import_api_fetch4.default)({
|
|
370
393
|
path: `${path}/${postId}`,
|
|
371
394
|
method: "DELETE"
|
|
372
395
|
});
|
|
373
396
|
};
|
|
374
397
|
var duplicateRequest = (originalPost) => {
|
|
375
398
|
const path = `/elementor/v1/site-navigation/duplicate-post`;
|
|
376
|
-
return (0,
|
|
399
|
+
return (0, import_api_fetch4.default)({
|
|
377
400
|
path,
|
|
378
401
|
method: "POST",
|
|
379
402
|
data: {
|
|
@@ -386,7 +409,7 @@ var duplicateRequest = (originalPost) => {
|
|
|
386
409
|
// src/hooks/use-posts.ts
|
|
387
410
|
var postsQueryKey = (postTypeSlug) => ["site-navigation", "posts", postTypeSlug];
|
|
388
411
|
function usePosts(postTypeSlug) {
|
|
389
|
-
return (0,
|
|
412
|
+
return (0, import_query3.useQuery)({
|
|
390
413
|
queryKey: postsQueryKey(postTypeSlug),
|
|
391
414
|
queryFn: () => getRequest2(postTypeSlug)
|
|
392
415
|
});
|
|
@@ -490,23 +513,23 @@ var React20 = __toESM(require("react"));
|
|
|
490
513
|
var React9 = __toESM(require("react"));
|
|
491
514
|
|
|
492
515
|
// src/hooks/use-posts-actions.ts
|
|
493
|
-
var
|
|
516
|
+
var import_query4 = require("@elementor/query");
|
|
494
517
|
function usePostActions(postTypeSlug) {
|
|
495
518
|
const invalidatePosts = useInvalidatePosts(postTypeSlug);
|
|
496
519
|
const onSuccess = () => invalidatePosts({ exact: true });
|
|
497
|
-
const createPost = (0,
|
|
520
|
+
const createPost = (0, import_query4.useMutation)({
|
|
498
521
|
mutationFn: (newPost) => createRequest(postTypeSlug, newPost),
|
|
499
522
|
onSuccess
|
|
500
523
|
});
|
|
501
|
-
const updatePost = (0,
|
|
524
|
+
const updatePost = (0, import_query4.useMutation)({
|
|
502
525
|
mutationFn: (updatedPost) => updateRequest(postTypeSlug, updatedPost),
|
|
503
526
|
onSuccess
|
|
504
527
|
});
|
|
505
|
-
const deletePost = (0,
|
|
528
|
+
const deletePost = (0, import_query4.useMutation)({
|
|
506
529
|
mutationFn: (postId) => deleteRequest(postTypeSlug, postId),
|
|
507
530
|
onSuccess
|
|
508
531
|
});
|
|
509
|
-
const duplicatePost = (0,
|
|
532
|
+
const duplicatePost = (0, import_query4.useMutation)({
|
|
510
533
|
mutationFn: (originalPost) => duplicateRequest(originalPost),
|
|
511
534
|
onSuccess
|
|
512
535
|
});
|
|
@@ -518,7 +541,7 @@ function usePostActions(postTypeSlug) {
|
|
|
518
541
|
};
|
|
519
542
|
}
|
|
520
543
|
function useInvalidatePosts(postTypeSlug) {
|
|
521
|
-
const queryClient = (0,
|
|
544
|
+
const queryClient = (0, import_query4.useQueryClient)();
|
|
522
545
|
return (options = {}) => {
|
|
523
546
|
const queryKey = postsQueryKey(postTypeSlug);
|
|
524
547
|
queryClient.invalidateQueries({ queryKey: recentPostsQueryKey }, options);
|
|
@@ -605,37 +628,68 @@ function CloseButton({ isLoading, closeButton }) {
|
|
|
605
628
|
);
|
|
606
629
|
}
|
|
607
630
|
|
|
631
|
+
// src/components/panel/posts-list/list-items/list-item-rename.tsx
|
|
632
|
+
var import_editor_documents4 = require("@elementor/editor-documents");
|
|
633
|
+
|
|
634
|
+
// src/hooks/use-rename-active-document.ts
|
|
635
|
+
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
636
|
+
function getV1DocumentsManager() {
|
|
637
|
+
const documentsManager = window.elementor?.documents;
|
|
638
|
+
if (!documentsManager) {
|
|
639
|
+
throw new Error("Elementor Editor V1 documents manager not found");
|
|
640
|
+
}
|
|
641
|
+
return documentsManager;
|
|
642
|
+
}
|
|
643
|
+
function useRenameActiveDocument() {
|
|
644
|
+
return async (title) => {
|
|
645
|
+
const currentDocument = getV1DocumentsManager().getCurrent();
|
|
646
|
+
const container = currentDocument.container;
|
|
647
|
+
await (0, import_editor_v1_adapters.__privateRunCommand)("document/elements/settings", {
|
|
648
|
+
container,
|
|
649
|
+
settings: { post_title: title }
|
|
650
|
+
});
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
|
|
608
654
|
// src/components/panel/posts-list/list-items/list-item-rename.tsx
|
|
609
655
|
function ListItemRename({ post }) {
|
|
610
656
|
const { type, resetEditMode } = usePostListContext();
|
|
611
657
|
const { updatePost } = usePostActions(type);
|
|
612
658
|
const { setError } = usePostListContext();
|
|
659
|
+
const activeDocument = (0, import_editor_documents4.__useActiveDocument)();
|
|
660
|
+
const rename = useRenameActiveDocument();
|
|
661
|
+
const isActive = activeDocument?.id === post.id;
|
|
662
|
+
const title = isActive ? activeDocument?.title : post.title.rendered;
|
|
613
663
|
const renamePostCallback = async (inputValue) => {
|
|
614
|
-
if (inputValue ===
|
|
664
|
+
if (inputValue === title) {
|
|
615
665
|
resetEditMode();
|
|
616
666
|
}
|
|
617
667
|
try {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
668
|
+
if (isActive) {
|
|
669
|
+
await rename(inputValue);
|
|
670
|
+
} else {
|
|
671
|
+
await updatePost.mutateAsync({
|
|
672
|
+
id: post.id,
|
|
673
|
+
title: inputValue
|
|
674
|
+
});
|
|
675
|
+
}
|
|
622
676
|
} catch (e) {
|
|
623
677
|
setError();
|
|
624
678
|
} finally {
|
|
625
679
|
resetEditMode();
|
|
626
680
|
}
|
|
627
681
|
};
|
|
628
|
-
return /* @__PURE__ */ React9.createElement(EditModeTemplate, { postTitle:
|
|
682
|
+
return /* @__PURE__ */ React9.createElement(EditModeTemplate, { postTitle: title, isLoading: updatePost.isPending, callback: renamePostCallback });
|
|
629
683
|
}
|
|
630
684
|
|
|
631
685
|
// src/components/panel/posts-list/list-items/list-item-create.tsx
|
|
632
686
|
var React10 = __toESM(require("react"));
|
|
633
687
|
var import_i18n5 = require("@wordpress/i18n");
|
|
634
|
-
var
|
|
688
|
+
var import_editor_documents5 = require("@elementor/editor-documents");
|
|
635
689
|
function ListItemCreate() {
|
|
636
690
|
const { type, resetEditMode } = usePostListContext();
|
|
637
691
|
const { createPost } = usePostActions(type);
|
|
638
|
-
const navigateToDocument = (0,
|
|
692
|
+
const navigateToDocument = (0, import_editor_documents5.__useNavigateToDocument)();
|
|
639
693
|
const { setError } = usePostListContext();
|
|
640
694
|
const createPostCallback = async (inputValue) => {
|
|
641
695
|
try {
|
|
@@ -656,10 +710,10 @@ function ListItemCreate() {
|
|
|
656
710
|
// src/components/panel/posts-list/list-items/list-item-duplicate.tsx
|
|
657
711
|
var React11 = __toESM(require("react"));
|
|
658
712
|
var import_i18n6 = require("@wordpress/i18n");
|
|
659
|
-
var
|
|
713
|
+
var import_editor_documents6 = require("@elementor/editor-documents");
|
|
660
714
|
function ListItemDuplicate() {
|
|
661
715
|
const { type, editMode, resetEditMode } = usePostListContext();
|
|
662
|
-
const navigateToDocument = (0,
|
|
716
|
+
const navigateToDocument = (0, import_editor_documents6.__useNavigateToDocument)();
|
|
663
717
|
const { duplicatePost } = usePostActions(type);
|
|
664
718
|
const { setError } = usePostListContext();
|
|
665
719
|
if ("duplicate" !== editMode.mode) {
|
|
@@ -685,7 +739,7 @@ function ListItemDuplicate() {
|
|
|
685
739
|
var React19 = __toESM(require("react"));
|
|
686
740
|
var import_ui12 = require("@elementor/ui");
|
|
687
741
|
var import_icons12 = require("@elementor/icons");
|
|
688
|
-
var
|
|
742
|
+
var import_editor_documents8 = require("@elementor/editor-documents");
|
|
689
743
|
|
|
690
744
|
// src/components/shared/page-title-and-status.tsx
|
|
691
745
|
var React12 = __toESM(require("react"));
|
|
@@ -728,8 +782,8 @@ var PageTitle = ({ title }) => {
|
|
|
728
782
|
modifiedTitle
|
|
729
783
|
);
|
|
730
784
|
};
|
|
731
|
-
function PageTitleAndStatus({
|
|
732
|
-
return /* @__PURE__ */ React12.createElement(import_ui8.Box, { display: "flex" }, /* @__PURE__ */ React12.createElement(PageTitle, { title
|
|
785
|
+
function PageTitleAndStatus({ title, status }) {
|
|
786
|
+
return /* @__PURE__ */ React12.createElement(import_ui8.Box, { display: "flex" }, /* @__PURE__ */ React12.createElement(PageTitle, { title }), "\xA0", /* @__PURE__ */ React12.createElement(PageStatus, { status }));
|
|
733
787
|
}
|
|
734
788
|
|
|
735
789
|
// src/components/panel/actions-menu/actions/rename.tsx
|
|
@@ -755,6 +809,7 @@ function Rename({ post }) {
|
|
|
755
809
|
title: (0, import_i18n7.__)("Rename", "elementor"),
|
|
756
810
|
icon: import_icons7.EraseIcon,
|
|
757
811
|
MenuItemProps: {
|
|
812
|
+
disabled: !post.user_can.edit,
|
|
758
813
|
onClick: () => {
|
|
759
814
|
setEditMode({
|
|
760
815
|
mode: "rename",
|
|
@@ -774,6 +829,7 @@ var import_icons8 = require("@elementor/icons");
|
|
|
774
829
|
var import_i18n8 = require("@wordpress/i18n");
|
|
775
830
|
function Duplicate({ post, popupState }) {
|
|
776
831
|
const { setEditMode } = usePostListContext();
|
|
832
|
+
const { data: user } = useUser();
|
|
777
833
|
const onClick = () => {
|
|
778
834
|
popupState.close();
|
|
779
835
|
setEditMode({
|
|
@@ -784,12 +840,14 @@ function Duplicate({ post, popupState }) {
|
|
|
784
840
|
}
|
|
785
841
|
});
|
|
786
842
|
};
|
|
843
|
+
const isDisabled = !user?.capabilities?.edit_pages;
|
|
787
844
|
return /* @__PURE__ */ React15.createElement(
|
|
788
845
|
ActionMenuItem,
|
|
789
846
|
{
|
|
790
847
|
title: (0, import_i18n8.__)("Duplicate", "elementor"),
|
|
791
848
|
icon: import_icons8.CopyIcon,
|
|
792
849
|
MenuItemProps: {
|
|
850
|
+
disabled: isDisabled,
|
|
793
851
|
onClick
|
|
794
852
|
}
|
|
795
853
|
}
|
|
@@ -802,18 +860,20 @@ var import_icons9 = require("@elementor/icons");
|
|
|
802
860
|
var import_i18n9 = require("@wordpress/i18n");
|
|
803
861
|
var import_ui10 = require("@elementor/ui");
|
|
804
862
|
var import_react6 = require("react");
|
|
805
|
-
var
|
|
863
|
+
var import_editor_documents7 = require("@elementor/editor-documents");
|
|
806
864
|
function Delete({ post }) {
|
|
807
865
|
const [isDialogOpen, setIsDialogOpen] = (0, import_react6.useState)(false);
|
|
808
|
-
const activeDocument = (0,
|
|
866
|
+
const activeDocument = (0, import_editor_documents7.__useActiveDocument)();
|
|
809
867
|
const isPostActive = activeDocument?.id === post.id;
|
|
868
|
+
const userCanDelete = post.user_can.delete;
|
|
869
|
+
const isDisabled = !userCanDelete || post.isHome || isPostActive;
|
|
810
870
|
return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(
|
|
811
871
|
ActionMenuItem,
|
|
812
872
|
{
|
|
813
873
|
title: (0, import_i18n9.__)("Delete", "elementor"),
|
|
814
874
|
icon: import_icons9.TrashIcon,
|
|
815
875
|
MenuItemProps: {
|
|
816
|
-
disabled:
|
|
876
|
+
disabled: isDisabled,
|
|
817
877
|
onClick: () => setIsDialogOpen(true),
|
|
818
878
|
sx: { "&:hover": { color: "error.main" } }
|
|
819
879
|
}
|
|
@@ -878,21 +938,17 @@ var import_icons11 = require("@elementor/icons");
|
|
|
878
938
|
var import_i18n11 = require("@wordpress/i18n");
|
|
879
939
|
|
|
880
940
|
// src/hooks/use-homepage-actions.ts
|
|
881
|
-
var
|
|
941
|
+
var import_query6 = require("@elementor/query");
|
|
882
942
|
|
|
883
943
|
// src/api/settings.ts
|
|
884
|
-
var
|
|
944
|
+
var import_api_fetch5 = __toESM(require("@wordpress/api-fetch"));
|
|
885
945
|
var getSettings = () => {
|
|
886
|
-
const baseUri = "/
|
|
887
|
-
const
|
|
888
|
-
|
|
889
|
-
_fields: keys.join(",")
|
|
890
|
-
});
|
|
891
|
-
const uri = baseUri + "?" + queryParams.toString();
|
|
892
|
-
return (0, import_api_fetch4.default)({ path: uri });
|
|
946
|
+
const baseUri = "/elementor/v1/site-navigation/homepage";
|
|
947
|
+
const uri = baseUri;
|
|
948
|
+
return (0, import_api_fetch5.default)({ path: uri });
|
|
893
949
|
};
|
|
894
950
|
var updateSettings = (settings) => {
|
|
895
|
-
return (0,
|
|
951
|
+
return (0, import_api_fetch5.default)({
|
|
896
952
|
path: "/wp/v2/settings",
|
|
897
953
|
method: "POST",
|
|
898
954
|
data: settings
|
|
@@ -900,10 +956,10 @@ var updateSettings = (settings) => {
|
|
|
900
956
|
};
|
|
901
957
|
|
|
902
958
|
// src/hooks/use-homepage.ts
|
|
903
|
-
var
|
|
959
|
+
var import_query5 = require("@elementor/query");
|
|
904
960
|
var settingsQueryKey = () => ["site-navigation", "homepage"];
|
|
905
961
|
function useHomepage() {
|
|
906
|
-
return (0,
|
|
962
|
+
return (0, import_query5.useQuery)({
|
|
907
963
|
queryKey: settingsQueryKey(),
|
|
908
964
|
queryFn: () => getSettings()
|
|
909
965
|
});
|
|
@@ -913,14 +969,14 @@ function useHomepage() {
|
|
|
913
969
|
function useHomepageActions() {
|
|
914
970
|
const invalidateSettings = useInvalidateSettings();
|
|
915
971
|
const onSuccess = async () => invalidateSettings({ exact: true });
|
|
916
|
-
const updateSettingsMutation = (0,
|
|
972
|
+
const updateSettingsMutation = (0, import_query6.useMutation)({
|
|
917
973
|
mutationFn: (settings) => updateSettings(settings),
|
|
918
974
|
onSuccess
|
|
919
975
|
});
|
|
920
976
|
return { updateSettingsMutation };
|
|
921
977
|
}
|
|
922
978
|
function useInvalidateSettings() {
|
|
923
|
-
const queryClient = (0,
|
|
979
|
+
const queryClient = (0, import_query6.useQueryClient)();
|
|
924
980
|
return (options = {}) => {
|
|
925
981
|
const queryKey = settingsQueryKey();
|
|
926
982
|
return queryClient.invalidateQueries({ queryKey }, options);
|
|
@@ -932,6 +988,7 @@ var import_ui11 = require("@elementor/ui");
|
|
|
932
988
|
function SetHome({ post, closeMenu }) {
|
|
933
989
|
const { updateSettingsMutation } = useHomepageActions();
|
|
934
990
|
const { setError } = usePostListContext();
|
|
991
|
+
const { data: user } = useUser();
|
|
935
992
|
const handleClick = async () => {
|
|
936
993
|
try {
|
|
937
994
|
await updateSettingsMutation.mutateAsync({ show_on_front: "page", page_on_front: post.id });
|
|
@@ -941,13 +998,17 @@ function SetHome({ post, closeMenu }) {
|
|
|
941
998
|
closeMenu();
|
|
942
999
|
}
|
|
943
1000
|
};
|
|
1001
|
+
const canManageOptions = !!user?.capabilities?.manage_options;
|
|
1002
|
+
const isPostPublished = post.status === "publish";
|
|
1003
|
+
const isPostHomepage = !!post.isHome;
|
|
1004
|
+
const isDisabled = !canManageOptions || isPostHomepage || !isPostPublished || updateSettingsMutation.isPending;
|
|
944
1005
|
return /* @__PURE__ */ React18.createElement(
|
|
945
1006
|
ActionMenuItem,
|
|
946
1007
|
{
|
|
947
1008
|
title: (0, import_i18n11.__)("Set as homepage", "elementor"),
|
|
948
1009
|
icon: !updateSettingsMutation.isPending ? import_icons11.HomeIcon : import_ui11.CircularProgress,
|
|
949
1010
|
MenuItemProps: {
|
|
950
|
-
disabled:
|
|
1011
|
+
disabled: isDisabled,
|
|
951
1012
|
onClick: handleClick
|
|
952
1013
|
}
|
|
953
1014
|
}
|
|
@@ -956,16 +1017,34 @@ function SetHome({ post, closeMenu }) {
|
|
|
956
1017
|
|
|
957
1018
|
// src/components/panel/posts-list/list-items/list-item-view.tsx
|
|
958
1019
|
var import_i18n12 = require("@wordpress/i18n");
|
|
1020
|
+
var DisabledPostTooltip = ({ children, isDisabled }) => {
|
|
1021
|
+
if (isDisabled) {
|
|
1022
|
+
const title = /* @__PURE__ */ React19.createElement(import_ui12.Typography, { variant: "caption" }, "You cannot edit this page.", /* @__PURE__ */ React19.createElement("br", null), "To edit it directly, contact the site owner");
|
|
1023
|
+
return /* @__PURE__ */ React19.createElement(
|
|
1024
|
+
import_ui12.Tooltip,
|
|
1025
|
+
{
|
|
1026
|
+
title,
|
|
1027
|
+
placement: "bottom",
|
|
1028
|
+
arrow: false
|
|
1029
|
+
},
|
|
1030
|
+
children
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, children);
|
|
1034
|
+
};
|
|
959
1035
|
function ListItemView({ post }) {
|
|
960
|
-
const activeDocument = (0,
|
|
961
|
-
const navigateToDocument = (0,
|
|
1036
|
+
const activeDocument = (0, import_editor_documents8.__useActiveDocument)();
|
|
1037
|
+
const navigateToDocument = (0, import_editor_documents8.__useNavigateToDocument)();
|
|
962
1038
|
const popupState = (0, import_ui12.usePopupState)({
|
|
963
1039
|
variant: "popover",
|
|
964
1040
|
popupId: "post-actions",
|
|
965
1041
|
disableAutoFocus: true
|
|
966
1042
|
});
|
|
967
1043
|
const isActive = activeDocument?.id === post.id;
|
|
968
|
-
|
|
1044
|
+
const status = isActive ? activeDocument?.status.value : post.status;
|
|
1045
|
+
const title = isActive ? activeDocument?.title : post.title.rendered;
|
|
1046
|
+
const isDisabled = !post.user_can.edit;
|
|
1047
|
+
return /* @__PURE__ */ React19.createElement(React19.Fragment, null, /* @__PURE__ */ React19.createElement(DisabledPostTooltip, { isDisabled }, /* @__PURE__ */ React19.createElement(
|
|
969
1048
|
import_ui12.ListItem,
|
|
970
1049
|
{
|
|
971
1050
|
disablePadding: true,
|
|
@@ -983,6 +1062,7 @@ function ListItemView({ post }) {
|
|
|
983
1062
|
import_ui12.ListItemButton,
|
|
984
1063
|
{
|
|
985
1064
|
selected: isActive,
|
|
1065
|
+
disabled: isDisabled,
|
|
986
1066
|
onClick: () => {
|
|
987
1067
|
if (!isActive) {
|
|
988
1068
|
navigateToDocument(post.id);
|
|
@@ -990,16 +1070,10 @@ function ListItemView({ post }) {
|
|
|
990
1070
|
},
|
|
991
1071
|
dense: true
|
|
992
1072
|
},
|
|
993
|
-
/* @__PURE__ */ React19.createElement(
|
|
994
|
-
import_ui12.ListItemText,
|
|
995
|
-
{
|
|
996
|
-
disableTypography: true
|
|
997
|
-
},
|
|
998
|
-
/* @__PURE__ */ React19.createElement(PageTitleAndStatus, { page: post })
|
|
999
|
-
),
|
|
1073
|
+
/* @__PURE__ */ React19.createElement(import_ui12.ListItemText, { disableTypography: true }, /* @__PURE__ */ React19.createElement(PageTitleAndStatus, { title, status })),
|
|
1000
1074
|
post.isHome && /* @__PURE__ */ React19.createElement(import_icons12.HomeIcon, { titleAccess: (0, import_i18n12.__)("Homepage", "elementor"), color: "disabled" })
|
|
1001
1075
|
)
|
|
1002
|
-
), /* @__PURE__ */ React19.createElement(
|
|
1076
|
+
)), /* @__PURE__ */ React19.createElement(
|
|
1003
1077
|
import_ui12.Menu,
|
|
1004
1078
|
{
|
|
1005
1079
|
PaperProps: { sx: { mt: 2, width: 200 } },
|
|
@@ -1040,11 +1114,13 @@ var import_icons13 = require("@elementor/icons");
|
|
|
1040
1114
|
var import_i18n13 = require("@wordpress/i18n");
|
|
1041
1115
|
function AddNewButton() {
|
|
1042
1116
|
const { setEditMode } = usePostListContext();
|
|
1117
|
+
const { data: user } = useUser();
|
|
1043
1118
|
return /* @__PURE__ */ React21.createElement(
|
|
1044
1119
|
import_ui13.Button,
|
|
1045
1120
|
{
|
|
1046
1121
|
size: "small",
|
|
1047
1122
|
startIcon: /* @__PURE__ */ React21.createElement(import_icons13.PlusIcon, null),
|
|
1123
|
+
disabled: !user?.capabilities?.edit_pages,
|
|
1048
1124
|
onClick: () => {
|
|
1049
1125
|
setEditMode({ mode: "create", details: {} });
|
|
1050
1126
|
},
|
|
@@ -1082,7 +1158,7 @@ function ErrorState() {
|
|
|
1082
1158
|
function PostsCollapsibleList({ isOpenByDefault = false }) {
|
|
1083
1159
|
const { type, editMode } = usePostListContext();
|
|
1084
1160
|
const { data: posts, isLoading: postsLoading, isError: postsError } = usePosts(type);
|
|
1085
|
-
const { data:
|
|
1161
|
+
const { data: homepageId } = useHomepage();
|
|
1086
1162
|
if (postsError) {
|
|
1087
1163
|
return /* @__PURE__ */ React23.createElement(ErrorState, null);
|
|
1088
1164
|
}
|
|
@@ -1098,8 +1174,6 @@ function PostsCollapsibleList({ isOpenByDefault = false }) {
|
|
|
1098
1174
|
), /* @__PURE__ */ React23.createElement(import_ui15.Box, null, /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "100%", height: "24px" }), /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "70%", height: "24px" }), /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "70%", height: "24px" }), /* @__PURE__ */ React23.createElement(import_ui15.Skeleton, { sx: { my: 3 }, animation: "wave", variant: "rounded", width: "70%", height: "24px" })));
|
|
1099
1175
|
}
|
|
1100
1176
|
const label = `${postTypesMap[type].labels.plural_name} (${posts.length.toString()})`;
|
|
1101
|
-
const isHomepageSet = homepageSettings?.show_on_front === "page" && !!homepageSettings?.page_on_front;
|
|
1102
|
-
const homepageId = isHomepageSet ? homepageSettings.page_on_front : null;
|
|
1103
1177
|
const mappedPosts = posts.map((post) => {
|
|
1104
1178
|
if (post.id === homepageId) {
|
|
1105
1179
|
return { ...post, isHome: true };
|