@elementor/editor-site-navigation 0.10.3 → 0.12.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.js +445 -174
  3. package/dist/index.mjs +441 -161
  4. package/package.json +2 -2
  5. package/src/api/post.ts +14 -6
  6. package/src/components/panel/actions-menu/action-list-item.tsx +1 -1
  7. package/src/components/panel/{pages-actions → actions-menu/actions}/delete.tsx +5 -5
  8. package/src/components/panel/actions-menu/actions/duplicate.tsx +29 -0
  9. package/src/components/panel/actions-menu/actions/rename.tsx +25 -0
  10. package/src/components/panel/{pages-actions → actions-menu/actions}/set-home.tsx +4 -4
  11. package/src/components/panel/actions-menu/actions/view.tsx +25 -0
  12. package/src/components/panel/add-new-button.tsx +22 -0
  13. package/src/components/panel/{pages-list/__tests__/page-list-item.test.tsx → posts-list/__tests__/post-list-item.test.tsx} +21 -18
  14. package/src/components/panel/{pages-list/__tests__/pages-collapsible-list.test.tsx → posts-list/__tests__/posts-collapsible-list.test.tsx} +11 -14
  15. package/src/components/panel/{pages-list → posts-list}/collapsible-list.tsx +4 -4
  16. package/src/components/panel/posts-list/list-items/edit-mode-template.tsx +103 -0
  17. package/src/components/panel/posts-list/list-items/list-item-create.tsx +25 -0
  18. package/src/components/panel/posts-list/list-items/list-item-duplicate.tsx +29 -0
  19. package/src/components/panel/posts-list/list-items/list-item-rename.tsx +33 -0
  20. package/src/components/panel/posts-list/list-items/list-item-view.tsx +87 -0
  21. package/src/components/panel/posts-list/post-list-item.tsx +29 -0
  22. package/src/components/panel/posts-list/posts-collapsible-list.tsx +44 -0
  23. package/src/components/panel/shell.tsx +14 -13
  24. package/src/components/top-bar/__tests__/add-new-page.test.tsx +11 -12
  25. package/src/components/top-bar/__tests__/recently-edited.test.tsx +30 -30
  26. package/src/contexts/post-list-context.tsx +73 -0
  27. package/src/env.ts +2 -2
  28. package/src/hooks/__tests__/use-create-page.test.ts +6 -8
  29. package/src/hooks/__tests__/use-posts.test.ts +4 -6
  30. package/src/hooks/__tests__/use-recent-posts.test.ts +4 -4
  31. package/src/init.ts +1 -1
  32. package/src/components/panel/actions-menu/page-actions-menu.tsx +0 -29
  33. package/src/components/panel/add-new-page-button.tsx +0 -15
  34. package/src/components/panel/pages-actions/duplicate.tsx +0 -14
  35. package/src/components/panel/pages-actions/rename.tsx +0 -14
  36. package/src/components/panel/pages-actions/view.tsx +0 -14
  37. package/src/components/panel/pages-list/page-list-item.tsx +0 -66
  38. package/src/components/panel/pages-list/pages-collapsible-list.tsx +0 -37
