@wordpress/boot 0.25.0 → 0.27.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/build-module/components/app/index.mjs +29 -53
- package/build-module/components/app/index.mjs.map +1 -7
- package/build-module/components/app/router.mjs +238 -214
- package/build-module/components/app/router.mjs.map +1 -7
- package/build-module/components/app/use-route-title.mjs +35 -42
- package/build-module/components/app/use-route-title.mjs.map +1 -7
- package/build-module/components/canvas/back-button.mjs +21 -20
- package/build-module/components/canvas/back-button.mjs.map +1 -7
- package/build-module/components/canvas/index.mjs +104 -130
- package/build-module/components/canvas/index.mjs.map +1 -7
- package/build-module/components/canvas/site-preview.mjs +36 -43
- package/build-module/components/canvas/site-preview.mjs.map +1 -7
- package/build-module/components/canvas/use-navigate-to-entity-record.mjs +109 -113
- package/build-module/components/canvas/use-navigate-to-entity-record.mjs.map +1 -7
- package/build-module/components/canvas/viewport.mjs +25 -13
- package/build-module/components/canvas/viewport.mjs.map +1 -7
- package/build-module/components/canvas-renderer/index.mjs +40 -32
- package/build-module/components/canvas-renderer/index.mjs.map +1 -7
- package/build-module/components/error-boundary/index.mjs +161 -109
- package/build-module/components/error-boundary/index.mjs.map +1 -7
- package/build-module/components/navigation/drilldown-item/index.mjs +124 -127
- package/build-module/components/navigation/drilldown-item/index.mjs.map +1 -7
- package/build-module/components/navigation/dropdown-item/index.mjs +156 -173
- package/build-module/components/navigation/dropdown-item/index.mjs.map +1 -7
- package/build-module/components/navigation/index.mjs +55 -90
- package/build-module/components/navigation/index.mjs.map +1 -7
- package/build-module/components/navigation/items.mjs +51 -53
- package/build-module/components/navigation/items.mjs.map +1 -7
- package/build-module/components/navigation/navigation-item/index.mjs +120 -114
- package/build-module/components/navigation/navigation-item/index.mjs.map +1 -7
- package/build-module/components/navigation/navigation-screen/index.mjs +192 -185
- package/build-module/components/navigation/navigation-screen/index.mjs.map +1 -7
- package/build-module/components/navigation/path-matching.mjs +74 -73
- package/build-module/components/navigation/path-matching.mjs.map +1 -7
- package/build-module/components/navigation/router-link-item.mjs +13 -11
- package/build-module/components/navigation/router-link-item.mjs.map +1 -7
- package/build-module/components/navigation/use-sidebar-parent.mjs +37 -48
- package/build-module/components/navigation/use-sidebar-parent.mjs.map +1 -7
- package/build-module/components/plugin-area/index.mjs +20 -24
- package/build-module/components/plugin-area/index.mjs.map +1 -7
- package/build-module/components/root/index.mjs +228 -243
- package/build-module/components/root/index.mjs.map +1 -7
- package/build-module/components/root/single-page.mjs +174 -148
- package/build-module/components/root/single-page.mjs.map +1 -7
- package/build-module/components/root/use-sync-body-background.mjs +28 -22
- package/build-module/components/root/use-sync-body-background.mjs.map +1 -7
- package/build-module/components/save-button/index.mjs +170 -214
- package/build-module/components/save-button/index.mjs.map +1 -7
- package/build-module/components/save-panel/index.mjs +110 -106
- package/build-module/components/save-panel/index.mjs.map +1 -7
- package/build-module/components/save-panel/use-save-shortcut.mjs +42 -51
- package/build-module/components/save-panel/use-save-shortcut.mjs.map +1 -7
- package/build-module/components/sidebar/index.mjs +126 -104
- package/build-module/components/sidebar/index.mjs.map +1 -7
- package/build-module/index.mjs +1 -7
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/store/actions.mjs +34 -31
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/index.mjs +9 -11
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +48 -55
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +21 -16
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/store/types.mjs +0 -1
- package/build-types/components/error-boundary/index.d.ts.map +1 -1
- package/build-types/components/root/index.d.ts.map +1 -1
- package/package.json +28 -28
- package/src/components/error-boundary/index.tsx +52 -6
- package/src/components/navigation/navigation-screen/index.tsx +2 -2
- package/src/components/root/_layout.module.scss +1 -1
- package/src/components/root/index.tsx +7 -3
- package/build-module/index.mjs.map +0 -7
- package/build-module/store/types.mjs.map +0 -7
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { useState, useMemo, useRef } from "@wordpress/element";
|
|
1
|
+
import { useMemo, useRef, useState } from "@wordpress/element";
|
|
3
2
|
import { useSelect } from "@wordpress/data";
|
|
4
3
|
import { STORE_NAME } from "../../store/index.mjs";
|
|
5
4
|
import NavigationItem from "./navigation-item/index.mjs";
|
|
@@ -8,93 +7,59 @@ import DropdownItem from "./dropdown-item/index.mjs";
|
|
|
8
7
|
import NavigationScreen from "./navigation-screen/index.mjs";
|
|
9
8
|
import { useSidebarParent } from "./use-sidebar-parent.mjs";
|
|
10
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
// packages/boot/src/components/navigation/index.tsx
|
|
11
11
|
function Navigation() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
isExpanded: parentDropdownId === item.id,
|
|
63
|
-
onToggle: () => handleDropdownToggle(item.id),
|
|
64
|
-
children: item.label
|
|
65
|
-
},
|
|
66
|
-
item.id
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
if (item.parent_type === "drilldown") {
|
|
70
|
-
return /* @__PURE__ */ jsx(
|
|
71
|
-
DrilldownItem,
|
|
72
|
-
{
|
|
73
|
-
id: item.id,
|
|
74
|
-
icon: item.icon,
|
|
75
|
-
shouldShowPlaceholder: hasRealIcons,
|
|
76
|
-
onNavigate: handleNavigate,
|
|
77
|
-
children: item.label
|
|
78
|
-
},
|
|
79
|
-
item.id
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
return /* @__PURE__ */ jsx(
|
|
83
|
-
NavigationItem,
|
|
84
|
-
{
|
|
85
|
-
to: item.to,
|
|
86
|
-
icon: item.icon,
|
|
87
|
-
shouldShowPlaceholder: hasRealIcons,
|
|
88
|
-
children: item.label
|
|
89
|
-
},
|
|
90
|
-
item.id
|
|
91
|
-
);
|
|
92
|
-
}) })
|
|
93
|
-
}
|
|
94
|
-
);
|
|
12
|
+
const backButtonRef = useRef(null);
|
|
13
|
+
const [animationDirection, setAnimationDirection] = useState(null);
|
|
14
|
+
const [parentId, setParentId, parentDropdownId, setParentDropdownId] = useSidebarParent();
|
|
15
|
+
const menuItems = useSelect((select) => select(STORE_NAME).getMenuItems(), []);
|
|
16
|
+
const parent = useMemo(() => menuItems.find((item) => item.id === parentId), [menuItems, parentId]);
|
|
17
|
+
const navigationKey = parent ? `drilldown-${parent.id}` : "root";
|
|
18
|
+
const handleNavigate = ({ id, direction }) => {
|
|
19
|
+
setAnimationDirection(direction);
|
|
20
|
+
setParentId(id);
|
|
21
|
+
};
|
|
22
|
+
const handleDropdownToggle = (dropdownId) => {
|
|
23
|
+
setParentDropdownId(parentDropdownId === dropdownId ? void 0 : dropdownId);
|
|
24
|
+
};
|
|
25
|
+
const items = useMemo(() => menuItems.filter((item) => item.parent === parentId), [menuItems, parentId]);
|
|
26
|
+
const hasRealIcons = items.some((item) => !!item.icon);
|
|
27
|
+
return /* @__PURE__ */ jsx(NavigationScreen, {
|
|
28
|
+
isRoot: !parent,
|
|
29
|
+
title: parent ? parent.label : "",
|
|
30
|
+
backMenuItem: parent?.parent,
|
|
31
|
+
backButtonRef,
|
|
32
|
+
animationDirection: animationDirection || void 0,
|
|
33
|
+
navigationKey,
|
|
34
|
+
onNavigate: handleNavigate,
|
|
35
|
+
content: /* @__PURE__ */ jsx("div", {
|
|
36
|
+
role: "list",
|
|
37
|
+
children: items.map((item) => {
|
|
38
|
+
if (item.parent_type === "dropdown") return /* @__PURE__ */ jsx(DropdownItem, {
|
|
39
|
+
id: item.id,
|
|
40
|
+
icon: item.icon,
|
|
41
|
+
shouldShowPlaceholder: hasRealIcons,
|
|
42
|
+
isExpanded: parentDropdownId === item.id,
|
|
43
|
+
onToggle: () => handleDropdownToggle(item.id),
|
|
44
|
+
children: item.label
|
|
45
|
+
}, item.id);
|
|
46
|
+
if (item.parent_type === "drilldown") return /* @__PURE__ */ jsx(DrilldownItem, {
|
|
47
|
+
id: item.id,
|
|
48
|
+
icon: item.icon,
|
|
49
|
+
shouldShowPlaceholder: hasRealIcons,
|
|
50
|
+
onNavigate: handleNavigate,
|
|
51
|
+
children: item.label
|
|
52
|
+
}, item.id);
|
|
53
|
+
return /* @__PURE__ */ jsx(NavigationItem, {
|
|
54
|
+
to: item.to,
|
|
55
|
+
icon: item.icon,
|
|
56
|
+
shouldShowPlaceholder: hasRealIcons,
|
|
57
|
+
children: item.label
|
|
58
|
+
}, item.id);
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
});
|
|
95
62
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
//# sourceMappingURL=index.mjs.map
|
|
63
|
+
export { Navigation as default };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/navigation/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useState, useMemo, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { STORE_NAME } from '../../store';\nimport NavigationItem from './navigation-item';\nimport DrilldownItem from './drilldown-item';\nimport DropdownItem from './dropdown-item';\nimport NavigationScreen from './navigation-screen';\nimport { useSidebarParent } from './use-sidebar-parent';\nimport type { MenuItem } from '../../store/types';\n\nfunction Navigation() {\n\tconst backButtonRef = useRef< HTMLButtonElement >( null );\n\tconst [ animationDirection, setAnimationDirection ] = useState<\n\t\t'forward' | 'backward' | null\n\t>( null );\n\tconst [ parentId, setParentId, parentDropdownId, setParentDropdownId ] =\n\t\tuseSidebarParent();\n\tconst menuItems = useSelect(\n\t\t( select ) =>\n\t\t\t// @ts-expect-error Store types are not available when selecting by store name.\n\t\t\tselect( STORE_NAME ).getMenuItems() as MenuItem[],\n\t\t[]\n\t);\n\tconst parent = useMemo(\n\t\t() => menuItems.find( ( item ) => item.id === parentId ),\n\t\t[ menuItems, parentId ]\n\t);\n\t// Create a unique key for the current navigation state\n\t// The sidebar will animate when the key changes.\n\tconst navigationKey = parent ? `drilldown-${ parent.id }` : 'root';\n\n\t// We use transitions to handle navigation clicks\n\t// This allows smooth animations and non blocking navigation.\n\tconst handleNavigate = ( {\n\t\tid,\n\t\tdirection,\n\t}: {\n\t\tid?: string;\n\t\tdirection: 'forward' | 'backward';\n\t} ) => {\n\t\tsetAnimationDirection( direction );\n\t\tsetParentId( id );\n\t};\n\n\tconst handleDropdownToggle = ( dropdownId: string ) => {\n\t\tsetParentDropdownId(\n\t\t\tparentDropdownId === dropdownId ? undefined : dropdownId\n\t\t);\n\t};\n\n\tconst items = useMemo(\n\t\t() => menuItems.filter( ( item ) => item.parent === parentId ),\n\t\t[ menuItems, parentId ]\n\t);\n\n\tconst hasRealIcons = items.some( ( item ) => !! item.icon );\n\n\treturn (\n\t\t<NavigationScreen\n\t\t\tisRoot={ ! parent }\n\t\t\ttitle={ parent ? parent.label : '' }\n\t\t\tbackMenuItem={ parent?.parent }\n\t\t\tbackButtonRef={ backButtonRef }\n\t\t\tanimationDirection={ animationDirection || undefined }\n\t\t\tnavigationKey={ navigationKey }\n\t\t\tonNavigate={ handleNavigate }\n\t\t\tcontent={\n\t\t\t\t<div role=\"list\">\n\t\t\t\t\t{ items.map( ( item: MenuItem ) => {\n\t\t\t\t\t\tif ( item.parent_type === 'dropdown' ) {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<DropdownItem\n\t\t\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\t\t\tid={ item.id }\n\t\t\t\t\t\t\t\t\ticon={ item.icon }\n\t\t\t\t\t\t\t\t\tshouldShowPlaceholder={ hasRealIcons }\n\t\t\t\t\t\t\t\t\tisExpanded={ parentDropdownId === item.id }\n\t\t\t\t\t\t\t\t\tonToggle={ () =>\n\t\t\t\t\t\t\t\t\t\thandleDropdownToggle( item.id )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</DropdownItem>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif ( item.parent_type === 'drilldown' ) {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<DrilldownItem\n\t\t\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\t\t\tid={ item.id }\n\t\t\t\t\t\t\t\t\ticon={ item.icon }\n\t\t\t\t\t\t\t\t\tshouldShowPlaceholder={ hasRealIcons }\n\t\t\t\t\t\t\t\t\tonNavigate={ handleNavigate }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</DrilldownItem>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<NavigationItem\n\t\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\t\tto={ item.to }\n\t\t\t\t\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AA,EACvB;AAEA,QAAM,eAAe,MAAM,KAAM,CAAE,SAAU,CAAC,CAAE,KAAK,IAAK;AAE1D,SACC;AAAA,IAAC;AAAA;AAAA,MACA,QAAS,CAAE;AAAA,MACX,OAAQ,SAAS,OAAO,QAAQ;AAAA,MAChC,cAAe,QAAQ;AAAA,MACvB;AAAA,MACA,oBAAqB,sBAAsB;AAAA,MAC3C;AAAA,MACA,YAAa;AAAA,MACb,SACC,oBAAC,SAAI,MAAK,QACP,gBAAM,IAAK,CAAE,SAAoB;AAClC,YAAK,KAAK,gBAAgB,YAAa;AACtC,iBACC;AAAA,YAAC;AAAA;AAAA,cAEA,IAAK,KAAK;AAAA,cACV,MAAO,KAAK;AAAA,cACZ,uBAAwB;AAAA,cACxB,YAAa,qBAAqB,KAAK;AAAA,cACvC,UAAW,MACV,qBAAsB,KAAK,EAAG;AAAA,cAG7B,eAAK;AAAA;AAAA,YATD,KAAK;AAAA,UAUZ;AAAA,QAEF;AAEA,YAAK,KAAK,gBAAgB,aAAc;AACvC,iBACC;AAAA,YAAC;AAAA;AAAA,cAEA,IAAK,KAAK;AAAA,cACV,MAAO,KAAK;AAAA,cACZ,uBAAwB;AAAA,cACxB,YAAa;AAAA,cAEX,eAAK;AAAA;AAAA,YAND,KAAK;AAAA,UAOZ;AAAA,QAEF;AAEA,eACC;AAAA,UAAC;AAAA;AAAA,YAEA,IAAK,KAAK;AAAA,YACV,MAAO,KAAK;AAAA,YACZ,uBAAwB;AAAA,YAEtB,eAAK;AAAA;AAAA,UALD,KAAK;AAAA,QAMZ;AAAA,MAEF,CAAE,GACH;AAAA;AAAA,EAEF;AAEF;AAEA,IAAO,qBAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/navigation/index.tsx"],"sourcesContent":["import { useState, useMemo, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { STORE_NAME } from '../../store';\nimport NavigationItem from './navigation-item';\nimport DrilldownItem from './drilldown-item';\nimport DropdownItem from './dropdown-item';\nimport NavigationScreen from './navigation-screen';\nimport { useSidebarParent } from './use-sidebar-parent';\nimport type { MenuItem } from '../../store/types';\n\nfunction Navigation() {\n\tconst backButtonRef = useRef< HTMLButtonElement >( null );\n\tconst [ animationDirection, setAnimationDirection ] = useState<\n\t\t'forward' | 'backward' | null\n\t>( null );\n\tconst [ parentId, setParentId, parentDropdownId, setParentDropdownId ] =\n\t\tuseSidebarParent();\n\tconst menuItems = useSelect(\n\t\t( select ) =>\n\t\t\t// @ts-expect-error Store types are not available when selecting by store name.\n\t\t\tselect( STORE_NAME ).getMenuItems() as MenuItem[],\n\t\t[]\n\t);\n\tconst parent = useMemo(\n\t\t() => menuItems.find( ( item ) => item.id === parentId ),\n\t\t[ menuItems, parentId ]\n\t);\n\t// Create a unique key for the current navigation state\n\t// The sidebar will animate when the key changes.\n\tconst navigationKey = parent ? `drilldown-${ parent.id }` : 'root';\n\n\t// We use transitions to handle navigation clicks\n\t// This allows smooth animations and non blocking navigation.\n\tconst handleNavigate = ( {\n\t\tid,\n\t\tdirection,\n\t}: {\n\t\tid?: string;\n\t\tdirection: 'forward' | 'backward';\n\t} ) => {\n\t\tsetAnimationDirection( direction );\n\t\tsetParentId( id );\n\t};\n\n\tconst handleDropdownToggle = ( dropdownId: string ) => {\n\t\tsetParentDropdownId(\n\t\t\tparentDropdownId === dropdownId ? undefined : dropdownId\n\t\t);\n\t};\n\n\tconst items = useMemo(\n\t\t() => menuItems.filter( ( item ) => item.parent === parentId ),\n\t\t[ menuItems, parentId ]\n\t);\n\n\tconst hasRealIcons = items.some( ( item ) => !! item.icon );\n\n\treturn (\n\t\t<NavigationScreen\n\t\t\tisRoot={ ! parent }\n\t\t\ttitle={ parent ? parent.label : '' }\n\t\t\tbackMenuItem={ parent?.parent }\n\t\t\tbackButtonRef={ backButtonRef }\n\t\t\tanimationDirection={ animationDirection || undefined }\n\t\t\tnavigationKey={ navigationKey }\n\t\t\tonNavigate={ handleNavigate }\n\t\t\tcontent={\n\t\t\t\t<div role=\"list\">\n\t\t\t\t\t{ items.map( ( item: MenuItem ) => {\n\t\t\t\t\t\tif ( item.parent_type === 'dropdown' ) {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<DropdownItem\n\t\t\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\t\t\tid={ item.id }\n\t\t\t\t\t\t\t\t\ticon={ item.icon }\n\t\t\t\t\t\t\t\t\tshouldShowPlaceholder={ hasRealIcons }\n\t\t\t\t\t\t\t\t\tisExpanded={ parentDropdownId === item.id }\n\t\t\t\t\t\t\t\t\tonToggle={ () =>\n\t\t\t\t\t\t\t\t\t\thandleDropdownToggle( item.id )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</DropdownItem>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif ( item.parent_type === 'drilldown' ) {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<DrilldownItem\n\t\t\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\t\t\tid={ item.id }\n\t\t\t\t\t\t\t\t\ticon={ item.icon }\n\t\t\t\t\t\t\t\t\tshouldShowPlaceholder={ hasRealIcons }\n\t\t\t\t\t\t\t\t\tonNavigate={ handleNavigate }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t</DrilldownItem>\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<NavigationItem\n\t\t\t\t\t\t\t\tkey={ item.id }\n\t\t\t\t\t\t\t\tto={ item.to }\n\t\t\t\t\t\t\t\ticon={ item.icon }\n\t\t\t\t\t\t\t\tshouldShowPlaceholder={ hasRealIcons }\n\t\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K,EAAG;KAG7B,UAAA,KAAK;IACM,GAVP,KAAK,EAUE;IAIhB,IAAK,KAAK,gBAAgB,aACzB,OACC,oBAAC,eAAD;KAEC,IAAK,KAAK;KACV,MAAO,KAAK;KACZ,uBAAwB;KACxB,YAAa;KAEX,UAAA,KAAK;IACO,GAPR,KAAK,EAOG;IAIjB,OACC,oBAAC,gBAAD;KAEC,IAAK,KAAK;KACV,MAAO,KAAK;KACZ,uBAAwB;KAEtB,UAAA,KAAK;IACQ,GANT,KAAK,EAMI;GAElB,CAAE;EACE,CAAA;CAEN,CAAA;AAEH"}
|
|
@@ -1,60 +1,58 @@
|
|
|
1
|
-
// packages/boot/src/components/navigation/items.tsx
|
|
2
1
|
import { isValidElement } from "@wordpress/element";
|
|
3
|
-
import { Dashicon, Icon
|
|
2
|
+
import { Dashicon, Icon } from "@wordpress/components";
|
|
4
3
|
import { SVG } from "@wordpress/primitives";
|
|
5
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// packages/boot/src/components/navigation/items.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Type guard for verifying whether a given element
|
|
8
|
+
* is a valid SVG element for the Icon component.
|
|
9
|
+
*
|
|
10
|
+
* @param element - The element to check
|
|
11
|
+
*/
|
|
6
12
|
function isSvg(element) {
|
|
7
|
-
|
|
13
|
+
return isValidElement(element) && (element.type === SVG || element.type === "svg");
|
|
8
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Converts the given IconType into a renderable component:
|
|
17
|
+
* - Dashicon string into a Dashicon component
|
|
18
|
+
* - JSX SVG element into an Icon component
|
|
19
|
+
* - Data URL into an img element
|
|
20
|
+
*
|
|
21
|
+
* @param icon - The icon to convert
|
|
22
|
+
* @param shouldShowPlaceholder - Whether to show placeholder when no icon is provided
|
|
23
|
+
* @return The converted icon as a JSX element
|
|
24
|
+
*/
|
|
9
25
|
function wrapIcon(icon, shouldShowPlaceholder = true) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
if (icon) {
|
|
44
|
-
return icon;
|
|
45
|
-
}
|
|
46
|
-
if (shouldShowPlaceholder) {
|
|
47
|
-
return /* @__PURE__ */ jsx(
|
|
48
|
-
"div",
|
|
49
|
-
{
|
|
50
|
-
style: { width: "24px", height: "24px" },
|
|
51
|
-
"aria-hidden": "true"
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
26
|
+
if (isSvg(icon)) return /* @__PURE__ */ jsx(Icon, { icon });
|
|
27
|
+
if (typeof icon === "string" && icon.startsWith("dashicons-")) {
|
|
28
|
+
const iconKey = icon.replace(/^dashicons-/, "");
|
|
29
|
+
return /* @__PURE__ */ jsx(Dashicon, {
|
|
30
|
+
style: { padding: "2px" },
|
|
31
|
+
icon: iconKey,
|
|
32
|
+
"aria-hidden": "true"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (typeof icon === "string" && icon.startsWith("data:")) return /* @__PURE__ */ jsx("img", {
|
|
36
|
+
src: icon,
|
|
37
|
+
alt: "",
|
|
38
|
+
"aria-hidden": "true",
|
|
39
|
+
style: {
|
|
40
|
+
width: "20px",
|
|
41
|
+
height: "20px",
|
|
42
|
+
display: "block",
|
|
43
|
+
padding: "2px"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (icon) return icon;
|
|
47
|
+
if (shouldShowPlaceholder) return /* @__PURE__ */ jsx("div", {
|
|
48
|
+
style: {
|
|
49
|
+
width: "24px",
|
|
50
|
+
height: "24px"
|
|
51
|
+
},
|
|
52
|
+
"aria-hidden": "true"
|
|
53
|
+
});
|
|
54
|
+
return null;
|
|
56
55
|
}
|
|
57
|
-
export {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
//# sourceMappingURL=items.mjs.map
|
|
56
|
+
export { wrapIcon };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=items.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/navigation/items.tsx"],
|
|
4
|
-
"sourcesContent": ["import { isValidElement } from '@wordpress/element';\nimport { Dashicon, Icon as WCIcon } from '@wordpress/components';\nimport { SVG } from '@wordpress/primitives';\nimport type { IconType } from '../../store/types';\n\n/**\n * Type guard for verifying whether a given element\n * is a valid SVG element for the Icon component.\n *\n * @param element - The element to check\n */\nfunction isSvg( element: unknown ): element is React.JSX.Element {\n\treturn (\n\t\tisValidElement( element ) &&\n\t\t( element.type === SVG || element.type === 'svg' )\n\t);\n}\n\n/**\n * Converts the given IconType into a renderable component:\n * - Dashicon string into a Dashicon component\n * - JSX SVG element into an Icon component\n * - Data URL into an img element\n *\n * @param icon - The icon to convert\n * @param shouldShowPlaceholder - Whether to show placeholder when no icon is provided\n * @return The converted icon as a JSX element\n */\nexport function wrapIcon(\n\ticon?: IconType,\n\tshouldShowPlaceholder: boolean = true\n) {\n\tif ( isSvg( icon ) ) {\n\t\treturn <WCIcon icon={ icon } />;\n\t}\n\n\tif ( typeof icon === 'string' && icon.startsWith( 'dashicons-' ) ) {\n\t\tconst iconKey = icon.replace(\n\t\t\t/^dashicons-/,\n\t\t\t''\n\t\t) as React.ComponentProps< typeof Dashicon >[ 'icon' ];\n\n\t\treturn (\n\t\t\t<Dashicon\n\t\t\t\tstyle={ { padding: '2px' } }\n\t\t\t\ticon={ iconKey }\n\t\t\t\taria-hidden=\"true\"\n\t\t\t/>\n\t\t);\n\t}\n\n\t// Handle data URLs (SVG images)\n\tif ( typeof icon === 'string' && icon.startsWith( 'data:' ) ) {\n\t\treturn (\n\t\t\t<img\n\t\t\t\tsrc={ icon }\n\t\t\t\talt=\"\"\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth: '20px',\n\t\t\t\t\theight: '20px',\n\t\t\t\t\tdisplay: 'block',\n\t\t\t\t\tpadding: '2px',\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t}\n\n\t// If icon is provided and valid, return it as-is\n\tif ( icon ) {\n\t\treturn icon;\n\t}\n\n\t// Return empty 24px placeholder for alignment when no icon is provided\n\t// Only if shouldShowPlaceholder is true\n\tif ( shouldShowPlaceholder ) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tstyle={ { width: '24px', height: '24px' } }\n\t\t\t\taria-hidden=\"true\"\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,sBAAsB;AAC/B,SAAS,UAAU,QAAQ,cAAc;AACzC,SAAS,WAAW;AA+BX;AAtBT,SAAS,MAAO,SAAiD;AAChE,SACC,eAAgB,OAAQ,MACtB,QAAQ,SAAS,OAAO,QAAQ,SAAS;AAE7C;AAYO,SAAS,SACf,MACA,wBAAiC,MAChC;AACD,MAAK,MAAO,IAAK,GAAI;AACpB,WAAO,oBAAC,UAAO,MAAc;AAAA,EAC9B;AAEA,MAAK,OAAO,SAAS,YAAY,KAAK,WAAY,YAAa,GAAI;AAClE,UAAM,UAAU,KAAK;AAAA,MACpB;AAAA,MACA;AAAA,IACD;AAEA,WACC;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,EAAE,SAAS,MAAM;AAAA,QACzB,MAAO;AAAA,QACP,eAAY;AAAA;AAAA,IACb;AAAA,EAEF;AAGA,MAAK,OAAO,SAAS,YAAY,KAAK,WAAY,OAAQ,GAAI;AAC7D,WACC;AAAA,MAAC;AAAA;AAAA,QACA,KAAM;AAAA,QACN,KAAI;AAAA,QACJ,eAAY;AAAA,QACZ,OAAQ;AAAA,UACP,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,SAAS;AAAA,UACT,SAAS;AAAA,QACV;AAAA;AAAA,IACD;AAAA,EAEF;AAGA,MAAK,MAAO;AACX,WAAO;AAAA,EACR;AAIA,MAAK,uBAAwB;AAC5B,WACC;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,EAAE,OAAO,QAAQ,QAAQ,OAAO;AAAA,QACxC,eAAY;AAAA;AAAA,IACb;AAAA,EAEF;AAEA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"items.mjs","names":["WCIcon"],"sources":["../../../src/components/navigation/items.tsx"],"sourcesContent":["import { isValidElement } from '@wordpress/element';\nimport { Dashicon, Icon as WCIcon } from '@wordpress/components';\nimport { SVG } from '@wordpress/primitives';\nimport type { IconType } from '../../store/types';\n\n/**\n * Type guard for verifying whether a given element\n * is a valid SVG element for the Icon component.\n *\n * @param element - The element to check\n */\nfunction isSvg( element: unknown ): element is React.JSX.Element {\n\treturn (\n\t\tisValidElement( element ) &&\n\t\t( element.type === SVG || element.type === 'svg' )\n\t);\n}\n\n/**\n * Converts the given IconType into a renderable component:\n * - Dashicon string into a Dashicon component\n * - JSX SVG element into an Icon component\n * - Data URL into an img element\n *\n * @param icon - The icon to convert\n * @param shouldShowPlaceholder - Whether to show placeholder when no icon is provided\n * @return The converted icon as a JSX element\n */\nexport function wrapIcon(\n\ticon?: IconType,\n\tshouldShowPlaceholder: boolean = true\n) {\n\tif ( isSvg( icon ) ) {\n\t\treturn <WCIcon icon={ icon } />;\n\t}\n\n\tif ( typeof icon === 'string' && icon.startsWith( 'dashicons-' ) ) {\n\t\tconst iconKey = icon.replace(\n\t\t\t/^dashicons-/,\n\t\t\t''\n\t\t) as React.ComponentProps< typeof Dashicon >[ 'icon' ];\n\n\t\treturn (\n\t\t\t<Dashicon\n\t\t\t\tstyle={ { padding: '2px' } }\n\t\t\t\ticon={ iconKey }\n\t\t\t\taria-hidden=\"true\"\n\t\t\t/>\n\t\t);\n\t}\n\n\t// Handle data URLs (SVG images)\n\tif ( typeof icon === 'string' && icon.startsWith( 'data:' ) ) {\n\t\treturn (\n\t\t\t<img\n\t\t\t\tsrc={ icon }\n\t\t\t\talt=\"\"\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tstyle={ {\n\t\t\t\t\twidth: '20px',\n\t\t\t\t\theight: '20px',\n\t\t\t\t\tdisplay: 'block',\n\t\t\t\t\tpadding: '2px',\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t}\n\n\t// If icon is provided and valid, return it as-is\n\tif ( icon ) {\n\t\treturn icon;\n\t}\n\n\t// Return empty 24px placeholder for alignment when no icon is provided\n\t// Only if shouldShowPlaceholder is true\n\tif ( shouldShowPlaceholder ) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tstyle={ { width: '24px', height: '24px' } }\n\t\t\t\taria-hidden=\"true\"\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn null;\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAS,MAAO,SAAiD;CAChE,OACC,eAAgB,OAAQ,MACtB,QAAQ,SAAS,OAAO,QAAQ,SAAS;AAE7C;;;;;;;;;;;AAYA,SAAgB,SACf,MACA,wBAAiC,MAChC;CACD,IAAK,MAAO,IAAK,GAChB,OAAO,oBAACA,MAAD,EAAe,KAAQ,CAAA;CAG/B,IAAK,OAAO,SAAS,YAAY,KAAK,WAAY,YAAa,GAAI;EAClE,MAAM,UAAU,KAAK,QACpB,eACA,EACD;EAEA,OACC,oBAAC,UAAD;GACC,OAAQ,EAAE,SAAS,MAAM;GACzB,MAAO;GACP,eAAY;EACZ,CAAA;CAEH;CAGA,IAAK,OAAO,SAAS,YAAY,KAAK,WAAY,OAAQ,GACzD,OACC,oBAAC,OAAD;EACC,KAAM;EACN,KAAI;EACJ,eAAY;EACZ,OAAQ;GACP,OAAO;GACP,QAAQ;GACR,SAAS;GACT,SAAS;EACV;CACA,CAAA;CAKH,IAAK,MACJ,OAAO;CAKR,IAAK,uBACJ,OACC,oBAAC,OAAD;EACC,OAAQ;GAAE,OAAO;GAAQ,QAAQ;EAAO;EACxC,eAAY;CACZ,CAAA;CAIH,OAAO;AACR"}
|
|
@@ -1,131 +1,137 @@
|
|
|
1
|
-
// packages/boot/src/components/navigation/navigation-item/index.tsx
|
|
2
1
|
import clsx from "clsx";
|
|
3
|
-
import {
|
|
4
|
-
FlexBlock,
|
|
5
|
-
__experimentalItem as Item,
|
|
6
|
-
__experimentalHStack as HStack
|
|
7
|
-
} from "@wordpress/components";
|
|
2
|
+
import { FlexBlock, __experimentalHStack, __experimentalItem } from "@wordpress/components";
|
|
8
3
|
import RouterLinkItem from "../router-link-item.mjs";
|
|
9
4
|
import { wrapIcon } from "../items.mjs";
|
|
10
|
-
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
6
|
// packages/style-runtime/src/index.ts
|
|
12
|
-
|
|
7
|
+
const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
8
|
+
/**
|
|
9
|
+
* Returns the shared style runtime registry.
|
|
10
|
+
*
|
|
11
|
+
* The registry is stored on `globalThis` so separately bundled copies of this
|
|
12
|
+
* package can coordinate through the same document and style maps.
|
|
13
|
+
*
|
|
14
|
+
* @return The shared runtime registry.
|
|
15
|
+
*/
|
|
13
16
|
function getRuntime() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (typeof document !== "undefined") {
|
|
24
|
-
registerDocument(document);
|
|
25
|
-
}
|
|
26
|
-
return globalScope.__wpStyleRuntime;
|
|
17
|
+
const globalScope = globalThis;
|
|
18
|
+
if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
|
|
19
|
+
globalScope.__wpStyleRuntime = {
|
|
20
|
+
documents: /* @__PURE__ */ new Map(),
|
|
21
|
+
styles: /* @__PURE__ */ new Map(),
|
|
22
|
+
injectedStyles: /* @__PURE__ */ new WeakMap()
|
|
23
|
+
};
|
|
24
|
+
if (typeof document !== "undefined") registerDocument(document);
|
|
25
|
+
return globalScope.__wpStyleRuntime;
|
|
27
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether a document already contains a style tag for a hash.
|
|
29
|
+
*
|
|
30
|
+
* @param targetDocument Document to inspect.
|
|
31
|
+
* @param hash Stable hash for the transformed CSS.
|
|
32
|
+
*
|
|
33
|
+
* @return Whether the style hash already exists in the document.
|
|
34
|
+
*/
|
|
28
35
|
function documentContainsStyleHash(targetDocument, hash) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for (const style of targetDocument.head.querySelectorAll(
|
|
33
|
-
`style[${STYLE_HASH_ATTRIBUTE}]`
|
|
34
|
-
)) {
|
|
35
|
-
if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return false;
|
|
36
|
+
if (!targetDocument.head) return false;
|
|
37
|
+
for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
|
|
38
|
+
return false;
|
|
40
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Injects a registered style into a document, unless that document already
|
|
42
|
+
* contains a style tag for the same hash.
|
|
43
|
+
*
|
|
44
|
+
* @param targetDocument Document to inject the style into.
|
|
45
|
+
* @param hash Stable hash for the transformed CSS.
|
|
46
|
+
* @param css CSS text to inject.
|
|
47
|
+
*/
|
|
41
48
|
function injectStyle(targetDocument, hash, css) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
60
|
-
style.appendChild(targetDocument.createTextNode(css));
|
|
61
|
-
targetDocument.head.appendChild(style);
|
|
62
|
-
injectedStyles.add(hash);
|
|
49
|
+
if (!targetDocument.head) return;
|
|
50
|
+
const runtime = getRuntime();
|
|
51
|
+
let injectedStyles = runtime.injectedStyles.get(targetDocument);
|
|
52
|
+
if (!injectedStyles) {
|
|
53
|
+
injectedStyles = /* @__PURE__ */ new Set();
|
|
54
|
+
runtime.injectedStyles.set(targetDocument, injectedStyles);
|
|
55
|
+
}
|
|
56
|
+
if (injectedStyles.has(hash)) return;
|
|
57
|
+
if (documentContainsStyleHash(targetDocument, hash)) {
|
|
58
|
+
injectedStyles.add(hash);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const style = targetDocument.createElement("style");
|
|
62
|
+
style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
|
|
63
|
+
style.appendChild(targetDocument.createTextNode(css));
|
|
64
|
+
targetDocument.head.appendChild(style);
|
|
65
|
+
injectedStyles.add(hash);
|
|
63
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Registers a document as a style injection target.
|
|
69
|
+
*
|
|
70
|
+
* Existing registered styles are replayed into the document immediately.
|
|
71
|
+
* Documents are reference-counted so multiple providers can safely register the
|
|
72
|
+
* same document without one cleanup removing it while another registration is
|
|
73
|
+
* still active.
|
|
74
|
+
*
|
|
75
|
+
* @param targetDocument Document to receive registered styles.
|
|
76
|
+
* @return Cleanup function that unregisters this document registration.
|
|
77
|
+
*/
|
|
64
78
|
function registerDocument(targetDocument) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (count <= 1) {
|
|
79
|
-
runtime.documents.delete(targetDocument);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
runtime.documents.set(targetDocument, count - 1);
|
|
83
|
-
};
|
|
79
|
+
const runtime = getRuntime();
|
|
80
|
+
runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
|
|
81
|
+
for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
|
|
82
|
+
return () => {
|
|
83
|
+
const count = runtime.documents.get(targetDocument);
|
|
84
|
+
if (count === void 0) return;
|
|
85
|
+
if (count <= 1) {
|
|
86
|
+
runtime.documents.delete(targetDocument);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
runtime.documents.set(targetDocument, count - 1);
|
|
90
|
+
};
|
|
84
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Registers a style and injects it into all registered documents.
|
|
94
|
+
*
|
|
95
|
+
* The hash is used as the deduplication key, so calling this repeatedly with
|
|
96
|
+
* the same hash will not add duplicate style tags to a document.
|
|
97
|
+
* Registered styles are retained for the lifetime of the page so they can be
|
|
98
|
+
* replayed into documents that are registered later.
|
|
99
|
+
*
|
|
100
|
+
* @param hash Stable hash for the transformed CSS.
|
|
101
|
+
* @param css CSS text to inject.
|
|
102
|
+
*/
|
|
85
103
|
function registerStyle(hash, css) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
injectStyle(targetDocument, hash, css);
|
|
90
|
-
}
|
|
104
|
+
const runtime = getRuntime();
|
|
105
|
+
runtime.styles.set(hash, css);
|
|
106
|
+
for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
|
|
91
107
|
}
|
|
92
|
-
|
|
93
108
|
// packages/boot/src/components/navigation/navigation-item/style.module.scss
|
|
94
|
-
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
109
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("8d0506d52b", "._873b0f189db62fa3__item._873b0f189db62fa3__item{align-items:center;border:none;border-radius:var(--wpds-border-radius-sm,2px);color:var(--wpds-color-foreground-interactive-neutral,#1e1e1e);display:flex;font-family:var(--wpds-typography-font-family-body,-apple-system,system-ui,\"Segoe UI\",\"Roboto\",\"Oxygen-Sans\",\"Ubuntu\",\"Cantarell\",\"Helvetica Neue\",sans-serif);font-size:var(--wpds-typography-font-size-md,13px);font-weight:var(--wpds-typography-font-weight-default,400);line-height:var(--wpds-typography-line-height-sm,20px);margin-block-end:4px;margin-inline:12px;min-height:32px;padding-block:0;padding-inline:4px;width:calc(100% - 24px)}._873b0f189db62fa3__item._873b0f189db62fa3__item:focus,._873b0f189db62fa3__item._873b0f189db62fa3__item:hover,._873b0f189db62fa3__item._873b0f189db62fa3__item[aria-current=true]{color:var(--wpds-color-foreground-interactive-brand-active,color-mix(in oklch,var(--wp-admin-theme-color,#3858e9) 52%,#000))}._873b0f189db62fa3__item._873b0f189db62fa3__item svg:last-child{padding:4px}._873b0f189db62fa3__item._873b0f189db62fa3__item[aria-current=page],._873b0f189db62fa3__item._873b0f189db62fa3__item[data-status=active]{color:var(--wpds-color-foreground-interactive-brand-active,color-mix(in oklch,var(--wp-admin-theme-color,#3858e9) 52%,#000));font-weight:var(--wpds-typography-font-weight-emphasis,600)}._873b0f189db62fa3__item._873b0f189db62fa3__item:focus-visible{transform:translateZ(0)}._873b0f189db62fa3__item._1ac4ca98dd21cec1__is-compact{min-height:24px}");
|
|
110
|
+
var style_module_default = {
|
|
111
|
+
"item": "_873b0f189db62fa3__item",
|
|
112
|
+
"is-compact": "_1ac4ca98dd21cec1__is-compact"
|
|
113
|
+
};
|
|
99
114
|
// packages/boot/src/components/navigation/navigation-item/index.tsx
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
as: "a",
|
|
120
|
-
href: to,
|
|
121
|
-
className: clsx(style_module_default.item, className),
|
|
122
|
-
children: content
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return /* @__PURE__ */ jsx(RouterLinkItem, { to, className: clsx(style_module_default.item, className), children: content });
|
|
115
|
+
function NavigationItem({ className, icon, shouldShowPlaceholder = true, children, to }) {
|
|
116
|
+
const isExternal = !String(new URL(to, window.location.origin)).startsWith(window.location.origin);
|
|
117
|
+
const content = /* @__PURE__ */ jsxs(__experimentalHStack, {
|
|
118
|
+
justify: "flex-start",
|
|
119
|
+
spacing: 2,
|
|
120
|
+
style: { flexGrow: "1" },
|
|
121
|
+
children: [wrapIcon(icon, shouldShowPlaceholder), /* @__PURE__ */ jsx(FlexBlock, { children })]
|
|
122
|
+
});
|
|
123
|
+
if (isExternal) return /* @__PURE__ */ jsx(__experimentalItem, {
|
|
124
|
+
as: "a",
|
|
125
|
+
href: to,
|
|
126
|
+
className: clsx(style_module_default.item, className),
|
|
127
|
+
children: content
|
|
128
|
+
});
|
|
129
|
+
return /* @__PURE__ */ jsx(RouterLinkItem, {
|
|
130
|
+
to,
|
|
131
|
+
className: clsx(style_module_default.item, className),
|
|
132
|
+
children: content
|
|
133
|
+
});
|
|
127
134
|
}
|
|
128
|
-
export {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
//# sourceMappingURL=index.mjs.map
|
|
135
|
+
export { NavigationItem as default };
|
|
136
|
+
|
|
137
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/components/navigation/navigation-item/index.tsx", "../../../../../style-runtime/src/index.ts", "../../../../src/components/navigation/navigation-item/style.module.scss"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport type { ReactNode } from 'react';\nimport {\n\tFlexBlock,\n\t__experimentalItem as Item,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport RouterLinkItem from '../router-link-item';\nimport { wrapIcon } from '../items';\nimport type { IconType } from '../../../store/types';\nimport styles from './style.module.scss';\n\ninterface NavigationItemProps {\n\t/**\n\t * Optional CSS class name.\n\t */\n\tclassName?: string;\n\t/**\n\t * Icon to display with the navigation item.\n\t */\n\ticon?: IconType;\n\t/**\n\t * Whether to show placeholder icons for alignment.\n\t */\n\tshouldShowPlaceholder?: boolean;\n\t/**\n\t * Content to display inside the navigation item.\n\t */\n\tchildren: ReactNode;\n\t/**\n\t * The path to navigate to.\n\t */\n\tto: string;\n}\n\nexport default function NavigationItem( {\n\tclassName,\n\ticon,\n\tshouldShowPlaceholder = true,\n\tchildren,\n\tto,\n}: NavigationItemProps ) {\n\t// Check if the 'to' prop is an external URL\n\tconst isExternal = ! String(\n\t\tnew URL( to, window.location.origin )\n\t).startsWith( window.location.origin );\n\n\tconst content = (\n\t\t<HStack justify=\"flex-start\" spacing={ 2 } style={ { flexGrow: '1' } }>\n\t\t\t{ wrapIcon( icon, shouldShowPlaceholder ) }\n\t\t\t<FlexBlock>{ children }</FlexBlock>\n\t\t</HStack>\n\t);\n\n\tif ( isExternal ) {\n\t\t// Render as a regular anchor tag for external URLs\n\t\treturn (\n\t\t\t<Item\n\t\t\t\tas=\"a\"\n\t\t\t\thref={ to }\n\t\t\t\tclassName={ clsx( styles.item, className ) }\n\t\t\t>\n\t\t\t\t{ content }\n\t\t\t</Item>\n\t\t);\n\t}\n\n\treturn (\n\t\t<RouterLinkItem to={ to } className={ clsx( styles.item, className ) }>\n\t\t\t{ content }\n\t\t</RouterLinkItem>\n\t);\n}\n", "type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n", "import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"74796ab776\", \".d5331ded354c389a__item.d5331ded354c389a__item{align-items:center;border:none;border-radius:var(--wpds-border-radius-sm,2px);color:var(--wpds-color-foreground-interactive-neutral,#1e1e1e);display:flex;font-family:-apple-system,system-ui,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:13px;font-weight:var(--wpds-typography-font-weight-default,400);line-height:20px;margin-block-end:4px;margin-inline:12px;min-height:32px;padding-block:0;padding-inline:4px;width:calc(100% - 24px)}.d5331ded354c389a__item.d5331ded354c389a__item:focus,.d5331ded354c389a__item.d5331ded354c389a__item:hover,.d5331ded354c389a__item.d5331ded354c389a__item[aria-current=true]{color:var(--wpds-color-foreground-interactive-brand-active,color-mix(in oklch,var(--wp-admin-theme-color,#3858e9) 52%,#000))}.d5331ded354c389a__item.d5331ded354c389a__item svg:last-child{padding:4px}.d5331ded354c389a__item.d5331ded354c389a__item[aria-current=page],.d5331ded354c389a__item.d5331ded354c389a__item[data-status=active]{color:var(--wpds-color-foreground-interactive-brand-active,color-mix(in oklch,var(--wp-admin-theme-color,#3858e9) 52%,#000));font-weight:var(--wpds-typography-font-weight-emphasis,600)}.d5331ded354c389a__item.d5331ded354c389a__item:focus-visible{transform:translateZ(0)}.d5331ded354c389a__item._44ce5374f19a05f7__is-compact{min-height:24px}\");\n}\nexport default {\"item\":\"d5331ded354c389a__item\",\"is-compact\":\"_44ce5374f19a05f7__is-compact\"};\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,UAAU;AAEjB;AAAA,EACC;AAAA,EACA,sBAA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ACxB;AAGD,MAAK,YAAa;AAEjB,WACC;AAAA,MAAC;AAAA;AAAA,QACA,IAAG;AAAA,QACH,MAAO;AAAA,QACP,WAAY,KAAM,qBAAO,MAAM,SAAU;AAAA,QAEvC;AAAA;AAAA,IACH;AAAA,EAEF;AAEA,SACC,oBAAC,kBAAe,IAAU,WAAY,KAAM,qBAAO,MAAM,SAAU,GAChE,mBACH;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["HStack","Item","styles"],"sources":["../../../../../style-runtime/src/index.ts","../../../../src/components/navigation/navigation-item/style.module.scss","../../../../src/components/navigation/navigation-item/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"8d0506d52b\", \"._873b0f189db62fa3__item._873b0f189db62fa3__item{align-items:center;border:none;border-radius:var(--wpds-border-radius-sm,2px);color:var(--wpds-color-foreground-interactive-neutral,#1e1e1e);display:flex;font-family:var(--wpds-typography-font-family-body,-apple-system,system-ui,\\\"Segoe UI\\\",\\\"Roboto\\\",\\\"Oxygen-Sans\\\",\\\"Ubuntu\\\",\\\"Cantarell\\\",\\\"Helvetica Neue\\\",sans-serif);font-size:var(--wpds-typography-font-size-md,13px);font-weight:var(--wpds-typography-font-weight-default,400);line-height:var(--wpds-typography-line-height-sm,20px);margin-block-end:4px;margin-inline:12px;min-height:32px;padding-block:0;padding-inline:4px;width:calc(100% - 24px)}._873b0f189db62fa3__item._873b0f189db62fa3__item:focus,._873b0f189db62fa3__item._873b0f189db62fa3__item:hover,._873b0f189db62fa3__item._873b0f189db62fa3__item[aria-current=true]{color:var(--wpds-color-foreground-interactive-brand-active,color-mix(in oklch,var(--wp-admin-theme-color,#3858e9) 52%,#000))}._873b0f189db62fa3__item._873b0f189db62fa3__item svg:last-child{padding:4px}._873b0f189db62fa3__item._873b0f189db62fa3__item[aria-current=page],._873b0f189db62fa3__item._873b0f189db62fa3__item[data-status=active]{color:var(--wpds-color-foreground-interactive-brand-active,color-mix(in oklch,var(--wp-admin-theme-color,#3858e9) 52%,#000));font-weight:var(--wpds-typography-font-weight-emphasis,600)}._873b0f189db62fa3__item._873b0f189db62fa3__item:focus-visible{transform:translateZ(0)}._873b0f189db62fa3__item._1ac4ca98dd21cec1__is-compact{min-height:24px}\");\n}\nexport default {\"item\":\"_873b0f189db62fa3__item\",\"is-compact\":\"_1ac4ca98dd21cec1__is-compact\"};\n","import clsx from 'clsx';\nimport type { ReactNode } from 'react';\nimport {\n\tFlexBlock,\n\t__experimentalItem as Item,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport RouterLinkItem from '../router-link-item';\nimport { wrapIcon } from '../items';\nimport type { IconType } from '../../../store/types';\nimport styles from './style.module.scss';\n\ninterface NavigationItemProps {\n\t/**\n\t * Optional CSS class name.\n\t */\n\tclassName?: string;\n\t/**\n\t * Icon to display with the navigation item.\n\t */\n\ticon?: IconType;\n\t/**\n\t * Whether to show placeholder icons for alignment.\n\t */\n\tshouldShowPlaceholder?: boolean;\n\t/**\n\t * Content to display inside the navigation item.\n\t */\n\tchildren: ReactNode;\n\t/**\n\t * The path to navigate to.\n\t */\n\tto: string;\n}\n\nexport default function NavigationItem( {\n\tclassName,\n\ticon,\n\tshouldShowPlaceholder = true,\n\tchildren,\n\tto,\n}: NavigationItemProps ) {\n\t// Check if the 'to' prop is an external URL\n\tconst isExternal = ! String(\n\t\tnew URL( to, window.location.origin )\n\t).startsWith( window.location.origin );\n\n\tconst content = (\n\t\t<HStack justify=\"flex-start\" spacing={ 2 } style={ { flexGrow: '1' } }>\n\t\t\t{ wrapIcon( icon, shouldShowPlaceholder ) }\n\t\t\t<FlexBlock>{ children }</FlexBlock>\n\t\t</HStack>\n\t);\n\n\tif ( isExternal ) {\n\t\t// Render as a regular anchor tag for external URLs\n\t\treturn (\n\t\t\t<Item\n\t\t\t\tas=\"a\"\n\t\t\t\thref={ to }\n\t\t\t\tclassName={ clsx( styles.item, className ) }\n\t\t\t>\n\t\t\t\t{ content }\n\t\t\t</Item>\n\t\t);\n\t}\n\n\treturn (\n\t\t<RouterLinkItem to={ to } className={ clsx( styles.item, className ) }>\n\t\t\t{ content }\n\t\t</RouterLinkItem>\n\t);\n}\n"],"mappings":";;;;;;AAUA,MAAM,uBAAuB;;;;;;;;;AAU7B,SAAS,aAAa;CACrB,MAAM,cAAc;CAEpB,IAAK,YAAY,kBAChB,OAAO,YAAY;CAGpB,YAAY,mBAAmB;EAC9B,2BAAW,IAAI,IAAI;EACnB,wBAAQ,IAAI,IAAI;EAChB,gCAAgB,IAAI,QAAQ;CAC7B;CAEA,IAAK,OAAO,aAAa,aACxB,iBAAkB,QAAS;CAG5B,OAAO,YAAY;AACpB;;;;;;;;;AAUA,SAAS,0BACR,gBACA,MACU;CACV,IAAK,CAAE,eAAe,MACrB,OAAO;CAGR,KAAM,MAAM,SAAS,eAAe,KAAK,iBACxC,SAAU,qBAAsB,EACjC,GACC,IAAK,MAAM,aAAc,oBAAqB,MAAM,MACnD,OAAO;CAIT,OAAO;AACR;;;;;;;;;AAUA,SAAS,YAAa,gBAA0B,MAAc,KAAc;CAC3E,IAAK,CAAE,eAAe,MACrB;CAGD,MAAM,UAAU,WAAW;CAC3B,IAAI,iBAAiB,QAAQ,eAAe,IAAK,cAAe;CAEhE,IAAK,CAAE,gBAAiB;EACvB,iCAAiB,IAAI,IAAI;EACzB,QAAQ,eAAe,IAAK,gBAAgB,cAAe;CAC5D;CAEA,IAAK,eAAe,IAAK,IAAK,GAC7B;CAMD,IAAK,0BAA2B,gBAAgB,IAAK,GAAI;EACxD,eAAe,IAAK,IAAK;EACz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