@wordpress/boot 0.4.0 → 0.4.1-next.ba3aee3a2.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 (119) hide show
  1. package/LICENSE.md +1 -1
  2. package/build-module/components/app/{index.js → index.mjs} +9 -5
  3. package/build-module/components/app/index.mjs.map +7 -0
  4. package/build-module/components/app/{router.js → router.mjs} +43 -40
  5. package/build-module/components/app/router.mjs.map +7 -0
  6. package/build-module/components/app/{use-route-title.js → use-route-title.mjs} +2 -2
  7. package/build-module/components/canvas/{back-button.js → back-button.mjs} +2 -2
  8. package/build-module/components/canvas/{index.js → index.mjs} +2 -2
  9. package/build-module/components/canvas-renderer/{index.js → index.mjs} +2 -2
  10. package/build-module/components/navigation/drilldown-item/{index.js → index.mjs} +2 -2
  11. package/build-module/components/navigation/dropdown-item/{index.js → index.mjs} +4 -4
  12. package/build-module/components/navigation/{index.js → index.mjs} +7 -7
  13. package/build-module/components/navigation/{items.js → items.mjs} +1 -1
  14. package/build-module/components/navigation/navigation-item/index.mjs +184 -0
  15. package/build-module/components/navigation/navigation-item/index.mjs.map +7 -0
  16. package/build-module/components/navigation/navigation-screen/{index.js → index.mjs} +1 -1
  17. package/build-module/components/navigation/{path-matching.js → path-matching.mjs} +1 -1
  18. package/build-module/components/navigation/{router-link-item.js → router-link-item.mjs} +2 -2
  19. package/build-module/components/navigation/{use-sidebar-parent.js → use-sidebar-parent.mjs} +4 -4
  20. package/build-module/components/root/index.mjs +425 -0
  21. package/build-module/components/root/index.mjs.map +7 -0
  22. package/build-module/components/root/single-page.mjs +334 -0
  23. package/build-module/components/root/single-page.mjs.map +7 -0
  24. package/build-module/components/save-button/{index.js → index.mjs} +2 -2
  25. package/build-module/components/save-panel/{index.js → index.mjs} +2 -2
  26. package/build-module/components/save-panel/{use-save-shortcut.js → use-save-shortcut.mjs} +1 -1
  27. package/build-module/components/sidebar/{index.js → index.mjs} +4 -4
  28. package/build-module/components/site-hub/index.mjs +179 -0
  29. package/build-module/components/site-hub/index.mjs.map +7 -0
  30. package/build-module/components/site-icon/{index.js → index.mjs} +3 -3
  31. package/build-module/components/site-icon/index.mjs.map +7 -0
  32. package/build-module/components/site-icon-link/{index.js → index.mjs} +6 -5
  33. package/build-module/components/site-icon-link/index.mjs.map +7 -0
  34. package/build-module/components/user-theme-provider/index.mjs +33 -0
  35. package/build-module/components/user-theme-provider/index.mjs.map +7 -0
  36. package/build-module/index.mjs +708 -0
  37. package/build-module/index.mjs.map +7 -0
  38. package/build-module/{lock-unlock.js → lock-unlock.mjs} +1 -1
  39. package/build-module/store/{actions.js → actions.mjs} +8 -1
  40. package/build-module/store/{actions.js.map → actions.mjs.map} +2 -2
  41. package/build-module/store/{index.js → index.mjs} +4 -4
  42. package/build-module/store/{reducer.js → reducer.mjs} +8 -2
  43. package/build-module/store/reducer.mjs.map +7 -0
  44. package/build-module/store/{selectors.js → selectors.mjs} +5 -1
  45. package/build-module/store/{selectors.js.map → selectors.mjs.map} +2 -2
  46. package/build-module/store/types.mjs +1 -0
  47. package/build-style/style-rtl.css +39 -71
  48. package/build-style/style.css +39 -71
  49. package/build-types/components/app/index.d.ts +2 -1
  50. package/build-types/components/app/index.d.ts.map +1 -1
  51. package/build-types/components/app/router.d.ts.map +1 -1
  52. package/build-types/components/navigation/items.d.ts +1 -1
  53. package/build-types/components/root/index.d.ts.map +1 -1
  54. package/build-types/components/root/single-page.d.ts.map +1 -1
  55. package/build-types/components/site-hub/index.d.ts.map +1 -1
  56. package/build-types/components/site-icon-link/index.d.ts.map +1 -1
  57. package/build-types/components/user-theme-provider/index.d.ts +6 -0
  58. package/build-types/components/user-theme-provider/index.d.ts.map +1 -0
  59. package/build-types/store/actions.d.ts +5 -1
  60. package/build-types/store/actions.d.ts.map +1 -1
  61. package/build-types/store/reducer.d.ts.map +1 -1
  62. package/build-types/store/selectors.d.ts +1 -0
  63. package/build-types/store/selectors.d.ts.map +1 -1
  64. package/build-types/store/types.d.ts +1 -0
  65. package/build-types/store/types.d.ts.map +1 -1
  66. package/package.json +33 -25
  67. package/src/components/app/index.tsx +6 -0
  68. package/src/components/app/router.tsx +54 -51
  69. package/src/components/root/index.tsx +44 -49
  70. package/src/components/root/single-page.tsx +34 -32
  71. package/src/components/root/style.scss +1 -0
  72. package/src/components/site-hub/index.tsx +13 -3
  73. package/src/components/site-hub/style.scss +21 -6
  74. package/src/components/site-icon/style.scss +1 -1
  75. package/src/components/site-icon-link/index.tsx +18 -15
  76. package/src/components/user-theme-provider/index.tsx +35 -0
  77. package/src/components/user-theme-provider/test/index.test.ts +11 -0
  78. package/src/store/actions.ts +9 -1
  79. package/src/store/reducer.ts +7 -0
  80. package/src/store/selectors.ts +4 -0
  81. package/src/store/types.ts +1 -0
  82. package/src/style.scss +19 -34
  83. package/build-module/components/app/index.js.map +0 -7
  84. package/build-module/components/app/router.js.map +0 -7
  85. package/build-module/components/navigation/navigation-item/index.js +0 -180
  86. package/build-module/components/navigation/navigation-item/index.js.map +0 -7
  87. package/build-module/components/root/index.js +0 -433
  88. package/build-module/components/root/index.js.map +0 -7
  89. package/build-module/components/root/single-page.js +0 -334
  90. package/build-module/components/root/single-page.js.map +0 -7
  91. package/build-module/components/site-hub/index.js +0 -153
  92. package/build-module/components/site-hub/index.js.map +0 -7
  93. package/build-module/components/site-icon/index.js.map +0 -7
  94. package/build-module/components/site-icon-link/index.js.map +0 -7
  95. package/build-module/index.js +0 -740
  96. package/build-module/index.js.map +0 -7
  97. package/build-module/store/reducer.js.map +0 -7
  98. package/build-module/store/types.js +0 -1
  99. package/tsconfig.json +0 -27
  100. package/tsconfig.tsbuildinfo +0 -1
  101. /package/build-module/components/app/{use-route-title.js.map → use-route-title.mjs.map} +0 -0
  102. /package/build-module/components/canvas/{back-button.js.map → back-button.mjs.map} +0 -0
  103. /package/build-module/components/canvas/{index.js.map → index.mjs.map} +0 -0
  104. /package/build-module/components/canvas-renderer/{index.js.map → index.mjs.map} +0 -0
  105. /package/build-module/components/navigation/drilldown-item/{index.js.map → index.mjs.map} +0 -0
  106. /package/build-module/components/navigation/dropdown-item/{index.js.map → index.mjs.map} +0 -0
  107. /package/build-module/components/navigation/{index.js.map → index.mjs.map} +0 -0
  108. /package/build-module/components/navigation/{items.js.map → items.mjs.map} +0 -0
  109. /package/build-module/components/navigation/navigation-screen/{index.js.map → index.mjs.map} +0 -0
  110. /package/build-module/components/navigation/{path-matching.js.map → path-matching.mjs.map} +0 -0
  111. /package/build-module/components/navigation/{router-link-item.js.map → router-link-item.mjs.map} +0 -0
  112. /package/build-module/components/navigation/{use-sidebar-parent.js.map → use-sidebar-parent.mjs.map} +0 -0
  113. /package/build-module/components/save-button/{index.js.map → index.mjs.map} +0 -0
  114. /package/build-module/components/save-panel/{index.js.map → index.mjs.map} +0 -0
  115. /package/build-module/components/save-panel/{use-save-shortcut.js.map → use-save-shortcut.mjs.map} +0 -0
  116. /package/build-module/components/sidebar/{index.js.map → index.mjs.map} +0 -0
  117. /package/build-module/{lock-unlock.js.map → lock-unlock.mjs.map} +0 -0
  118. /package/build-module/store/{index.js.map → index.mjs.map} +0 -0
  119. /package/build-module/store/{types.js.map → types.mjs.map} +0 -0