package/dist/index.mjs CHANGED
@@ -232,23 +232,120 @@ function RecentlyEdited() {
232
232
  import { injectIntoPageIndication, toolsMenu } from "@elementor/editor-app-bar";
233
233
 
234
234
  // src/hooks/useToggleButtonProps.ts
235
- import { __ as __10 } from "@wordpress/i18n";
235
+ import { __ as __14 } from "@wordpress/i18n";
236
236
  import { PagesIcon } from "@elementor/icons";
237
237
 
238
238
  // src/components/panel/panel.ts
239
239
  import { createPanel } from "@elementor/editor-panels";
240
240
 
241
241
  // src/components/panel/shell.tsx
242
- import * as React19 from "react";
243
- import { Box as Box4, List as List2 } from "@elementor/ui";
242
+ import * as React24 from "react";
243
+ import { Box as Box5 } from "@elementor/ui";
244
244
  import { Panel, PanelBody, PanelHeader, PanelHeaderTitle } from "@elementor/editor-panels";
245
+ import { __ as __13 } from "@wordpress/i18n";
245
246
 
246
- // src/components/panel/pages-list/pages-collapsible-list.tsx
247
- import * as React17 from "react";
247
+ // src/components/panel/posts-list/posts-collapsible-list.tsx
248
+ import * as React22 from "react";
249
+ import { PageTypeIcon as PageTypeIcon2 } from "@elementor/icons";
250
+ import { Skeleton, Box as Box4, List as List2 } from "@elementor/ui";
251
+
252
+ // src/hooks/use-posts.ts
253
+ import { useQuery } from "@elementor/query";
248
254
 
249
- // src/components/panel/pages-list/collapsible-list.tsx
255
+ // src/api/post.ts
256
+ import apiFetch3 from "@wordpress/api-fetch";
257
+ import { __ as __3 } from "@wordpress/i18n";
258
+ var postTypesMap = {
259
+ page: {
260
+ labels: {
261
+ singular_name: __3("Page", "elementor"),
262
+ plural_name: __3("Pages", "elementor")
263
+ },
264
+ rest_base: "pages"
265
+ }
266
+ };
267
+ var getRequest = (postTypeSlug) => {
268
+ const baseUri = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
269
+ const keys = ["id", "type", "title", "link", "status"];
270
+ const queryParams = new URLSearchParams({
271
+ status: "any",
272
+ per_page: "-1",
273
+ order: "asc",
274
+ _fields: keys.join(",")
275
+ });
276
+ const uri = baseUri + "?" + queryParams.toString();
277
+ return apiFetch3({ path: uri });
278
+ };
279
+ var createRequest = (postTypeSlug, newPost) => {
280
+ const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
281
+ return apiFetch3({
282
+ path,
283
+ method: "POST",
284
+ data: newPost
285
+ });
286
+ };
287
+ var updateRequest = (postTypeSlug, updatedPost) => {
288
+ const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
289
+ const { id, ...data } = updatedPost;
290
+ return apiFetch3({
291
+ path: `${path}/${id}`,
292
+ method: "POST",
293
+ data
294
+ });
295
+ };
296
+ var deleteRequest = (postTypeSlug, postId) => {
297
+ const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`;
298
+ return apiFetch3({
299
+ path: `${path}/${postId}`,
300
+ method: "DELETE"
301
+ });
302
+ };
303
+
304
+ // src/hooks/use-posts.ts
305
+ var postsQueryKey = (postTypeSlug) => ["site-navigation", "posts", postTypeSlug];
306
+ function usePosts(postTypeSlug) {
307
+ return useQuery({
308
+ queryKey: postsQueryKey(postTypeSlug),
309
+ queryFn: () => getRequest(postTypeSlug)
310
+ });
311
+ }
312
+
313
+ // src/contexts/post-list-context.tsx
250
314
  import * as React6 from "react";
251
- import { useState as useState3 } from "react";
315
+ import { useState as useState3, useContext, createContext } from "react";
316
+ var defaultValues = {
317
+ type: "page",
318
+ editMode: { mode: "none", details: {} },
319
+ setEditMode: () => null,
320
+ resetEditMode: () => null
321
+ };
322
+ var PostListContext = createContext(defaultValues);
323
+ var PostListContextProvider = ({
324
+ type,
325
+ children
326
+ }) => {
327
+ const [editMode, setEditMode] = useState3(defaultValues.editMode);
328
+ const resetEditMode = () => {
329
+ setEditMode(defaultValues.editMode);
330
+ };
331
+ return /* @__PURE__ */ React6.createElement(PostListContext.Provider, { value: {
332
+ type,
333
+ editMode,
334
+ setEditMode,
335
+ resetEditMode
336
+ } }, children);
337
+ };
338
+ function usePostListContext() {
339
+ const context = useContext(PostListContext);
340
+ if (!context) {
341
+ throw new Error("The `usePostListContext()` hook must be used within an `<PostListContextProvider />`");
342
+ }
343
+ return context;
344
+ }
345
+
346
+ // src/components/panel/posts-list/collapsible-list.tsx
347
+ import * as React7 from "react";
348
+ import { useState as useState4 } from "react";
252
349
  import { Collapse, IconButton, List, ListItem, ListItemIcon as ListItemIcon2, ListItemText, styled } from "@elementor/ui";
253
350
  import { ChevronDownIcon as ChevronDownIcon2 } from "@elementor/icons";
254
351
  var RotateIcon = styled(ChevronDownIcon2, {
@@ -265,39 +362,213 @@ function CollapsibleList({
265
362
  isOpenByDefault = false,
266
363
  children
267
364
  }) {
268
- const [isOpen, setIsOpen] = useState3(isOpenByDefault);
269
- return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(ListItem, { disableGutters: true }, /* @__PURE__ */ React6.createElement(ListItemIcon2, null, /* @__PURE__ */ React6.createElement(
365
+ const [isOpen, setIsOpen] = useState4(isOpenByDefault);
366
+ return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(ListItem, { disableGutters: true }, /* @__PURE__ */ React7.createElement(ListItemIcon2, null, /* @__PURE__ */ React7.createElement(
270
367
  IconButton,
271
368
  {
272
369
  onClick: () => setIsOpen((prev) => !prev),
273
370
  sx: { color: "inherit" },
274
371
  size: "small"
275
372
  },
276
- /* @__PURE__ */ React6.createElement(RotateIcon, { fontSize: "small", isOpen })
277
- )), /* @__PURE__ */ React6.createElement(ListItemIcon2, null, /* @__PURE__ */ React6.createElement(Icon, null)), /* @__PURE__ */ React6.createElement(ListItemText, null, label)), /* @__PURE__ */ React6.createElement(
373
+ /* @__PURE__ */ React7.createElement(RotateIcon, { fontSize: "small", isOpen })
374
+ )), /* @__PURE__ */ React7.createElement(ListItemIcon2, null, /* @__PURE__ */ React7.createElement(Icon, null)), /* @__PURE__ */ React7.createElement(ListItemText, null, label)), /* @__PURE__ */ React7.createElement(
278
375
  Collapse,
279
376
  {
280
377
  in: isOpen,
281
378
  timeout: "auto",
282
379
  unmountOnExit: true
283
380
  },
284
- /* @__PURE__ */ React6.createElement(List, { dense: true }, children)
381
+ /* @__PURE__ */ React7.createElement(List, { dense: true }, children)
285
382
  ));
286
383
  }
287
384
 
288
- // src/components/panel/pages-list/pages-collapsible-list.tsx
289
- import { PageTypeIcon as PageTypeIcon2 } from "@elementor/icons";
290
- import { Skeleton, Box as Box3 } from "@elementor/ui";
385
+ // src/components/panel/posts-list/post-list-item.tsx
386
+ import * as React21 from "react";
291
387
 
292
- // src/components/panel/pages-list/page-list-item.tsx
293
- import * as React16 from "react";
388
+ // src/components/panel/posts-list/list-items/list-item-rename.tsx
389
+ import * as React9 from "react";
390
+
391
+ // src/hooks/use-posts-actions.ts
392
+ import { useQueryClient, useMutation } from "@elementor/query";
393
+ function usePostActions(postTypeSlug) {
394
+ const invalidatePosts = useInvalidatePosts(postTypeSlug);
395
+ const onSuccess = () => invalidatePosts({ exact: true });
396
+ const createPost = useMutation(
397
+ (newPost) => createRequest(postTypeSlug, newPost),
398
+ { onSuccess }
399
+ );
400
+ const updatePost = useMutation(
401
+ (updatedPost) => updateRequest(postTypeSlug, updatedPost),
402
+ { onSuccess }
403
+ );
404
+ const deletePost = useMutation(
405
+ (postId) => deleteRequest(postTypeSlug, postId),
406
+ { onSuccess }
407
+ );
408
+ return {
409
+ createPost,
410
+ updatePost,
411
+ deletePost
412
+ };
413
+ }
414
+ function useInvalidatePosts(postTypeSlug) {
415
+ const queryClient = useQueryClient();
416
+ return (options = {}) => {
417
+ const queryKey = postsQueryKey(postTypeSlug);
418
+ return queryClient.invalidateQueries(queryKey, options);
419
+ };
420
+ }
421
+
422
+ // src/components/panel/posts-list/list-items/edit-mode-template.tsx
423
+ import * as React8 from "react";
424
+ import { useState as useState5, useRef } from "react";
425
+ import {
426
+ Box as Box2,
427
+ ListItem as ListItem2,
428
+ ListItemIcon as ListItemIcon3,
429
+ TextField,
430
+ IconButton as IconButton2,
431
+ CircularProgress as CircularProgress2
432
+ } from "@elementor/ui";
433
+ import { XIcon } from "@elementor/icons";
434
+ import { __ as __4 } from "@wordpress/i18n";
435
+ function EditModeTemplate({ postTitle, isLoading, callback }) {
436
+ const inputRef = useRef();
437
+ const [inputError, setInputError] = useState5("");
438
+ const closeButton = useRef();
439
+ const onBlur = (e) => {
440
+ if (closeButton.current === e.relatedTarget) {
441
+ return;
442
+ }
443
+ runCallback();
444
+ };
445
+ const onFormSubmit = (e) => {
446
+ e.preventDefault();
447
+ runCallback();
448
+ };
449
+ const validateInput = () => {
450
+ let isValid = true;
451
+ if (inputRef.current?.value === "") {
452
+ isValid = false;
453
+ setInputError(__4("Name is required", "elementor"));
454
+ }
455
+ return isValid;
456
+ };
457
+ const runCallback = () => {
458
+ if (!validateInput()) {
459
+ return;
460
+ }
461
+ callback(inputRef.current?.value || "");
462
+ };
463
+ return /* @__PURE__ */ React8.createElement(
464
+ ListItem2,
465
+ {
466
+ selected: true,
467
+ disablePadding: true,
468
+ secondaryAction: /* @__PURE__ */ React8.createElement(CloseButton, { isLoading, closeButton })
469
+ },
470
+ /* @__PURE__ */ React8.createElement(ListItemIcon3, null),
471
+ /* @__PURE__ */ React8.createElement(Box2, { component: "form", onSubmit: onFormSubmit }, /* @__PURE__ */ React8.createElement(
472
+ TextField,
473
+ {
474
+ autoFocus: true,
475
+ ref: inputRef,
476
+ defaultValue: postTitle,
477
+ disabled: isLoading,
478
+ error: !!inputError,
479
+ onBlur,
480
+ variant: "outlined",
481
+ size: "small"
482
+ }
483
+ ))
484
+ );
485
+ }
486
+ function CloseButton({ isLoading, closeButton }) {
487
+ const { resetEditMode } = usePostListContext();
488
+ return /* @__PURE__ */ React8.createElement(
489
+ IconButton2,
490
+ {
491
+ size: "small",
492
+ onClick: resetEditMode,
493
+ ref: closeButton,
494
+ disabled: isLoading
495
+ },
496
+ isLoading ? /* @__PURE__ */ React8.createElement(CircularProgress2, null) : /* @__PURE__ */ React8.createElement(XIcon, { fontSize: "small" })
497
+ );
498
+ }
499
+
500
+ // src/components/panel/posts-list/list-items/list-item-rename.tsx
501
+ function ListItemRename({ post }) {
502
+ const { type, resetEditMode } = usePostListContext();
503
+ const { updatePost } = usePostActions(type);
504
+ const renamePostCallback = (inputValue) => {
505
+ if (inputValue === post.title.rendered) {
506
+ resetEditMode();
507
+ }
508
+ updatePost.mutateAsync({
509
+ id: post.id,
510
+ title: inputValue
511
+ }, {
512
+ onSuccess: () => {
513
+ resetEditMode();
514
+ }
515
+ });
516
+ };
517
+ return /* @__PURE__ */ React9.createElement(EditModeTemplate, { postTitle: post.title.rendered, isLoading: updatePost.isLoading, callback: renamePostCallback });
518
+ }
519
+
520
+ // src/components/panel/posts-list/list-items/list-item-create.tsx
521
+ import * as React10 from "react";
522
+ import { __ as __5 } from "@wordpress/i18n";
523
+ function ListItemCreate() {
524
+ const { type, resetEditMode } = usePostListContext();
525
+ const { createPost } = usePostActions(type);
526
+ const createPostCallback = (inputValue) => {
527
+ createPost.mutateAsync({
528
+ title: inputValue,
529
+ status: "draft"
530
+ }, {
531
+ onSuccess: () => {
532
+ resetEditMode();
533
+ }
534
+ });
535
+ };
536
+ return /* @__PURE__ */ React10.createElement(EditModeTemplate, { postTitle: __5("New Page", "elementor"), isLoading: createPost.isLoading, callback: createPostCallback });
537
+ }
538
+
539
+ // src/components/panel/posts-list/list-items/list-item-duplicate.tsx
540
+ import * as React11 from "react";
541
+ import { __ as __6 } from "@wordpress/i18n";
542
+ function ListItemDuplicate() {
543
+ const { type, editMode, resetEditMode } = usePostListContext();
544
+ const { createPost } = usePostActions(type);
545
+ if ("duplicate" !== editMode.mode) {
546
+ return null;
547
+ }
548
+ const duplicatePostCallback = (inputValue) => {
549
+ createPost.mutateAsync({
550
+ title: inputValue,
551
+ status: "draft"
552
+ }, {
553
+ onSuccess: () => {
554
+ resetEditMode();
555
+ }
556
+ });
557
+ };
558
+ return /* @__PURE__ */ React11.createElement(EditModeTemplate, { postTitle: `${editMode.details.title} ${__6("copy", "elementor")}`, isLoading: createPost.isLoading, callback: duplicatePostCallback });
559
+ }
560
+
561
+ // src/components/panel/posts-list/list-items/list-item-view.tsx
562
+ import * as React20 from "react";
294
563
  import {
295
564
  bindMenu as bindMenu2,
296
565
  bindTrigger as bindTrigger2,
297
- ListItem as ListItem2,
566
+ Divider as Divider2,
567
+ ListItem as ListItem3,
298
568
  ListItemButton as ListItemButton2,
299
- ListItemIcon as ListItemIcon4,
569
+ ListItemIcon as ListItemIcon5,
300
570
  ListItemText as ListItemText3,
571
+ Menu as Menu2,
301
572
  ToggleButton,
302
573
  usePopupState as usePopupState2
303
574
  } from "@elementor/ui";
@@ -305,13 +576,13 @@ import { DotsVerticalIcon, HomeIcon as HomeIcon2 } from "@elementor/icons";
305
576
  import { useActiveDocument as useActiveDocument3, useNavigateToDocument as useNavigateToDocument3 } from "@elementor/editor-documents";
306
577
 
307
578
  // src/components/shared/page-title-and-status.tsx
308
- import * as React7 from "react";
309
- import { Box as Box2, Typography as Typography3 } from "@elementor/ui";
579
+ import * as React12 from "react";
580
+ import { Box as Box3, Typography as Typography3 } from "@elementor/ui";
310
581
  var PageStatus = ({ status }) => {
311
582
  if ("publish" === status) {
312
583
  return null;
313
584
  }
314
- return /* @__PURE__ */ React7.createElement(
585
+ return /* @__PURE__ */ React12.createElement(
315
586
  Typography3,
316
587
  {
317
588
  component: "span",
@@ -330,7 +601,7 @@ var PageStatus = ({ status }) => {
330
601
  };
331
602
  var PageTitle = ({ title }) => {
332
603
  const modifiedTitle = useReverseHtmlEntities(title);
333
- return /* @__PURE__ */ React7.createElement(
604
+ return /* @__PURE__ */ React12.createElement(
334
605
  Typography3,
335
606
  {
336
607
  component: "span",
@@ -344,260 +615,269 @@ var PageTitle = ({ title }) => {
344
615
  );
345
616
  };
346
617
  function PageTitleAndStatus({ page }) {
347
- return /* @__PURE__ */ React7.createElement(Box2, { display: "flex" }, /* @__PURE__ */ React7.createElement(PageTitle, { title: page.title.rendered }), "\xA0", /* @__PURE__ */ React7.createElement(PageStatus, { status: page.status }));
618
+ return /* @__PURE__ */ React12.createElement(Box3, { display: "flex" }, /* @__PURE__ */ React12.createElement(PageTitle, { title: page.title.rendered }), "\xA0", /* @__PURE__ */ React12.createElement(PageStatus, { status: page.status }));
348
619
  }
349
620
 
350
- // src/components/panel/actions-menu/page-actions-menu.tsx
621
+ // src/components/panel/actions-menu/actions/rename.tsx
351
622
  import * as React15 from "react";
352
- import { Divider as Divider2, Menu as Menu2 } from "@elementor/ui";
353
-
354
- // src/components/panel/pages-actions/rename.tsx
355
- import * as React10 from "react";
356
623
  import { EraseIcon } from "@elementor/icons";
357
- import { __ as __3 } from "@wordpress/i18n";
624
+ import { __ as __7 } from "@wordpress/i18n";
358
625
 
359
626
  // src/components/panel/actions-menu/action-menu-item.tsx
360
- import * as React9 from "react";
627
+ import * as React14 from "react";
361
628
 
362
629
  // src/components/panel/actions-menu/action-list-item.tsx
363
- import * as React8 from "react";
364
- import { ListItemButton, ListItemIcon as ListItemIcon3, ListItemText as ListItemText2 } from "@elementor/ui";
630
+ import * as React13 from "react";
631
+ import { ListItemButton, ListItemIcon as ListItemIcon4, ListItemText as ListItemText2 } from "@elementor/ui";
365
632
  function ActionListItem({ title, icon: Icon, disabled, onClick }) {
366
- return /* @__PURE__ */ React8.createElement(
633
+ return /* @__PURE__ */ React13.createElement(
367
634
  ListItemButton,
368
635
  {
369
636
  disabled,
370
637
  onClick
371
638
  },
372
- /* @__PURE__ */ React8.createElement(ListItemIcon3, null, /* @__PURE__ */ React8.createElement(Icon, null)),
373
- /* @__PURE__ */ React8.createElement(ListItemText2, null, title)
639
+ /* @__PURE__ */ React13.createElement(ListItemIcon4, null, /* @__PURE__ */ React13.createElement(Icon, null)),
640
+ /* @__PURE__ */ React13.createElement(ListItemText2, null, title)
374
641
  );
375
642
  }
376
643
 
377
644
  // src/components/panel/actions-menu/action-menu-item.tsx
378
645
  import { MenuItem as MenuItem3 } from "@elementor/ui";
379
646
  function ActionMenuItem(props) {
380
- return /* @__PURE__ */ React9.createElement(MenuItem3, { disableGutters: true }, /* @__PURE__ */ React9.createElement(ActionListItem, { ...props }));
647
+ return /* @__PURE__ */ React14.createElement(MenuItem3, { disableGutters: true }, /* @__PURE__ */ React14.createElement(ActionListItem, { ...props }));
381
648
  }
382
649
 
383
- // src/components/panel/pages-actions/rename.tsx
384
- function Rename() {
385
- return /* @__PURE__ */ React10.createElement(
650
+ // src/components/panel/actions-menu/actions/rename.tsx
651
+ function Rename({ post }) {
652
+ const { setEditMode } = usePostListContext();
653
+ return /* @__PURE__ */ React15.createElement(
386
654
  ActionMenuItem,
387
655
  {
388
- title: __3("Rename", "elementor"),
656
+ title: __7("Rename", "elementor"),
389
657
  icon: EraseIcon,
390
- onClick: () => null
658
+ onClick: () => {
659
+ setEditMode({
660
+ mode: "rename",
661
+ details: {
662
+ postId: post.id
663
+ }
664
+ });
665
+ }
391
666
  }
392
667
  );
393
668
  }
394
669
 
395
- // src/components/panel/pages-actions/duplicate.tsx
396
- import * as React11 from "react";
397
- import { __ as __4 } from "@wordpress/i18n";
670
+ // src/components/panel/actions-menu/actions/duplicate.tsx
671
+ import * as React16 from "react";
398
672
  import { CopyIcon } from "@elementor/icons";
399
- function Duplicate() {
400
- return /* @__PURE__ */ React11.createElement(
673
+ import { __ as __8 } from "@wordpress/i18n";
674
+ function Duplicate({ post, popupState }) {
675
+ const { setEditMode } = usePostListContext();
676
+ return /* @__PURE__ */ React16.createElement(
401
677
  ActionMenuItem,
402
678
  {
403
- title: __4("Duplicate", "elementor"),
679
+ title: __8("Duplicate", "elementor"),
404
680
  icon: CopyIcon,
405
- onClick: () => null
681
+ onClick: () => {
682
+ popupState.close();
683
+ setEditMode({
684
+ mode: "duplicate",
685
+ details: {
686
+ postId: post.id,
687
+ title: post.title.rendered
688
+ }
689
+ });
690
+ }
406
691
  }
407
692
  );
408
693
  }
409
694
 
410
- // src/components/panel/pages-actions/delete.tsx
411
- import * as React12 from "react";
695
+ // src/components/panel/actions-menu/actions/delete.tsx
696
+ import * as React17 from "react";
412
697
  import { TrashIcon } from "@elementor/icons";
413
698
  import { useActiveDocument as useActiveDocument2 } from "@elementor/editor-documents";
414
- import { __ as __5 } from "@wordpress/i18n";
415
- function Delete({ page }) {
699
+ import { __ as __9 } from "@wordpress/i18n";
700
+ function Delete({ post }) {
416
701
  const activeDocument = useActiveDocument2();
417
- const isActive = activeDocument?.id === page.id;
418
- return /* @__PURE__ */ React12.createElement(
702
+ const isActive = activeDocument?.id === post.id;
703
+ return /* @__PURE__ */ React17.createElement(
419
704
  ActionMenuItem,
420
705
  {
421
- title: __5("Delete", "elementor"),
706
+ title: __9("Delete", "elementor"),
422
707
  icon: TrashIcon,
423
- disabled: page.isHome || isActive,
708
+ disabled: post.isHome || isActive,
424
709
  onClick: () => null
425
710
  }
426
711
  );
427
712
  }
428
713
 
429
- // src/components/panel/pages-actions/view.tsx
430
- import * as React13 from "react";
714
+ // src/components/panel/actions-menu/actions/view.tsx
715
+ import * as React18 from "react";
431
716
  import { EyeIcon } from "@elementor/icons";
432
- import { __ as __6 } from "@wordpress/i18n";
433
- function View() {
434
- return /* @__PURE__ */ React13.createElement(
717
+ import { __ as __10 } from "@wordpress/i18n";
718
+ function View({ post }) {
719
+ const { type } = usePostListContext();
720
+ const title = __10("View %s", "elementor").replace("%s", postTypesMap[type].labels.singular_name);
721
+ return /* @__PURE__ */ React18.createElement(
435
722
  ActionMenuItem,
436
723
  {
437
- title: __6("View Page", "elementor"),
724
+ title,
438
725
  icon: EyeIcon,
439
- onClick: () => null
726
+ onClick: () => {
727
+ console.log(post);
728
+ }
440
729
  }
441
730
  );
442
731
  }
443
732
 
444
- // src/components/panel/pages-actions/set-home.tsx
445
- import * as React14 from "react";
733
+ // src/components/panel/actions-menu/actions/set-home.tsx
734
+ import * as React19 from "react";
446
735
  import { HomeIcon } from "@elementor/icons";
447
- import { __ as __7 } from "@wordpress/i18n";
448
- function SetHome({ page }) {
449
- return /* @__PURE__ */ React14.createElement(
736
+ import { __ as __11 } from "@wordpress/i18n";
737
+ function SetHome({ post }) {
738
+ return /* @__PURE__ */ React19.createElement(
450
739
  ActionMenuItem,
451
740
  {
452
- title: __7("Set as homepage", "elementor"),
741
+ title: __11("Set as homepage", "elementor"),
453
742
  icon: HomeIcon,
454
- disabled: !!page.isHome,
743
+ disabled: !!post.isHome,
455
744
  onClick: () => null
456
745
  }
457
746
  );
458
747
  }
459
748
 
460
- // src/components/panel/actions-menu/page-actions-menu.tsx
461
- function PageActionsMenu({ page, ...props }) {
462
- return /* @__PURE__ */ React15.createElement(
463
- Menu2,
464
- {
465
- PaperProps: { sx: { mt: 4, width: 200 } },
466
- MenuListProps: { dense: true },
467
- ...props
468
- },
469
- /* @__PURE__ */ React15.createElement(Rename, null),
470
- /* @__PURE__ */ React15.createElement(Duplicate, null),
471
- /* @__PURE__ */ React15.createElement(Delete, { page }),
472
- /* @__PURE__ */ React15.createElement(View, null),
473
- /* @__PURE__ */ React15.createElement(Divider2, null),
474
- /* @__PURE__ */ React15.createElement(SetHome, { page })
475
- );
476
- }
477
-
478
- // src/components/panel/pages-list/page-list-item.tsx
479
- function PageListItem({ page }) {
749
+ // src/components/panel/posts-list/list-items/list-item-view.tsx
750
+ function ListItemView({ post }) {
751
+ const activeDocument = useActiveDocument3();
752
+ const navigateToDocument = useNavigateToDocument3();
480
753
  const popupState = usePopupState2({
481
754
  variant: "popover",
482
- popupId: "page-actions"
755
+ popupId: "post-actions",
756
+ disableAutoFocus: true
483
757
  });
484
- const activeDocument = useActiveDocument3();
485
- const navigateToDocument = useNavigateToDocument3();
486
- const isActive = activeDocument?.id === page.id;
487
- return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(
488
- ListItem2,
758
+ const isActive = activeDocument?.id === post.id;
759
+ return /* @__PURE__ */ React20.createElement(React20.Fragment, null, /* @__PURE__ */ React20.createElement(
760
+ ListItem3,
489
761
  {
490
762
  disablePadding: true,
491
- secondaryAction: /* @__PURE__ */ React16.createElement(
763
+ secondaryAction: /* @__PURE__ */ React20.createElement(
492
764
  ToggleButton,
493
765
  {
494
766
  value: true,
495
- color: "secondary",
496
767
  size: "small",
497
768
  selected: popupState.isOpen,
498
769
  ...bindTrigger2(popupState)
499
770
  },
500
- /* @__PURE__ */ React16.createElement(DotsVerticalIcon, { fontSize: "small" })
771
+ /* @__PURE__ */ React20.createElement(DotsVerticalIcon, { fontSize: "small" })
501
772
  )
502
773
  },
503
- /* @__PURE__ */ React16.createElement(
774
+ /* @__PURE__ */ React20.createElement(
504
775
  ListItemButton2,
505
776
  {
506
777
  selected: isActive,
507
- onClick: () => navigateToDocument(page.id),
778
+ onClick: () => {
779
+ if (!isActive) {
780
+ navigateToDocument(post.id);
781
+ }
782
+ },
508
783
  dense: true
509
784
  },
510
- /* @__PURE__ */ React16.createElement(ListItemIcon4, null),
511
- /* @__PURE__ */ React16.createElement(
785
+ /* @__PURE__ */ React20.createElement(ListItemIcon5, null),
786
+ /* @__PURE__ */ React20.createElement(
512
787
  ListItemText3,
513
788
  {
514
789
  disableTypography: true
515
790
  },
516
- /* @__PURE__ */ React16.createElement(PageTitleAndStatus, { page })
791
+ /* @__PURE__ */ React20.createElement(PageTitleAndStatus, { page: post })
517
792
  ),
518
- page.isHome && /* @__PURE__ */ React16.createElement(ListItemIcon4, null, /* @__PURE__ */ React16.createElement(HomeIcon2, { color: "disabled" }))
793
+ post.isHome && /* @__PURE__ */ React20.createElement(ListItemIcon5, null, /* @__PURE__ */ React20.createElement(HomeIcon2, { color: "disabled" }))
519
794
  )
520
- ), /* @__PURE__ */ React16.createElement(PageActionsMenu, { page, ...bindMenu2(popupState) }));
795
+ ), /* @__PURE__ */ React20.createElement(
796
+ Menu2,
797
+ {
798
+ PaperProps: { sx: { mt: 4, width: 200 } },
799
+ MenuListProps: { dense: true },
800
+ ...bindMenu2(popupState)
801
+ },
802
+ /* @__PURE__ */ React20.createElement(Rename, { post }),
803
+ /* @__PURE__ */ React20.createElement(Duplicate, { post, popupState }),
804
+ /* @__PURE__ */ React20.createElement(Delete, { post }),
805
+ /* @__PURE__ */ React20.createElement(View, { post }),
806
+ /* @__PURE__ */ React20.createElement(Divider2, null),
807
+ /* @__PURE__ */ React20.createElement(SetHome, { post })
808
+ ));
521
809
  }
522
810
 
523
- // src/hooks/use-posts.ts
524
- import { useQuery } from "@elementor/query";
525
-
526
- // src/api/post.ts
527
- import apiFetch3 from "@wordpress/api-fetch";
528
- var postTypesMap = {
529
- page: "pages"
530
- };
531
- var getRequest = (postTypeSlug) => {
532
- const baseUri = `/wp/v2/${postTypesMap[postTypeSlug]}`;
533
- const keys = ["id", "type", "title", "link", "status"];
534
- const queryParams = new URLSearchParams({
535
- status: "any",
536
- per_page: "-1",
537
- _fields: keys.join(",")
538
- });
539
- const uri = baseUri + "?" + queryParams.toString();
540
- return apiFetch3({ path: uri });
541
- };
542
-
543
- // src/hooks/use-posts.ts
544
- var postsQueryKey = (postTypeSlug) => ["site-navigation", "posts", postTypeSlug];
545
- function usePosts(postTypeSlug) {
546
- return useQuery({
547
- queryKey: postsQueryKey(postTypeSlug),
548
- queryFn: () => getRequest(postTypeSlug)
549
- });
811
+ // src/components/panel/posts-list/post-list-item.tsx
812
+ function PostListItem2({ post }) {
813
+ const { editMode } = usePostListContext();
814
+ if ("rename" === editMode.mode && post?.id && post?.id === editMode.details.postId) {
815
+ return /* @__PURE__ */ React21.createElement(ListItemRename, { post });
816
+ }
817
+ if ("create" === editMode.mode && !post) {
818
+ return /* @__PURE__ */ React21.createElement(ListItemCreate, null);
819
+ }
820
+ if ("duplicate" === editMode.mode && !post) {
821
+ return /* @__PURE__ */ React21.createElement(ListItemDuplicate, null);
822
+ }
823
+ if (!post) {
824
+ return null;
825
+ }
826
+ return /* @__PURE__ */ React21.createElement(ListItemView, { post });
550
827
  }
551
828
 
552
- // src/components/panel/pages-list/pages-collapsible-list.tsx
553
- import { __ as __8 } from "@wordpress/i18n";
554
- function PagesCollapsibleList({ isOpenByDefault = false }) {
555
- const { data: pages, isLoading: pagesLoading } = usePosts("page");
556
- if (!pages || pagesLoading) {
557
- return /* @__PURE__ */ React17.createElement(Box3, { spacing: 4, sx: { px: 6 } }, /* @__PURE__ */ React17.createElement(Skeleton, { variant: "text", sx: { fontSize: "2rem" } }), /* @__PURE__ */ React17.createElement(Skeleton, { variant: "rounded", width: "100%", height: "48" }));
829
+ // src/components/panel/posts-list/posts-collapsible-list.tsx
830
+ function PostsCollapsibleList({ isOpenByDefault = false }) {
831
+ const { type, editMode } = usePostListContext();
832
+ const { data: posts, isLoading: postsLoading } = usePosts(type);
833
+ if (!posts || postsLoading) {
834
+ return /* @__PURE__ */ React22.createElement(Box4, { spacing: 4, sx: { px: 6 } }, /* @__PURE__ */ React22.createElement(Skeleton, { variant: "text", sx: { fontSize: "2rem" } }), /* @__PURE__ */ React22.createElement(Skeleton, { variant: "rounded", width: "100%", height: "48" }));
558
835
  }
559
- const label = __8("Pages (%s)", "elementor").replace("%s", pages.length.toString());
560
- return /* @__PURE__ */ React17.createElement(
836
+ const label = `${postTypesMap[type].labels.plural_name} (${posts.length.toString()})`;
837
+ return /* @__PURE__ */ React22.createElement(List2, { dense: true }, /* @__PURE__ */ React22.createElement(
561
838
  CollapsibleList,
562
839
  {
563
840
  label,
564
841
  Icon: PageTypeIcon2,
565
- isOpenByDefault
842
+ isOpenByDefault: isOpenByDefault || false
566
843
  },
567
- pages.map((page) => /* @__PURE__ */ React17.createElement(PageListItem, { key: page.id, page }))
568
- );
844
+ posts.map((post) => /* @__PURE__ */ React22.createElement(PostListItem2, { key: post.id, post })),
845
+ ["duplicate", "create"].includes(editMode.mode) && /* @__PURE__ */ React22.createElement(PostListItem2, null)
846
+ ));
569
847
  }
570
848
 
571
- // src/components/panel/shell.tsx
572
- import { __ as __9 } from "@wordpress/i18n";
573
-
574
- // src/components/panel/add-new-page-button.tsx
849
+ // src/components/panel/add-new-button.tsx
850
+ import * as React23 from "react";
575
851
  import { Button as Button2 } from "@elementor/ui";
576
852
  import { PlusIcon as PlusIcon2 } from "@elementor/icons";
577
- import * as React18 from "react";
578
- function AddNewPageButton() {
579
- return /* @__PURE__ */ React18.createElement(
853
+ import { __ as __12 } from "@wordpress/i18n";
854
+ function AddNewButton() {
855
+ const { setEditMode } = usePostListContext();
856
+ return /* @__PURE__ */ React23.createElement(
580
857
  Button2,
581
858
  {
859
+ size: "small",
582
860
  sx: { mt: 4, mb: 4, mr: 5 },
583
- startIcon: /* @__PURE__ */ React18.createElement(PlusIcon2, null),
584
- onClick: () => null
861
+ startIcon: /* @__PURE__ */ React23.createElement(PlusIcon2, null),
862
+ onClick: () => {
863
+ setEditMode({ mode: "create", details: {} });
864
+ }
585
865
  },
586
- "Add New"
866
+ __12("Add New", "elementor")
587
867
  );
588
868
  }
589
869
 
590
870
  // src/components/panel/shell.tsx
591
871
  var Shell = () => {
592
- return /* @__PURE__ */ React19.createElement(Panel, null, /* @__PURE__ */ React19.createElement(PanelHeader, null, /* @__PURE__ */ React19.createElement(PanelHeaderTitle, null, __9("Pages", "elementor"))), /* @__PURE__ */ React19.createElement(PanelBody, null, /* @__PURE__ */ React19.createElement(
593
- Box4,
872
+ return /* @__PURE__ */ React24.createElement(Panel, null, /* @__PURE__ */ React24.createElement(PanelHeader, null, /* @__PURE__ */ React24.createElement(PanelHeaderTitle, null, __13("Pages", "elementor"))), /* @__PURE__ */ React24.createElement(PanelBody, null, /* @__PURE__ */ React24.createElement(PostListContextProvider, { type: "page" }, /* @__PURE__ */ React24.createElement(
873
+ Box5,
594
874
  {
595
875
  display: "flex",
596
876
  justifyContent: "flex-end",
597
877
  alignItems: "center"
598
878
  },
599
- /* @__PURE__ */ React19.createElement(AddNewPageButton, null)
600
- ), /* @__PURE__ */ React19.createElement(List2, { dense: true }, /* @__PURE__ */ React19.createElement(PagesCollapsibleList, { isOpenByDefault: true }))));
879
+ /* @__PURE__ */ React24.createElement(AddNewButton, null)
880
+ ), /* @__PURE__ */ React24.createElement(PostsCollapsibleList, { isOpenByDefault: true }))));
601
881
  };
602
882
  var shell_default = Shell;
603
883
 
@@ -616,7 +896,7 @@ function useToggleButtonProps() {
616
896
  const { isOpen, isBlocked } = usePanelStatus();
617
897
  const { open, close } = usePanelActions();
618
898
  return {
619
- title: __10("Pages", "elementor"),
899
+ title: __14("Pages", "elementor"),
620
900
  icon: PagesIcon,
621
901
  onClick: () => isOpen ? close() : open(),
622
902
  selected: isOpen,
@@ -636,7 +916,7 @@ var { env, validateEnv } = parseEnv("@elementor/editor-site-navigation", (envDat
636
916
  // src/init.ts
637
917
  function init() {
638
918
  registerTopBarMenuItems();
639
- if (env.is_panel_active) {
919
+ if (env.is_pages_panel_active) {
640
920
  registerPanel(panel);
641
921
  registerButton();
642
922
  }