@elementor/editor-site-navigation 0.6.2 → 0.8.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.8.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.7.0...@elementor/editor-site-navigation@0.8.0) (2023-06-25)
7
+
8
+
9
+ ### Features
10
+
11
+ * **site-navigation:** pages navigation panel UI [ED-10871] ([#51](https://github.com/elementor/elementor-packages/issues/51)) ([594427c](https://github.com/elementor/elementor-packages/commit/594427c3c296fe664577319bba29bf711f6bbdde))
12
+
13
+
14
+
15
+
16
+
17
+ # [0.7.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.6.2...@elementor/editor-site-navigation@0.7.0) (2023-06-25)
18
+
19
+
20
+ ### Features
21
+
22
+ * **api:** add PostsData class for managing post data and API interactions [ED-11021] ([#57](https://github.com/elementor/elementor-packages/issues/57)) ([a7b93ac](https://github.com/elementor/elementor-packages/commit/a7b93acfc00076f9452cf86f04670412c42b5773))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.6.2](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.6.1...@elementor/editor-site-navigation@0.6.2) (2023-06-13)
7
29
 
8
30
  **Note:** Version bump only for package @elementor/editor-site-navigation
package/README.md CHANGED
@@ -3,3 +3,51 @@
3
3
  > **Warning**
4
4
  >
5
5
  > This package is under development and not ready for production use.
6
+
7
+ ## Code examples
8
+
9
+ **Get all pages and create a new one:**
10
+
11
+ ```
12
+ import * as React from 'react';
13
+ import { useEffect } from 'react';
14
+ import { usePosts } from './use-posts';
15
+
16
+ const PageList = () => {
17
+ const { getPosts: getPages, createPost: createPage, isLoading, posts } = usePosts( 'page' );
18
+
19
+ useEffect( () => {
20
+ getPages();
21
+ }, [ getPages ] );
22
+
23
+ const createNewPage = () => {
24
+ const newPage = {
25
+ title: 'New Page',
26
+ content: 'This is a demo page',
27
+ status: 'publish',
28
+ };
29
+
30
+ createPage( newPage );
31
+ };
32
+
33
+ if ( isLoading ) {
34
+ return <div>Loading...</div>;
35
+ }
36
+
37
+ return (
38
+ <div>
39
+ <h1>Pages</h1>
40
+ <button onClick={ createNewPage }>Create New Page</button>
41
+ <ul>
42
+ {
43
+ posts.map( ( page ) => (
44
+ <li key={ page.id }>{ page.title }</li>
45
+ ) )
46
+ }
47
+ </ul>
48
+ </div>
49
+ );
50
+ };
51
+
52
+ export default PageList;
53
+ ```
package/dist/index.js CHANGED
@@ -248,8 +248,340 @@ function RecentlyEdited() {
248
248
 
249
249
  // src/init.ts
250
250
  var import_editor_app_bar = require("@elementor/editor-app-bar");
251
+ var import_editor = require("@elementor/editor");
252
+
253
+ // src/components/panel/shell.tsx
254
+ var React18 = __toESM(require("react"));
255
+ var import_ui12 = require("@elementor/ui");
256
+ var import_icons13 = require("@elementor/icons");
257
+
258
+ // src/components/panel/pages-list/pages-collapsible-list.tsx
259
+ var React17 = __toESM(require("react"));
260
+
261
+ // src/components/panel/pages-list/collapsible-list.tsx
262
+ var React6 = __toESM(require("react"));
263
+ var import_react4 = require("react");
264
+ var import_ui6 = require("@elementor/ui");
265
+ var import_icons5 = require("@elementor/icons");
266
+ var RotateIcon = (0, import_ui6.styled)(import_icons5.ChevronDownIcon, {
267
+ shouldForwardProp: (prop) => prop !== "isOpen"
268
+ })(({ theme, isOpen }) => ({
269
+ transform: isOpen ? "rotate(0deg)" : "rotate(-90deg)",
270
+ transition: theme.transitions.create("transform", {
271
+ duration: theme.transitions.duration.standard
272
+ })
273
+ }));
274
+ function CollapsibleList({
275
+ label,
276
+ Icon,
277
+ isOpenByDefault = false,
278
+ children
279
+ }) {
280
+ const [isOpen, setIsOpen] = (0, import_react4.useState)(isOpenByDefault);
281
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(import_ui6.ListItem, { disableGutters: true }, /* @__PURE__ */ React6.createElement(import_ui6.ListItemIcon, null, /* @__PURE__ */ React6.createElement(
282
+ import_ui6.IconButton,
283
+ {
284
+ onClick: () => setIsOpen((prev) => !prev),
285
+ sx: { color: "inherit" },
286
+ size: "small"
287
+ },
288
+ /* @__PURE__ */ React6.createElement(RotateIcon, { fontSize: "small", isOpen })
289
+ )), /* @__PURE__ */ React6.createElement(import_ui6.ListItemIcon, null, /* @__PURE__ */ React6.createElement(Icon, null)), /* @__PURE__ */ React6.createElement(import_ui6.ListItemText, null, label)), /* @__PURE__ */ React6.createElement(
290
+ import_ui6.Collapse,
291
+ {
292
+ in: isOpen,
293
+ timeout: "auto",
294
+ unmountOnExit: true
295
+ },
296
+ /* @__PURE__ */ React6.createElement(import_ui6.List, { dense: true }, children)
297
+ ));
298
+ }
299
+
300
+ // src/components/panel/pages-list/pages-collapsible-list.tsx
301
+ var import_icons12 = require("@elementor/icons");
302
+
303
+ // src/components/panel/pages-list/page-list-item.tsx
304
+ var React16 = __toESM(require("react"));
305
+ var import_ui11 = require("@elementor/ui");
306
+ var import_icons11 = require("@elementor/icons");
307
+ var import_editor_documents5 = require("@elementor/editor-documents");
308
+
309
+ // src/components/shared/page-title-and-status.tsx
310
+ var React7 = __toESM(require("react"));
311
+ var import_ui7 = require("@elementor/ui");
312
+ var PageStatus = ({ status }) => {
313
+ if ("publish" === status) {
314
+ return null;
315
+ }
316
+ return /* @__PURE__ */ React7.createElement(
317
+ import_ui7.Typography,
318
+ {
319
+ component: "span",
320
+ variant: "body1",
321
+ sx: {
322
+ textTransform: "capitalize",
323
+ fontStyle: "italic",
324
+ whiteSpace: "nowrap",
325
+ flexBasis: "content"
326
+ }
327
+ },
328
+ "(",
329
+ status,
330
+ ")"
331
+ );
332
+ };
333
+ var PageTitle = ({ title }) => {
334
+ const modifiedTitle = useReverseHtmlEntities(title);
335
+ return /* @__PURE__ */ React7.createElement(
336
+ import_ui7.Typography,
337
+ {
338
+ component: "span",
339
+ variant: "body1",
340
+ noWrap: true,
341
+ sx: {
342
+ flexBasis: "auto"
343
+ }
344
+ },
345
+ modifiedTitle
346
+ );
347
+ };
348
+ function PageTitleAndStatus({ page }) {
349
+ return /* @__PURE__ */ React7.createElement(import_ui7.Box, { display: "flex" }, /* @__PURE__ */ React7.createElement(PageTitle, { title: page.title }), "\xA0", /* @__PURE__ */ React7.createElement(PageStatus, { status: page.status }));
350
+ }
351
+
352
+ // src/components/panel/actions-menu/page-actions-menu.tsx
353
+ var React15 = __toESM(require("react"));
354
+ var import_ui10 = require("@elementor/ui");
355
+
356
+ // src/components/panel/pages-actions/rename.tsx
357
+ var React10 = __toESM(require("react"));
358
+ var import_icons6 = require("@elementor/icons");
359
+ var import_i18n3 = require("@wordpress/i18n");
360
+
361
+ // src/components/panel/actions-menu/action-menu-item.tsx
362
+ var React9 = __toESM(require("react"));
363
+
364
+ // src/components/panel/actions-menu/action-list-item.tsx
365
+ var React8 = __toESM(require("react"));
366
+ var import_ui8 = require("@elementor/ui");
367
+ function ActionListItem({ title, icon: Icon, disabled, onClick }) {
368
+ return /* @__PURE__ */ React8.createElement(
369
+ import_ui8.ListItemButton,
370
+ {
371
+ disabled,
372
+ onClick
373
+ },
374
+ /* @__PURE__ */ React8.createElement(import_ui8.ListItemIcon, null, /* @__PURE__ */ React8.createElement(Icon, null)),
375
+ /* @__PURE__ */ React8.createElement(import_ui8.ListItemText, null, title)
376
+ );
377
+ }
378
+
379
+ // src/components/panel/actions-menu/action-menu-item.tsx
380
+ var import_ui9 = require("@elementor/ui");
381
+ function ActionMenuItem(props) {
382
+ return /* @__PURE__ */ React9.createElement(import_ui9.MenuItem, { disableGutters: true }, /* @__PURE__ */ React9.createElement(ActionListItem, { ...props }));
383
+ }
384
+
385
+ // src/components/panel/pages-actions/rename.tsx
386
+ function Rename() {
387
+ return /* @__PURE__ */ React10.createElement(
388
+ ActionMenuItem,
389
+ {
390
+ title: (0, import_i18n3.__)("Rename", "elementor"),
391
+ icon: import_icons6.EraseIcon,
392
+ onClick: () => null
393
+ }
394
+ );
395
+ }
396
+
397
+ // src/components/panel/pages-actions/duplicate.tsx
398
+ var React11 = __toESM(require("react"));
399
+ var import_i18n4 = require("@wordpress/i18n");
400
+ var import_icons7 = require("@elementor/icons");
401
+ function Duplicate() {
402
+ return /* @__PURE__ */ React11.createElement(
403
+ ActionMenuItem,
404
+ {
405
+ title: (0, import_i18n4.__)("Duplicate", "elementor"),
406
+ icon: import_icons7.CopyIcon,
407
+ onClick: () => null
408
+ }
409
+ );
410
+ }
411
+
412
+ // src/components/panel/pages-actions/delete.tsx
413
+ var React12 = __toESM(require("react"));
414
+ var import_icons8 = require("@elementor/icons");
415
+ var import_editor_documents4 = require("@elementor/editor-documents");
416
+ var import_i18n5 = require("@wordpress/i18n");
417
+ function Delete({ page }) {
418
+ const activeDocument = (0, import_editor_documents4.useActiveDocument)();
419
+ const isActive = activeDocument?.id === page.id;
420
+ return /* @__PURE__ */ React12.createElement(
421
+ ActionMenuItem,
422
+ {
423
+ title: (0, import_i18n5.__)("Delete", "elementor"),
424
+ icon: import_icons8.TrashIcon,
425
+ disabled: page.isHome || isActive,
426
+ onClick: () => null
427
+ }
428
+ );
429
+ }
430
+
431
+ // src/components/panel/pages-actions/view.tsx
432
+ var React13 = __toESM(require("react"));
433
+ var import_icons9 = require("@elementor/icons");
434
+ var import_i18n6 = require("@wordpress/i18n");
435
+ function View() {
436
+ return /* @__PURE__ */ React13.createElement(
437
+ ActionMenuItem,
438
+ {
439
+ title: (0, import_i18n6.__)("View Page", "elementor"),
440
+ icon: import_icons9.EyeIcon,
441
+ onClick: () => null
442
+ }
443
+ );
444
+ }
445
+
446
+ // src/components/panel/pages-actions/set-home.tsx
447
+ var React14 = __toESM(require("react"));
448
+ var import_icons10 = require("@elementor/icons");
449
+ var import_i18n7 = require("@wordpress/i18n");
450
+ function SetHome({ page }) {
451
+ return /* @__PURE__ */ React14.createElement(
452
+ ActionMenuItem,
453
+ {
454
+ title: (0, import_i18n7.__)("Set as homepage", "elementor"),
455
+ icon: import_icons10.HomeIcon,
456
+ disabled: !!page.isHome,
457
+ onClick: () => null
458
+ }
459
+ );
460
+ }
461
+
462
+ // src/components/panel/actions-menu/page-actions-menu.tsx
463
+ function PageActionsMenu({ page, ...props }) {
464
+ return /* @__PURE__ */ React15.createElement(
465
+ import_ui10.Menu,
466
+ {
467
+ PaperProps: { sx: { mt: 4, width: 200 } },
468
+ MenuListProps: { dense: true },
469
+ ...props
470
+ },
471
+ /* @__PURE__ */ React15.createElement(Rename, null),
472
+ /* @__PURE__ */ React15.createElement(Duplicate, null),
473
+ /* @__PURE__ */ React15.createElement(Delete, { page }),
474
+ /* @__PURE__ */ React15.createElement(View, null),
475
+ /* @__PURE__ */ React15.createElement(import_ui10.Divider, null),
476
+ /* @__PURE__ */ React15.createElement(SetHome, { page })
477
+ );
478
+ }
479
+
480
+ // src/components/panel/pages-list/page-list-item.tsx
481
+ function PageListItem({ page }) {
482
+ const popupState = (0, import_ui11.usePopupState)({
483
+ variant: "popover",
484
+ popupId: "page-actions"
485
+ });
486
+ const activeDocument = (0, import_editor_documents5.useActiveDocument)();
487
+ const navigateToDocument = (0, import_editor_documents5.useNavigateToDocument)();
488
+ const isActive = activeDocument?.id === page.id;
489
+ return /* @__PURE__ */ React16.createElement(React16.Fragment, null, /* @__PURE__ */ React16.createElement(
490
+ import_ui11.ListItem,
491
+ {
492
+ disablePadding: true,
493
+ secondaryAction: /* @__PURE__ */ React16.createElement(
494
+ import_ui11.ToggleButton,
495
+ {
496
+ value: true,
497
+ color: "secondary",
498
+ size: "small",
499
+ selected: popupState.isOpen,
500
+ ...(0, import_ui11.bindTrigger)(popupState)
501
+ },
502
+ /* @__PURE__ */ React16.createElement(import_icons11.DotsVerticalIcon, { fontSize: "small" })
503
+ )
504
+ },
505
+ /* @__PURE__ */ React16.createElement(
506
+ import_ui11.ListItemButton,
507
+ {
508
+ selected: isActive,
509
+ onClick: () => navigateToDocument(page.id),
510
+ dense: true
511
+ },
512
+ /* @__PURE__ */ React16.createElement(import_ui11.ListItemIcon, null),
513
+ /* @__PURE__ */ React16.createElement(
514
+ import_ui11.ListItemText,
515
+ {
516
+ disableTypography: true
517
+ },
518
+ /* @__PURE__ */ React16.createElement(PageTitleAndStatus, { page })
519
+ ),
520
+ page.isHome && /* @__PURE__ */ React16.createElement(import_ui11.ListItemIcon, null, /* @__PURE__ */ React16.createElement(import_icons11.HomeIcon, { color: "disabled" }))
521
+ )
522
+ ), /* @__PURE__ */ React16.createElement(PageActionsMenu, { page, ...(0, import_ui11.bindMenu)(popupState) }));
523
+ }
524
+
525
+ // src/components/panel/pages-list/pages-collapsible-list.tsx
526
+ function PagesCollapsibleList({ pages, isOpenByDefault = false }) {
527
+ const label = `Pages (${pages.length})`;
528
+ return /* @__PURE__ */ React17.createElement(
529
+ CollapsibleList,
530
+ {
531
+ label,
532
+ Icon: import_icons12.PageTypeIcon,
533
+ isOpenByDefault
534
+ },
535
+ pages.map((page) => /* @__PURE__ */ React17.createElement(PageListItem, { key: page.id, page }))
536
+ );
537
+ }
538
+
539
+ // src/components/panel/shell.tsx
540
+ var mockPages = [
541
+ {
542
+ id: 1,
543
+ type: "page",
544
+ title: "This is a very long title that somebody wrote, a very very long line",
545
+ status: "pending approval"
546
+ },
547
+ { id: 2, type: "page", title: "About", status: "publish" },
548
+ { id: 3, type: "page", title: "Services", status: "publish", isHome: true },
549
+ { id: 4, type: "page", title: "Contact", status: "draft" },
550
+ { id: 5, type: "page", title: "FAQ", status: "publish" }
551
+ ];
552
+ var Shell = () => {
553
+ return /* @__PURE__ */ React18.createElement(import_ui12.ThemeProvider, { colorScheme: "light" }, /* @__PURE__ */ React18.createElement(import_ui12.Box, { sx: { width: "100%", maxWidth: 360 } }, /* @__PURE__ */ React18.createElement(import_ui12.Paper, null, /* @__PURE__ */ React18.createElement(
554
+ import_ui12.Grid,
555
+ {
556
+ container: true,
557
+ justifyContent: "center",
558
+ alignItems: "center",
559
+ sx: { height: 51 }
560
+ },
561
+ /* @__PURE__ */ React18.createElement(import_ui12.Typography, { variant: "h6" }, "Pages")
562
+ ), /* @__PURE__ */ React18.createElement(import_ui12.Divider, null), /* @__PURE__ */ React18.createElement(
563
+ import_ui12.Box,
564
+ {
565
+ display: "flex",
566
+ justifyContent: "flex-end",
567
+ alignItems: "center"
568
+ },
569
+ /* @__PURE__ */ React18.createElement(
570
+ import_ui12.Button,
571
+ {
572
+ sx: { mt: 4, mb: 4, mr: 5 },
573
+ startIcon: /* @__PURE__ */ React18.createElement(import_icons13.PlusIcon, null)
574
+ },
575
+ "Add New"
576
+ )
577
+ ), /* @__PURE__ */ React18.createElement(import_ui12.Box, { sx: { width: "100%", maxWidth: 360 } }, /* @__PURE__ */ React18.createElement(import_ui12.List, { dense: true }, /* @__PURE__ */ React18.createElement(PagesCollapsibleList, { pages: mockPages, isOpenByDefault: true }))), /* @__PURE__ */ React18.createElement(import_ui12.Divider, null))));
578
+ };
579
+ var shell_default = Shell;
580
+
581
+ // src/init.ts
251
582
  function init() {
252
583
  registerTopBarMenuItems();
584
+ registerPanel();
253
585
  }
254
586
  function registerTopBarMenuItems() {
255
587
  (0, import_editor_app_bar.injectIntoPageIndication)({
@@ -257,6 +589,12 @@ function registerTopBarMenuItems() {
257
589
  filler: RecentlyEdited
258
590
  });
259
591
  }
592
+ function registerPanel() {
593
+ (0, import_editor.injectIntoTop)({
594
+ id: "navigation-panel",
595
+ filler: shell_default
596
+ });
597
+ }
260
598
 
261
599
  // src/index.ts
262
600
  init();