@@ -7,10 +7,8 @@ import clsx from 'clsx';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { privateApis as routePrivateApis } from '@wordpress/route';
10
- // @ts-expect-error Commands is not typed properly.
11
- import { CommandMenu } from '@wordpress/commands';
12
- import { privateApis as themePrivateApis } from '@wordpress/theme';
13
10
  import { EditorSnackbars } from '@wordpress/editor';
11
+ import { SlotFillProvider } from '@wordpress/components';
14
12
 
15
13
  /**
16
14
  * Internal dependencies
@@ -21,9 +19,9 @@ import { unlock } from '../../lock-unlock';
21
19
  import type { CanvasData } from '../../store/types';
22
20
  import './style.scss';
23
21
  import useRouteTitle from '../app/use-route-title';
22
+ import { UserThemeProvider } from '../user-theme-provider';
24
23
 
25
24
  const { useMatches, Outlet } = unlock( routePrivateApis );
26
- const { ThemeProvider } = unlock( themePrivateApis );
27
25
 
28
26
  /**
29
27
  * Root component for single page mode (no sidebar).
@@ -43,35 +41,39 @@ export default function RootSinglePage() {
43
41
  useRouteTitle();
44
42
 
45
43
  return (
46
- <ThemeProvider isRoot color={ { bg: '#f8f8f8', primary: '#3858e9' } }>
47
- <ThemeProvider color={ { bg: '#1d2327', primary: '#3858e9' } }>
48
- <div
49
- className={ clsx( 'boot-layout boot-layout--single-page', {
50
- 'has-canvas': !! canvas || canvas === null,
51
- 'has-full-canvas': isFullScreen,
52
- } ) }
53
- >
54
- <CommandMenu />
55
- <SavePanel />
56
- <EditorSnackbars />
57
- <div className="boot-layout__surfaces">
58
- <ThemeProvider
59
- color={ { bg: '#ffffff', primary: '#3858e9' } }
60
- >
61
- <Outlet />
62
- </ThemeProvider>
63
- { /* Render Canvas in Root to prevent remounting on route changes */ }
64
- { ( canvas || canvas === null ) && (
65
- <div className="boot-layout__canvas">
66
- <CanvasRenderer
67
- canvas={ canvas }
68
- routeContentModule={ routeContentModule }
69
- />
70
- </div>
44
+ <SlotFillProvider>
45
+ <UserThemeProvider isRoot color={ { bg: '#f8f8f8' } }>
46
+ <UserThemeProvider color={ { bg: '#1d2327' } }>
47
+ <div
48
+ className={ clsx(
49
+ 'boot-layout boot-layout--single-page',
50
+ {
51
+ 'has-canvas': !! canvas || canvas === null,
52
+ 'has-full-canvas': isFullScreen,
53
+ }
71
54
  ) }
55
+ >
56
+ <SavePanel />
57
+ <EditorSnackbars />
58
+ <div className="boot-layout__surfaces">
59
+ <UserThemeProvider color={ { bg: '#ffffff' } }>
60
+ <Outlet />
61
+ { /* Render Canvas in Root to prevent remounting on route changes */ }
62
+ { ( canvas || canvas === null ) && (
63
+ <div className="boot-layout__canvas">
64
+ <CanvasRenderer
65
+ canvas={ canvas }
66
+ routeContentModule={
67
+ routeContentModule
68
+ }
69
+ />
70
+ </div>
71
+ ) }
72
+ </UserThemeProvider>
73
+ </div>
72
74
  </div>
73
- </div>
74
- </ThemeProvider>
75
- </ThemeProvider>
75
+ </UserThemeProvider>
76
+ </UserThemeProvider>
77
+ </SlotFillProvider>
76
78
  );
77
79
  }
