@elementor/editor-site-navigation 0.13.0 → 0.14.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 +11 -0
- package/dist/index.js +25 -9
- package/dist/index.mjs +25 -9
- package/package.json +2 -2
- package/src/api/post.ts +13 -0
- package/src/components/panel/posts-list/list-items/list-item-duplicate.tsx +10 -5
- package/src/components/panel/posts-list/post-list-item.tsx +2 -2
- package/src/hooks/use-posts-actions.ts +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.14.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.13.0...@elementor/editor-site-navigation@0.14.0) (2023-07-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **site-navigation:** add duplicate action to pages panel [ED-10867] ([#95](https://github.com/elementor/elementor-packages/issues/95)) ([2fd8b3c](https://github.com/elementor/elementor-packages/commit/2fd8b3cc88feb525adc4dfebe75ea14189876075))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [0.13.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.12.0...@elementor/editor-site-navigation@0.13.0) (2023-07-26)
|
|
7
18
|
|
|
8
19
|
|
package/dist/index.js
CHANGED
|
@@ -318,6 +318,17 @@ var deleteRequest = (postTypeSlug, postId) => {
|
|
|
318
318
|
method: "DELETE"
|
|
319
319
|
});
|
|
320
320
|
};
|
|
321
|
+
var duplicateRequest = (originalPost) => {
|
|
322
|
+
const path = `/elementor/v1/site-navigation/duplicate-post`;
|
|
323
|
+
return (0, import_api_fetch3.default)({
|
|
324
|
+
path,
|
|
325
|
+
method: "POST",
|
|
326
|
+
data: {
|
|
327
|
+
post_id: originalPost.id,
|
|
328
|
+
title: originalPost.title
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
};
|
|
321
332
|
|
|
322
333
|
// src/hooks/use-posts.ts
|
|
323
334
|
var postsQueryKey = (postTypeSlug) => ["site-navigation", "posts", postTypeSlug];
|
|
@@ -423,10 +434,15 @@ function usePostActions(postTypeSlug) {
|
|
|
423
434
|
(postId) => deleteRequest(postTypeSlug, postId),
|
|
424
435
|
{ onSuccess }
|
|
425
436
|
);
|
|
437
|
+
const duplicatePost = (0, import_query2.useMutation)(
|
|
438
|
+
(originalPost) => duplicateRequest(originalPost),
|
|
439
|
+
{ onSuccess }
|
|
440
|
+
);
|
|
426
441
|
return {
|
|
427
442
|
createPost,
|
|
428
443
|
updatePost,
|
|
429
|
-
deletePost
|
|
444
|
+
deletePost,
|
|
445
|
+
duplicatePost
|
|
430
446
|
};
|
|
431
447
|
}
|
|
432
448
|
function useInvalidatePosts(postTypeSlug) {
|
|
@@ -550,23 +566,23 @@ function ListItemCreate() {
|
|
|
550
566
|
// src/components/panel/posts-list/list-items/list-item-duplicate.tsx
|
|
551
567
|
var React11 = __toESM(require("react"));
|
|
552
568
|
var import_i18n6 = require("@wordpress/i18n");
|
|
553
|
-
function ListItemDuplicate() {
|
|
569
|
+
function ListItemDuplicate({ post }) {
|
|
554
570
|
const { type, editMode, resetEditMode } = usePostListContext();
|
|
555
|
-
const {
|
|
571
|
+
const { duplicatePost } = usePostActions(type);
|
|
556
572
|
if ("duplicate" !== editMode.mode) {
|
|
557
573
|
return null;
|
|
558
574
|
}
|
|
559
575
|
const duplicatePostCallback = (inputValue) => {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
576
|
+
duplicatePost.mutateAsync({
|
|
577
|
+
id: post.id,
|
|
578
|
+
title: inputValue
|
|
563
579
|
}, {
|
|
564
580
|
onSuccess: () => {
|
|
565
581
|
resetEditMode();
|
|
566
582
|
}
|
|
567
583
|
});
|
|
568
584
|
};
|
|
569
|
-
return /* @__PURE__ */ React11.createElement(EditModeTemplate, { postTitle: `${editMode.details.title} ${(0, import_i18n6.__)("copy", "elementor")}`, isLoading:
|
|
585
|
+
return /* @__PURE__ */ React11.createElement(EditModeTemplate, { postTitle: `${editMode.details.title} ${(0, import_i18n6.__)("copy", "elementor")}`, isLoading: duplicatePost.isLoading, callback: duplicatePostCallback });
|
|
570
586
|
}
|
|
571
587
|
|
|
572
588
|
// src/components/panel/posts-list/list-items/list-item-view.tsx
|
|
@@ -817,8 +833,8 @@ function PostListItem2({ post }) {
|
|
|
817
833
|
if ("create" === editMode.mode && !post) {
|
|
818
834
|
return /* @__PURE__ */ React21.createElement(ListItemCreate, null);
|
|
819
835
|
}
|
|
820
|
-
if ("duplicate" === editMode.mode &&
|
|
821
|
-
return /* @__PURE__ */ React21.createElement(ListItemDuplicate,
|
|
836
|
+
if ("duplicate" === editMode.mode && post?.id && post?.id === editMode.details.postId) {
|
|
837
|
+
return /* @__PURE__ */ React21.createElement(ListItemDuplicate, { post });
|
|
822
838
|
}
|
|
823
839
|
if (!post) {
|
|
824
840
|
return null;
|
package/dist/index.mjs
CHANGED
|
@@ -300,6 +300,17 @@ var deleteRequest = (postTypeSlug, postId) => {
|
|
|
300
300
|
method: "DELETE"
|
|
301
301
|
});
|
|
302
302
|
};
|
|
303
|
+
var duplicateRequest = (originalPost) => {
|
|
304
|
+
const path = `/elementor/v1/site-navigation/duplicate-post`;
|
|
305
|
+
return apiFetch3({
|
|
306
|
+
path,
|
|
307
|
+
method: "POST",
|
|
308
|
+
data: {
|
|
309
|
+
post_id: originalPost.id,
|
|
310
|
+
title: originalPost.title
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
};
|
|
303
314
|
|
|
304
315
|
// src/hooks/use-posts.ts
|
|
305
316
|
var postsQueryKey = (postTypeSlug) => ["site-navigation", "posts", postTypeSlug];
|
|
@@ -405,10 +416,15 @@ function usePostActions(postTypeSlug) {
|
|
|
405
416
|
(postId) => deleteRequest(postTypeSlug, postId),
|
|
406
417
|
{ onSuccess }
|
|
407
418
|
);
|
|
419
|
+
const duplicatePost = useMutation(
|
|
420
|
+
(originalPost) => duplicateRequest(originalPost),
|
|
421
|
+
{ onSuccess }
|
|
422
|
+
);
|
|
408
423
|
return {
|
|
409
424
|
createPost,
|
|
410
425
|
updatePost,
|
|
411
|
-
deletePost
|
|
426
|
+
deletePost,
|
|
427
|
+
duplicatePost
|
|
412
428
|
};
|
|
413
429
|
}
|
|
414
430
|
function useInvalidatePosts(postTypeSlug) {
|
|
@@ -539,23 +555,23 @@ function ListItemCreate() {
|
|
|
539
555
|
// src/components/panel/posts-list/list-items/list-item-duplicate.tsx
|
|
540
556
|
import * as React11 from "react";
|
|
541
557
|
import { __ as __6 } from "@wordpress/i18n";
|
|
542
|
-
function ListItemDuplicate() {
|
|
558
|
+
function ListItemDuplicate({ post }) {
|
|
543
559
|
const { type, editMode, resetEditMode } = usePostListContext();
|
|
544
|
-
const {
|
|
560
|
+
const { duplicatePost } = usePostActions(type);
|
|
545
561
|
if ("duplicate" !== editMode.mode) {
|
|
546
562
|
return null;
|
|
547
563
|
}
|
|
548
564
|
const duplicatePostCallback = (inputValue) => {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
565
|
+
duplicatePost.mutateAsync({
|
|
566
|
+
id: post.id,
|
|
567
|
+
title: inputValue
|
|
552
568
|
}, {
|
|
553
569
|
onSuccess: () => {
|
|
554
570
|
resetEditMode();
|
|
555
571
|
}
|
|
556
572
|
});
|
|
557
573
|
};
|
|
558
|
-
return /* @__PURE__ */ React11.createElement(EditModeTemplate, { postTitle: `${editMode.details.title} ${__6("copy", "elementor")}`, isLoading:
|
|
574
|
+
return /* @__PURE__ */ React11.createElement(EditModeTemplate, { postTitle: `${editMode.details.title} ${__6("copy", "elementor")}`, isLoading: duplicatePost.isLoading, callback: duplicatePostCallback });
|
|
559
575
|
}
|
|
560
576
|
|
|
561
577
|
// src/components/panel/posts-list/list-items/list-item-view.tsx
|
|
@@ -817,8 +833,8 @@ function PostListItem2({ post }) {
|
|
|
817
833
|
if ("create" === editMode.mode && !post) {
|
|
818
834
|
return /* @__PURE__ */ React21.createElement(ListItemCreate, null);
|
|
819
835
|
}
|
|
820
|
-
if ("duplicate" === editMode.mode &&
|
|
821
|
-
return /* @__PURE__ */ React21.createElement(ListItemDuplicate,
|
|
836
|
+
if ("duplicate" === editMode.mode && post?.id && post?.id === editMode.details.postId) {
|
|
837
|
+
return /* @__PURE__ */ React21.createElement(ListItemDuplicate, { post });
|
|
822
838
|
}
|
|
823
839
|
if (!post) {
|
|
824
840
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-site-navigation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"elementor": {
|
|
50
50
|
"type": "extension"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "025f7ec0942da99205377c41e713afe1e8f7898d"
|
|
53
53
|
}
|
package/src/api/post.ts
CHANGED
|
@@ -70,3 +70,16 @@ export const deleteRequest = ( postTypeSlug: Slug, postId: number ) => {
|
|
|
70
70
|
method: 'DELETE',
|
|
71
71
|
} );
|
|
72
72
|
};
|
|
73
|
+
|
|
74
|
+
export const duplicateRequest = ( originalPost: UpdatePost ) => {
|
|
75
|
+
const path = `/elementor/v1/site-navigation/duplicate-post`;
|
|
76
|
+
|
|
77
|
+
return apiFetch( {
|
|
78
|
+
path,
|
|
79
|
+
method: 'POST',
|
|
80
|
+
data: {
|
|
81
|
+
post_id: originalPost.id,
|
|
82
|
+
title: originalPost.title,
|
|
83
|
+
},
|
|
84
|
+
} );
|
|
85
|
+
};
|
|
@@ -3,19 +3,24 @@ import { __ } from '@wordpress/i18n';
|
|
|
3
3
|
import { usePostListContext } from '../../../../contexts/post-list-context';
|
|
4
4
|
import { usePostActions } from '../../../../hooks/use-posts-actions';
|
|
5
5
|
import EditModeTemplate from './edit-mode-template';
|
|
6
|
+
import { Post } from '../../../../types';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
type Props = {
|
|
9
|
+
post: Post,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function ListItemDuplicate( { post }: Props ) {
|
|
8
13
|
const { type, editMode, resetEditMode } = usePostListContext();
|
|
9
|
-
const {
|
|
14
|
+
const { duplicatePost } = usePostActions( type );
|
|
10
15
|
|
|
11
16
|
if ( 'duplicate' !== editMode.mode ) {
|
|
12
17
|
return null;
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
const duplicatePostCallback = ( inputValue: string ) => {
|
|
16
|
-
|
|
21
|
+
duplicatePost.mutateAsync( {
|
|
22
|
+
id: post.id,
|
|
17
23
|
title: inputValue,
|
|
18
|
-
status: 'draft',
|
|
19
24
|
}, {
|
|
20
25
|
onSuccess: () => {
|
|
21
26
|
resetEditMode();
|
|
@@ -24,6 +29,6 @@ export default function ListItemDuplicate() {
|
|
|
24
29
|
};
|
|
25
30
|
|
|
26
31
|
return (
|
|
27
|
-
<EditModeTemplate postTitle={ `${ editMode.details.title } ${ __( 'copy', 'elementor' ) }` } isLoading={
|
|
32
|
+
<EditModeTemplate postTitle={ `${ editMode.details.title } ${ __( 'copy', 'elementor' ) }` } isLoading={ duplicatePost.isLoading } callback={ duplicatePostCallback } />
|
|
28
33
|
);
|
|
29
34
|
}
|
|
@@ -17,8 +17,8 @@ export default function PostListItem( { post }: { post?: Post } ) {
|
|
|
17
17
|
return <ListItemCreate />;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
if ( 'duplicate' === editMode.mode &&
|
|
21
|
-
return <ListItemDuplicate />;
|
|
20
|
+
if ( 'duplicate' === editMode.mode && post?.id && post?.id === editMode.details.postId ) {
|
|
21
|
+
return <ListItemDuplicate post={ post } />;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if ( ! post ) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useQueryClient, useMutation } from '@elementor/query';
|
|
2
|
-
import { createRequest, deleteRequest, updateRequest, NewPost, Slug, UpdatePost } from '../api/post';
|
|
2
|
+
import { createRequest, deleteRequest, updateRequest, duplicateRequest, NewPost, Slug, UpdatePost } from '../api/post';
|
|
3
3
|
import { postsQueryKey } from './use-posts';
|
|
4
4
|
|
|
5
5
|
export function usePostActions( postTypeSlug: Slug ) {
|
|
@@ -22,10 +22,16 @@ export function usePostActions( postTypeSlug: Slug ) {
|
|
|
22
22
|
{ onSuccess }
|
|
23
23
|
);
|
|
24
24
|
|
|
25
|
+
const duplicatePost = useMutation(
|
|
26
|
+
( originalPost: UpdatePost ) => duplicateRequest( originalPost ),
|
|
27
|
+
{ onSuccess }
|
|
28
|
+
);
|
|
29
|
+
|
|
25
30
|
return {
|
|
26
31
|
createPost,
|
|
27
32
|
updatePost,
|
|
28
33
|
deletePost,
|
|
34
|
+
duplicatePost,
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
37
|
|