@elementor/editor-site-navigation 0.13.0 → 0.15.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 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.15.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.14.0...@elementor/editor-site-navigation@0.15.0) (2023-07-30)
7
+
8
+
9
+ ### Features
10
+
11
+ * **site-navigation:** add duplicate action to pages panel - fix [ED-10867] ([#96](https://github.com/elementor/elementor-packages/issues/96)) ([a1ece1b](https://github.com/elementor/elementor-packages/commit/a1ece1bf08657e8bc905cad59e3f9f65064b2f9a))
12
+
13
+
14
+
15
+
16
+
17
+ # [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * **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))
23
+
24
+
25
+
26
+
27
+
6
28
  # [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
29
 
8
30
 
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) {
@@ -552,21 +568,21 @@ var React11 = __toESM(require("react"));
552
568
  var import_i18n6 = require("@wordpress/i18n");
553
569
  function ListItemDuplicate() {
554
570
  const { type, editMode, resetEditMode } = usePostListContext();
555
- const { createPost } = usePostActions(type);
571
+ const { duplicatePost } = usePostActions(type);
556
572
  if ("duplicate" !== editMode.mode) {
557
573
  return null;
558
574
  }
559
575
  const duplicatePostCallback = (inputValue) => {
560
- createPost.mutateAsync({
561
- title: inputValue,
562
- status: "draft"
576
+ duplicatePost.mutateAsync({
577
+ id: editMode.details.postId,
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: createPost.isLoading, callback: duplicatePostCallback });
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
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) {
@@ -541,21 +557,21 @@ import * as React11 from "react";
541
557
  import { __ as __6 } from "@wordpress/i18n";
542
558
  function ListItemDuplicate() {
543
559
  const { type, editMode, resetEditMode } = usePostListContext();
544
- const { createPost } = usePostActions(type);
560
+ const { duplicatePost } = usePostActions(type);
545
561
  if ("duplicate" !== editMode.mode) {
546
562
  return null;
547
563
  }
548
564
  const duplicatePostCallback = (inputValue) => {
549
- createPost.mutateAsync({
550
- title: inputValue,
551
- status: "draft"
565
+ duplicatePost.mutateAsync({
566
+ id: editMode.details.postId,
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: createPost.isLoading, callback: duplicatePostCallback });
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-site-navigation",
3
- "version": "0.13.0",
3
+ "version": "0.15.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": "eb0ac23904894e5643c30e5b66b91541032bb8a0"
52
+ "gitHead": "78d26926d1e887adf068cfc7974b36aaf46c0e5c"
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
+ };
@@ -6,16 +6,16 @@ import EditModeTemplate from './edit-mode-template';
6
6
 
7
7
  export default function ListItemDuplicate() {
8
8
  const { type, editMode, resetEditMode } = usePostListContext();
9
- const { createPost } = usePostActions( type );
9
+ const { duplicatePost } = usePostActions( type );
10
10
 
11
11
  if ( 'duplicate' !== editMode.mode ) {
12
12
  return null;
13
13
  }
14
14
 
15
15
  const duplicatePostCallback = ( inputValue: string ) => {
16
- createPost.mutateAsync( {
16
+ duplicatePost.mutateAsync( {
17
+ id: editMode.details.postId,
17
18
  title: inputValue,
18
- status: 'draft',
19
19
  }, {
20
20
  onSuccess: () => {
21
21
  resetEditMode();
@@ -24,6 +24,6 @@ export default function ListItemDuplicate() {
24
24
  };
25
25
 
26
26
  return (
27
- <EditModeTemplate postTitle={ `${ editMode.details.title } ${ __( 'copy', 'elementor' ) }` } isLoading={ createPost.isLoading } callback={ duplicatePostCallback } />
27
+ <EditModeTemplate postTitle={ `${ editMode.details.title } ${ __( 'copy', 'elementor' ) }` } isLoading={ duplicatePost.isLoading } callback={ duplicatePostCallback } />
28
28
  );
29
29
  }
@@ -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