@@ -72,6 +72,7 @@
72
72
 
73
73
  .boot-layout--single-page & {
74
74
  margin-top: 0;
75
+ margin-left: 0;
75
76
  }
76
77
  }
77
78
  }
@@ -22,16 +22,18 @@ import type { UnstableBase } from '@wordpress/core-data';
22
22
  * Internal dependencies
23
23
  */
24
24
  import SiteIconLink from '../site-icon-link';
25
+ import { store as bootStore } from '../../store';
25
26
  import './style.scss';
26
27
 
27
28
  function SiteHub() {
28
- const { homeUrl, siteTitle } = useSelect( ( select ) => {
29
+ const { dashboardLink, homeUrl, siteTitle } = useSelect( ( select ) => {
29
30
  const { getEntityRecord } = select( coreStore );
30
31
  const _base = getEntityRecord< UnstableBase >(
31
32
  'root',
32
33
  '__unstableBase'
33
34
  );
34
35
  return {
36
+ dashboardLink: select( bootStore ).getDashboardLink(),
35
37
  homeUrl: _base?.home,
36
38
  siteTitle:
37
39
  ! _base?.name && !! _base?.url
@@ -43,12 +45,20 @@ function SiteHub() {
43
45
 
44
46
  return (
45
47
  <div className="boot-site-hub">
46
- <SiteIconLink to="/" aria-label={ __( 'Go to the Dashboard' ) } />
48
+ <SiteIconLink
49
+ to={ dashboardLink || '/' }
50
+ aria-label={ __( 'Go to the Dashboard' ) }
51
+ />
47
52
  <ExternalLink
48
53
  href={ homeUrl ?? '/' }
49
54
  className="boot-site-hub__title"
50
55
  >
51
- { siteTitle && decodeEntities( siteTitle ) }
56
+ <div className="boot-site-hub__title-text">
57
+ { siteTitle && decodeEntities( siteTitle ) }
58
+ </div>
59
+ <div className="boot-site-hub__url">
60
+ { filterURLForDisplay( homeUrl ?? '' ) }
61
+ </div>
52
62
  </ExternalLink>
53
63
  <HStack className="boot-site-hub__actions">
54
64
  <Button
@@ -17,17 +17,15 @@
17
17
  }
18
18
 
19
19
  .boot-site-hub__title {
20
- color: var(--wpds-color-fg-content-neutral, #1e1e1e);
21
- font-size: variables.$font-size-medium;
22
- font-weight: variables.$font-weight-medium;
23
- overflow: hidden;
24
- text-overflow: ellipsis;
25
- white-space: nowrap;
20
+ display: flex;
21
+ align-items: center;
26
22
  text-decoration: none;
27
23
 
28
24
  .components-external-link__contents {
29
25
  text-decoration: none;
30
26
  margin-inline-start: variables.$grid-unit-05;
27
+ overflow: hidden;
28
+ max-width: 140px;
31
29
  }
32
30
 
33
31
  // Show icon on hover
@@ -52,3 +50,20 @@
52
50
  outline-offset: calc(-1 * var(--wpds-border-width-interactive-focus, 2px));
53
51
  }
54
52
  }
53
+
54
+ .boot-site-hub__title-text {
55
+ color: var(--wpds-color-fg-content-neutral, #1e1e1e);
56
+ font-size: variables.$font-size-medium;
57
+ font-weight: variables.$font-weight-medium;
58
+ overflow: hidden;
59
+ text-overflow: ellipsis;
60
+ white-space: nowrap;
61
+ }
62
+
63
+ .boot-site-hub__url {
64
+ color: var(--wpds-color-fg-content-neutral-weak, #757575);
65
+ font-size: variables.$font-size-small;
66
+ overflow: hidden;
67
+ text-overflow: ellipsis;
68
+ white-space: nowrap;
69
+ }
@@ -7,7 +7,7 @@
7
7
  .boot-site-icon__icon {
8
8
  width: variables.$grid-unit-40;
9
9
  height: variables.$grid-unit-40;
10
- color: var(--wpds-color-fg-content-neutral, #1e1e1e);
10
+ fill: var(--wpds-color-fg-content-neutral, #1e1e1e);
11
11
  }
12
12
 
13
13
  .boot-site-icon__image {
@@ -2,6 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { Link, privateApis as routePrivateApis } from '@wordpress/route';
5
+ import { Tooltip } from '@wordpress/components';
5
6
 
6
7
  /**
7
8
  * Internal dependencies
@@ -25,21 +26,23 @@ function SiteIconLink( {
25
26
  const canGoBack = useCanGoBack();
26
27
 
27
28
  return (
28
- <Link
29
- to={ to }
30
- aria-label={ props[ 'aria-label' ] }
31
- className="boot-site-icon-link"
32
- onClick={ ( event ) => {
33
- // If possible, restore the previous page with
34
- // filters etc.
35
- if ( canGoBack && isBackButton ) {
36
- event.preventDefault();
37
- router.history.back();
38
- }
39
- } }
40
- >
41
- <SiteIcon />
42
- </Link>
29
+ <Tooltip text={ props[ 'aria-label' ] } placement="right">
30
+ <Link
31
+ to={ to }
32
+ aria-label={ props[ 'aria-label' ] }
33
+ className="boot-site-icon-link"
34
+ onClick={ ( event ) => {
35
+ // If possible, restore the previous page with
36
+ // filters etc.
37
+ if ( canGoBack && isBackButton ) {
38
+ event.preventDefault();
39
+ router.history.back();
40
+ }
41
+ } }
42
+ >
43
+ <SiteIcon />
44
+ </Link>
45
+ </Tooltip>
43
46
  );
44
47
  }
45
48
 
@@ -0,0 +1,35 @@
1
+ import {
2
+ type ThemeProvider as ThemeProviderType,
3
+ privateApis as themePrivateApis,
4
+ } from '@wordpress/theme';
5
+ import { unlock } from '../../lock-unlock';
6
+
7
+ const ThemeProvider: typeof ThemeProviderType =
8
+ unlock( themePrivateApis ).ThemeProvider;
9
+
10
+ const THEME_PRIMARY_COLORS = new Map< string, string >( [
11
+ [ 'light', '#0085ba' ],
12
+ [ 'modern', '#3858e9' ],
13
+ [ 'blue', '#096484' ],
14
+ [ 'coffee', '#46403c' ],
15
+ [ 'ectoplasm', '#523f6d' ],
16
+ [ 'midnight', '#e14d43' ],
17
+ [ 'ocean', '#627c83' ],
18
+ [ 'sunrise', '#dd823b' ],
19
+ ] );
20
+
21
+ export function getAdminThemePrimaryColor(): string | undefined {
22
+ const theme =
23
+ document.body.className.match( /admin-color-([a-z]+)/ )?.[ 1 ];
24
+
25
+ return theme && THEME_PRIMARY_COLORS.get( theme );
26
+ }
27
+
28
+ export function UserThemeProvider( {
29
+ color,
30
+ ...restProps
31
+ }: React.ComponentProps< typeof ThemeProvider > ) {
32
+ const primary = getAdminThemePrimaryColor();
33
+
34
+ return <ThemeProvider { ...restProps } color={ { primary, ...color } } />;
35
+ }
@@ -0,0 +1,11 @@
1
+ import { getAdminThemePrimaryColor } from '../index';
2
+
3
+ describe( 'getAdminThemePrimaryColor', () => {
4
+ it( 'should return the primary color for the admin theme from the body class', () => {
5
+ document.body.className = 'foo admin-color-coffee bar';
6
+
7
+ const primaryColor = getAdminThemePrimaryColor();
8
+
9
+ expect( primaryColor ).toBe( '#46403c' );
10
+ } );
11
+ } );
@@ -26,7 +26,15 @@ export function registerRoute( route: Route ) {
26
26
  };
27
27
  }
28
28
 
29
+ export function setDashboardLink( dashboardLink: string ) {
30
+ return {
31
+ type: 'SET_DASHBOARD_LINK' as const,
32
+ dashboardLink,
33
+ };
34
+ }
35
+
29
36
  export type Action =
30
37
  | ReturnType< typeof registerMenuItem >
31
38
  | ReturnType< typeof updateMenuItem >
32
- | ReturnType< typeof registerRoute >;
39
+ | ReturnType< typeof registerRoute >
40
+ | ReturnType< typeof setDashboardLink >;
@@ -7,6 +7,7 @@ import type { State } from './types';
7
7
  const initialState: State = {
8
8
  menuItems: {},
9
9
  routes: [],
10
+ dashboardLink: undefined,
10
11
  };
11
12
 
12
13
  export function reducer( state: State = initialState, action: Action ): State {
@@ -37,6 +38,12 @@ export function reducer( state: State = initialState, action: Action ): State {
37
38
  ...state,
38
39
  routes: [ ...state.routes, action.route ],
39
40
  };
41
+
42
+ case 'SET_DASHBOARD_LINK':
43
+ return {
44
+ ...state,
45
+ dashboardLink: action.dashboardLink,
46
+ };
40
47
  }
41
48
 
42
49
  return state;
@@ -10,3 +10,7 @@ export function getMenuItems( state: State ) {
10
10
  export function getRoutes( state: State ) {
11
11
  return state.routes;
12
12
  }
13
+
14
+ export function getDashboardLink( state: State ) {
15
+ return state.dashboardLink;
16
+ }
@@ -163,4 +163,5 @@ export interface Route {
163
163
  export interface State {
164
164
  menuItems: Record< string, MenuItem >;
165
165
  routes: Route[];
166
+ dashboardLink?: string;
166
167
  }
package/src/style.scss CHANGED
@@ -1,47 +1,32 @@
1
1
  @use "@wordpress/theme/src/prebuilt/css/design-tokens.css" as *;
2
2
  @use "@wordpress/admin-ui/build-style/style.css" as *;
3
3
  @use "@wordpress/base-styles/mixins" as *;
4
- @use "@wordpress/base-styles/variables";
4
+ @use "@wordpress/base-styles/variables" as *;
5
5
 
6
- // Reset wp-admin layout styles when loaded inside wp-admin.
7
6
  .boot-layout-container .boot-layout {
8
- height: calc(100vh - #{variables.$admin-bar-height});
9
- }
10
-
11
- body:has(.boot-layout-container) {
12
- background: #1d2327; // Same as WP-Admin sidebar
13
- overflow: hidden;
14
- @include wp-admin-reset( ".boot-layout-container" );
15
- }
16
-
17
- #wpcontent {
18
- padding-left: 0;
19
- }
20
-
21
- #wpbody-content {
22
- padding-bottom: 0;
23
- }
24
-
25
- #wpfooter {
26
- display: none;
27
- }
7
+ // On mobile the main content area has to scroll, otherwise you can invoke
8
+ // the overscroll bounce on the non-scrolling container, for a bad experience.
9
+ @include break-small {
10
+ position: absolute;
11
+ top: 0;
12
+ right: 0;
13
+ bottom: 0;
14
+ left: 0;
15
+ min-height: calc(100vh - #{$admin-bar-height-big});
16
+ }
28
17
 
29
- body:has(.boot-layout.has-full-canvas) {
18
+ // The WP header height changes at this breakpoint.
30
19
  @include break-medium {
31
- // Reset the html.wp-topbar padding.
32
- // Because this uses negative margins, we have to compensate for the height.
33
- margin-top: - variables.$admin-bar-height;
34
- height: calc(100% + #{ variables.$admin-bar-height });
20
+ min-height: calc(100vh - #{$admin-bar-height});
35
21
 
36
- #adminmenumain,
37
- #wpadminbar {
38
- display: none;
22
+ body:has(.boot-layout.has-full-canvas) & {
23
+ min-height: 100vh;
39
24
  }
25
+ }
40
26
 
41
- #wpcontent,
42
- #wpfooter {
43
- margin-left: 0;
44
- }
27
+ img {
28
+ max-width: 100%;
29
+ height: auto;
45
30
  }
46
31
  }
47
32
 
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/app/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createRoot, StrictMode, type ComponentType } from '@wordpress/element';\nimport { dispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport Router from './router';\nimport RootSinglePage from '../root/single-page';\nimport { store } from '../../store';\nimport type { MenuItem, Route } from '../../store/types';\n\nfunction App( { rootComponent }: { rootComponent?: ComponentType } ) {\n\tconst routes = useSelect( ( select ) => select( store ).getRoutes(), [] );\n\n\treturn <Router routes={ routes } rootComponent={ rootComponent } />;\n}\n\nexport async function init( {\n\tmountId,\n\tmenuItems,\n\troutes,\n\tinitModules,\n}: {\n\tmountId: string;\n\tmenuItems?: MenuItem[];\n\troutes?: Route[];\n\tinitModules?: string[];\n} ) {\n\t( menuItems ?? [] ).forEach( ( menuItem ) => {\n\t\tdispatch( store ).registerMenuItem( menuItem.id, menuItem );\n\t} );\n\n\t( routes ?? [] ).forEach( ( route ) => {\n\t\tdispatch( store ).registerRoute( route );\n\t} );\n\n\tfor ( const moduleId of initModules ?? [] ) {\n\t\tconst module = await import( moduleId );\n\t\tawait module.init();\n\t}\n\n\t// Render the app\n\tconst rootElement = document.getElementById( mountId );\n\tif ( rootElement ) {\n\t\tconst root = createRoot( rootElement );\n\t\troot.render(\n\t\t\t<StrictMode>\n\t\t\t\t<App />\n\t\t\t</StrictMode>\n\t\t);\n\t}\n}\n\nexport async function initSinglePage( {\n\tmountId,\n\troutes,\n}: {\n\tmountId: string;\n\troutes?: Route[];\n} ) {\n\t( routes ?? [] ).forEach( ( route ) => {\n\t\tdispatch( store ).registerRoute( route );\n\t} );\n\n\t// Render the app without sidebar\n\tconst rootElement = document.getElementById( mountId );\n\tif ( rootElement ) {\n\t\tconst root = createRoot( rootElement );\n\t\troot.render(\n\t\t\t<StrictMode>\n\t\t\t\t<App rootComponent={ RootSinglePage } />\n\t\t\t</StrictMode>\n\t\t);\n\t}\n}\n"],
5
- "mappings": ";AAGA,SAAS,YAAY,kBAAsC;AAC3D,SAAS,UAAU,iBAAiB;AAKpC,OAAO,YAAY;AACnB,OAAO,oBAAoB;AAC3B,SAAS,aAAa;AAMd;AAHR,SAAS,IAAK,EAAE,cAAc,GAAuC;AACpE,QAAM,SAAS,UAAW,CAAE,WAAY,OAAQ,KAAM,EAAE,UAAU,GAAG,CAAC,CAAE;AAExE,SAAO,oBAAC,UAAO,QAAkB,eAAgC;AAClE;AAEA,eAAsB,KAAM;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAKI;AACH,GAAE,aAAa,CAAC,GAAI,QAAS,CAAE,aAAc;AAC5C,aAAU,KAAM,EAAE,iBAAkB,SAAS,IAAI,QAAS;AAAA,EAC3D,CAAE;AAEF,GAAE,UAAU,CAAC,GAAI,QAAS,CAAE,UAAW;AACtC,aAAU,KAAM,EAAE,cAAe,KAAM;AAAA,EACxC,CAAE;AAEF,aAAY,YAAY,eAAe,CAAC,GAAI;AAC3C,UAAM,SAAS,MAAM,OAAQ;AAC7B,UAAM,OAAO,KAAK;AAAA,EACnB;AAGA,QAAM,cAAc,SAAS,eAAgB,OAAQ;AACrD,MAAK,aAAc;AAClB,UAAM,OAAO,WAAY,WAAY;AACrC,SAAK;AAAA,MACJ,oBAAC,cACA,8BAAC,OAAI,GACN;AAAA,IACD;AAAA,EACD;AACD;AAEA,eAAsB,eAAgB;AAAA,EACrC;AAAA,EACA;AACD,GAGI;AACH,GAAE,UAAU,CAAC,GAAI,QAAS,CAAE,UAAW;AACtC,aAAU,KAAM,EAAE,cAAe,KAAM;AAAA,EACxC,CAAE;AAGF,QAAM,cAAc,SAAS,eAAgB,OAAQ;AACrD,MAAK,aAAc;AAClB,UAAM,OAAO,WAAY,WAAY;AACrC,SAAK;AAAA,MACJ,oBAAC,cACA,8BAAC,OAAI,eAAgB,gBAAiB,GACvC;AAAA,IACD;AAAA,EACD;AACD;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/app/router.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport { Page } from '@wordpress/admin-ui';\nimport {\n\tprivateApis as routePrivateApis,\n\ttype AnyRoute,\n} from '@wordpress/route';\nimport { resolveSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport Root from '../root';\nimport type { Route, RouteConfig, RouteLoaderContext } from '../../store/types';\nimport { unlock } from '../../lock-unlock';\n\nconst {\n\tcreateLazyRoute,\n\tcreateRouter,\n\tcreateRootRoute,\n\tcreateRoute,\n\tRouterProvider,\n\tcreateBrowserHistory,\n\tparseHref,\n\tuseLoaderData,\n} = unlock( routePrivateApis );\n\n// Not found component\nfunction NotFoundComponent() {\n\treturn (\n\t\t<div className=\"boot-layout__stage\">\n\t\t\t<Page title={ __( 'Route not found' ) } hasPadding>\n\t\t\t\t{ __( \"The page you're looking for does not exist\" ) }\n\t\t\t</Page>\n\t\t</div>\n\t);\n}\n\n/**\n * Creates a TanStack route from a Route definition.\n *\n * @param route Route configuration\n * @param parentRoute Parent route.\n * @return Tanstack Route.\n */\nasync function createRouteFromDefinition(\n\troute: Route,\n\tparentRoute: AnyRoute\n) {\n\tlet routeConfig: RouteConfig = {};\n\n\tif ( route.route_module ) {\n\t\tconst module = await import( route.route_module );\n\t\trouteConfig = module.route || {};\n\t}\n\n\t// Create route without component initially\n\tlet tanstackRoute = createRoute( {\n\t\tgetParentRoute: () => parentRoute,\n\t\tpath: route.path,\n\t\tbeforeLoad: routeConfig.beforeLoad\n\t\t\t? ( opts: any ) =>\n\t\t\t\t\trouteConfig.beforeLoad!( {\n\t\t\t\t\t\tparams: opts.params || {},\n\t\t\t\t\t\tsearch: opts.search || {},\n\t\t\t\t\t} )\n\t\t\t: undefined,\n\t\tloader: async ( opts: any ) => {\n\t\t\tconst context: RouteLoaderContext = {\n\t\t\t\tparams: opts.params || {},\n\t\t\t\tsearch: opts.deps || {},\n\t\t\t};\n\n\t\t\tconst [ , loaderData, canvasData, titleData ] = await Promise.all( [\n\t\t\t\tresolveSelect( coreStore ).getEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'__unstableBase'\n\t\t\t\t),\n\t\t\t\trouteConfig.loader\n\t\t\t\t\t? routeConfig.loader( context )\n\t\t\t\t\t: Promise.resolve( undefined ),\n\t\t\t\trouteConfig.canvas\n\t\t\t\t\t? routeConfig.canvas( context )\n\t\t\t\t\t: Promise.resolve( undefined ),\n\t\t\t\trouteConfig.title\n\t\t\t\t\t? routeConfig.title( context )\n\t\t\t\t\t: Promise.resolve( undefined ),\n\t\t\t] );\n\n\t\t\tlet inspector = true;\n\t\t\tif ( routeConfig.inspector ) {\n\t\t\t\tinspector = await routeConfig.inspector( context );\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...( loaderData as any ),\n\t\t\t\tcanvas: canvasData,\n\t\t\t\tinspector,\n\t\t\t\ttitle: titleData,\n\t\t\t\trouteContentModule: route.content_module,\n\t\t\t};\n\t\t},\n\t\tloaderDeps: ( opts: any ) => opts.search,\n\t} );\n\n\t// Chain .lazy() to preload content module on intent\n\ttanstackRoute = tanstackRoute.lazy( async () => {\n\t\tconst module = route.content_module\n\t\t\t? await import( route.content_module )\n\t\t\t: {};\n\n\t\tconst Stage = module.stage;\n\t\tconst Inspector = module.inspector;\n\n\t\treturn createLazyRoute( route.path )( {\n\t\t\tcomponent: function RouteComponent() {\n\t\t\t\tconst { inspector: showInspector } =\n\t\t\t\t\tuseLoaderData( { from: route.path } ) ?? {};\n\n\t\t\t\treturn (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ Stage && (\n\t\t\t\t\t\t\t<div className=\"boot-layout__stage\">\n\t\t\t\t\t\t\t\t<Stage />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ Inspector && showInspector && (\n\t\t\t\t\t\t\t<div className=\"boot-layout__inspector\">\n\t\t\t\t\t\t\t\t<Inspector />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t);\n\t\t\t},\n\t\t} );\n\t} );\n\n\treturn tanstackRoute;\n}\n\n/**\n * Creates a route tree from route definitions.\n *\n * @param routes Routes definition.\n * @param rootComponent Root component to use for the router.\n * @return Router tree.\n */\nasync function createRouteTree(\n\troutes: Route[],\n\trootComponent: ComponentType = Root\n) {\n\tconst rootRoute = createRootRoute( {\n\t\tcomponent: rootComponent as any,\n\t\tcontext: () => ( {} ),\n\t} );\n\n\t// Create routes from definitions\n\tconst dynamicRoutes = await Promise.all(\n\t\troutes.map( ( route ) => createRouteFromDefinition( route, rootRoute ) )\n\t);\n\n\treturn rootRoute.addChildren( dynamicRoutes );\n}\n\n// Create custom history that parses ?p= query parameter\nfunction createPathHistory() {\n\treturn createBrowserHistory( {\n\t\tparseLocation: () => {\n\t\t\tconst url = new URL( window.location.href );\n\t\t\tconst path = url.searchParams.get( 'p' ) || '/';\n\t\t\tconst pathHref = `${ path }${ url.hash }`;\n\t\t\treturn parseHref( pathHref, window.history.state );\n\t\t},\n\t\tcreateHref: ( href: string ) => {\n\t\t\tconst searchParams = new URLSearchParams( window.location.search );\n\t\t\tsearchParams.set( 'p', href );\n\t\t\treturn `${ window.location.pathname }?${ searchParams }`;\n\t\t},\n\t} );\n}\n\ninterface RouterProps {\n\troutes: Route[];\n\trootComponent?: ComponentType;\n}\n\nexport default function Router( {\n\troutes,\n\trootComponent = Root,\n}: RouterProps ) {\n\tconst [ router, setRouter ] = useState< any >( null );\n\n\tuseEffect( () => {\n\t\tlet cancelled = false;\n\n\t\tasync function initializeRouter() {\n\t\t\tconst history = createPathHistory();\n\t\t\tconst routeTree = await createRouteTree( routes, rootComponent );\n\n\t\t\tif ( ! cancelled ) {\n\t\t\t\tconst newRouter = createRouter( {\n\t\t\t\t\thistory,\n\t\t\t\t\trouteTree,\n\t\t\t\t\tdefaultPreload: 'intent',\n\t\t\t\t\tdefaultNotFoundComponent: NotFoundComponent,\n\t\t\t\t\tdefaultViewTransition: true,\n\t\t\t\t} );\n\t\t\t\tsetRouter( newRouter );\n\t\t\t}\n\t\t}\n\n\t\tinitializeRouter();\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t};\n\t}, [ routes, rootComponent ] );\n\n\tif ( ! router ) {\n\t\treturn <div>Loading routes...</div>;\n\t}\n\n\treturn <RouterProvider router={ router } />;\n}\n"],
5
- "mappings": ";AAQA,SAAS,UAAU;AACnB,SAAS,UAAU,iBAAiB;AACpC,SAAS,YAAY;AACrB;AAAA,EACC,eAAe;AAAA,OAET;AACP,SAAS,qBAAqB;AAC9B,SAAS,SAAS,iBAAiB;AAKnC,OAAO,UAAU;AAEjB,SAAS,cAAc;AAiBpB,SAyFE,UAzFF,KAyFE,YAzFF;AAfH,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,IAAI,OAAQ,gBAAiB;AAG7B,SAAS,oBAAoB;AAC5B,SACC,oBAAC,SAAI,WAAU,sBACd,8BAAC,QAAK,OAAQ,GAAI,iBAAkB,GAAI,YAAU,MAC/C,aAAI,4CAA6C,GACpD,GACD;AAEF;AASA,eAAe,0BACd,OACA,aACC;AACD,MAAI,cAA2B,CAAC;AAEhC,MAAK,MAAM,cAAe;AACzB,UAAM,SAAS,MAAM,OAAQ,MAAM;AACnC,kBAAc,OAAO,SAAS,CAAC;AAAA,EAChC;AAGA,MAAI,gBAAgB,YAAa;AAAA,IAChC,gBAAgB,MAAM;AAAA,IACtB,MAAM,MAAM;AAAA,IACZ,YAAY,YAAY,aACrB,CAAE,SACF,YAAY,WAAa;AAAA,MACxB,QAAQ,KAAK,UAAU,CAAC;AAAA,MACxB,QAAQ,KAAK,UAAU,CAAC;AAAA,IACzB,CAAE,IACF;AAAA,IACH,QAAQ,OAAQ,SAAe;AAC9B,YAAM,UAA8B;AAAA,QACnC,QAAQ,KAAK,UAAU,CAAC;AAAA,QACxB,QAAQ,KAAK,QAAQ,CAAC;AAAA,MACvB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