@wordpress/boot 0.24.0 → 0.26.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 (75) hide show
  1. package/build-module/components/app/index.mjs +29 -53
  2. package/build-module/components/app/index.mjs.map +1 -7
  3. package/build-module/components/app/router.mjs +238 -214
  4. package/build-module/components/app/router.mjs.map +1 -7
  5. package/build-module/components/app/use-route-title.mjs +35 -42
  6. package/build-module/components/app/use-route-title.mjs.map +1 -7
  7. package/build-module/components/canvas/back-button.mjs +21 -20
  8. package/build-module/components/canvas/back-button.mjs.map +1 -7
  9. package/build-module/components/canvas/index.mjs +103 -129
  10. package/build-module/components/canvas/index.mjs.map +1 -7
  11. package/build-module/components/canvas/site-preview.mjs +36 -43
  12. package/build-module/components/canvas/site-preview.mjs.map +1 -7
  13. package/build-module/components/canvas/use-navigate-to-entity-record.mjs +109 -113
  14. package/build-module/components/canvas/use-navigate-to-entity-record.mjs.map +1 -7
  15. package/build-module/components/canvas/viewport.mjs +25 -13
  16. package/build-module/components/canvas/viewport.mjs.map +1 -7
  17. package/build-module/components/canvas-renderer/index.mjs +40 -32
  18. package/build-module/components/canvas-renderer/index.mjs.map +1 -7
  19. package/build-module/components/error-boundary/index.mjs +160 -108
  20. package/build-module/components/error-boundary/index.mjs.map +1 -7
  21. package/build-module/components/navigation/drilldown-item/index.mjs +124 -127
  22. package/build-module/components/navigation/drilldown-item/index.mjs.map +1 -7
  23. package/build-module/components/navigation/dropdown-item/index.mjs +156 -173
  24. package/build-module/components/navigation/dropdown-item/index.mjs.map +1 -7
  25. package/build-module/components/navigation/index.mjs +55 -90
  26. package/build-module/components/navigation/index.mjs.map +1 -7
  27. package/build-module/components/navigation/items.mjs +51 -53
  28. package/build-module/components/navigation/items.mjs.map +1 -7
  29. package/build-module/components/navigation/navigation-item/index.mjs +120 -114
  30. package/build-module/components/navigation/navigation-item/index.mjs.map +1 -7
  31. package/build-module/components/navigation/navigation-screen/index.mjs +192 -185
  32. package/build-module/components/navigation/navigation-screen/index.mjs.map +1 -7
  33. package/build-module/components/navigation/path-matching.mjs +74 -73
  34. package/build-module/components/navigation/path-matching.mjs.map +1 -7
  35. package/build-module/components/navigation/router-link-item.mjs +13 -11
  36. package/build-module/components/navigation/router-link-item.mjs.map +1 -7
  37. package/build-module/components/navigation/use-sidebar-parent.mjs +37 -48
  38. package/build-module/components/navigation/use-sidebar-parent.mjs.map +1 -7
  39. package/build-module/components/plugin-area/index.mjs +20 -24
  40. package/build-module/components/plugin-area/index.mjs.map +1 -7
  41. package/build-module/components/root/index.mjs +227 -242
  42. package/build-module/components/root/index.mjs.map +1 -7
  43. package/build-module/components/root/single-page.mjs +174 -148
  44. package/build-module/components/root/single-page.mjs.map +1 -7
  45. package/build-module/components/root/use-sync-body-background.mjs +28 -22
  46. package/build-module/components/root/use-sync-body-background.mjs.map +1 -7
  47. package/build-module/components/save-button/index.mjs +170 -214
  48. package/build-module/components/save-button/index.mjs.map +1 -7
  49. package/build-module/components/save-panel/index.mjs +110 -106
  50. package/build-module/components/save-panel/index.mjs.map +1 -7
  51. package/build-module/components/save-panel/use-save-shortcut.mjs +42 -51
  52. package/build-module/components/save-panel/use-save-shortcut.mjs.map +1 -7
  53. package/build-module/components/sidebar/index.mjs +126 -104
  54. package/build-module/components/sidebar/index.mjs.map +1 -7
  55. package/build-module/index.mjs +1 -7
  56. package/build-module/lock-unlock.mjs +5 -10
  57. package/build-module/lock-unlock.mjs.map +1 -7
  58. package/build-module/store/actions.mjs +34 -31
  59. package/build-module/store/actions.mjs.map +1 -7
  60. package/build-module/store/index.mjs +9 -11
  61. package/build-module/store/index.mjs.map +1 -7
  62. package/build-module/store/reducer.mjs +48 -55
  63. package/build-module/store/reducer.mjs.map +1 -7
  64. package/build-module/store/selectors.mjs +21 -16
  65. package/build-module/store/selectors.mjs.map +1 -7
  66. package/build-module/store/types.mjs +0 -1
  67. package/build-types/components/error-boundary/index.d.ts.map +1 -1
  68. package/build-types/store/types.d.ts +1 -1
  69. package/package.json +30 -31
  70. package/src/components/canvas/index.tsx +2 -2
  71. package/src/components/error-boundary/index.tsx +50 -4
  72. package/src/store/types.ts +1 -1
  73. package/CHANGELOG.md +0 -81
  74. package/build-module/index.mjs.map +0 -7
  75. package/build-module/store/types.mjs.map +0 -7
@@ -1,129 +1,181 @@
1
- // packages/boot/src/components/error-boundary/index.tsx
2
- import { Component } from "@wordpress/element";
1
+ import { speak } from "@wordpress/a11y";
2
+ import { Component, useEffect, useState } from "@wordpress/element";
3
3
  import { __ } from "@wordpress/i18n";
4
4
  import { Button } from "@wordpress/components";
5
5
  import { EmptyState } from "@wordpress/ui";
6
6
  import { useCopyToClipboard } from "@wordpress/compose";
7
- import { caution } from "@wordpress/icons";
8
-
7
+ import { caution, check, copy, error } from "@wordpress/icons";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
9
  // packages/style-runtime/src/index.ts
10
- var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
10
+ const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
11
+ /**
12
+ * Returns the shared style runtime registry.
13
+ *
14
+ * The registry is stored on `globalThis` so separately bundled copies of this
15
+ * package can coordinate through the same document and style maps.
16
+ *
17
+ * @return The shared runtime registry.
18
+ */
11
19
  function getRuntime() {
12
- const globalScope = globalThis;
13
- if (globalScope.__wpStyleRuntime) {
14
- return globalScope.__wpStyleRuntime;
15
- }
16
- globalScope.__wpStyleRuntime = {
17
- documents: /* @__PURE__ */ new Map(),
18
- styles: /* @__PURE__ */ new Map(),
19
- injectedStyles: /* @__PURE__ */ new WeakMap()
20
- };
21
- if (typeof document !== "undefined") {
22
- registerDocument(document);
23
- }
24
- return globalScope.__wpStyleRuntime;
20
+ const globalScope = globalThis;
21
+ if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
22
+ globalScope.__wpStyleRuntime = {
23
+ documents: /* @__PURE__ */ new Map(),
24
+ styles: /* @__PURE__ */ new Map(),
25
+ injectedStyles: /* @__PURE__ */ new WeakMap()
26
+ };
27
+ if (typeof document !== "undefined") registerDocument(document);
28
+ return globalScope.__wpStyleRuntime;
25
29
  }
30
+ /**
31
+ * Checks whether a document already contains a style tag for a hash.
32
+ *
33
+ * @param targetDocument Document to inspect.
34
+ * @param hash Stable hash for the transformed CSS.
35
+ *
36
+ * @return Whether the style hash already exists in the document.
37
+ */
26
38
  function documentContainsStyleHash(targetDocument, hash) {
27
- if (!targetDocument.head) {
28
- return false;
29
- }
30
- for (const style of targetDocument.head.querySelectorAll(
31
- `style[${STYLE_HASH_ATTRIBUTE}]`
32
- )) {
33
- if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
34
- return true;
35
- }
36
- }
37
- return false;
39
+ if (!targetDocument.head) return false;
40
+ for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
41
+ return false;
38
42
  }
43
+ /**
44
+ * Injects a registered style into a document, unless that document already
45
+ * contains a style tag for the same hash.
46
+ *
47
+ * @param targetDocument Document to inject the style into.
48
+ * @param hash Stable hash for the transformed CSS.
49
+ * @param css CSS text to inject.
50
+ */
39
51
  function injectStyle(targetDocument, hash, css) {
40
- if (!targetDocument.head) {
41
- return;
42
- }
43
- const runtime = getRuntime();
44
- let injectedStyles = runtime.injectedStyles.get(targetDocument);
45
- if (!injectedStyles) {
46
- injectedStyles = /* @__PURE__ */ new Set();
47
- runtime.injectedStyles.set(targetDocument, injectedStyles);
48
- }
49
- if (injectedStyles.has(hash)) {
50
- return;
51
- }
52
- if (documentContainsStyleHash(targetDocument, hash)) {
53
- injectedStyles.add(hash);
54
- return;
55
- }
56
- const style = targetDocument.createElement("style");
57
- style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
58
- style.appendChild(targetDocument.createTextNode(css));
59
- targetDocument.head.appendChild(style);
60
- injectedStyles.add(hash);
52
+ if (!targetDocument.head) return;
53
+ const runtime = getRuntime();
54
+ let injectedStyles = runtime.injectedStyles.get(targetDocument);
55
+ if (!injectedStyles) {
56
+ injectedStyles = /* @__PURE__ */ new Set();
57
+ runtime.injectedStyles.set(targetDocument, injectedStyles);
58
+ }
59
+ if (injectedStyles.has(hash)) return;
60
+ if (documentContainsStyleHash(targetDocument, hash)) {
61
+ injectedStyles.add(hash);
62
+ return;
63
+ }
64
+ const style = targetDocument.createElement("style");
65
+ style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
66
+ style.appendChild(targetDocument.createTextNode(css));
67
+ targetDocument.head.appendChild(style);
68
+ injectedStyles.add(hash);
61
69
  }
70
+ /**
71
+ * Registers a document as a style injection target.
72
+ *
73
+ * Existing registered styles are replayed into the document immediately.
74
+ * Documents are reference-counted so multiple providers can safely register the
75
+ * same document without one cleanup removing it while another registration is
76
+ * still active.
77
+ *
78
+ * @param targetDocument Document to receive registered styles.
79
+ * @return Cleanup function that unregisters this document registration.
80
+ */
62
81
  function registerDocument(targetDocument) {
63
- const runtime = getRuntime();
64
- runtime.documents.set(
65
- targetDocument,
66
- (runtime.documents.get(targetDocument) ?? 0) + 1
67
- );
68
- for (const [hash, css] of runtime.styles) {
69
- injectStyle(targetDocument, hash, css);
70
- }
71
- return () => {
72
- const count = runtime.documents.get(targetDocument);
73
- if (count === void 0) {
74
- return;
75
- }
76
- if (count <= 1) {
77
- runtime.documents.delete(targetDocument);
78
- return;
79
- }
80
- runtime.documents.set(targetDocument, count - 1);
81
- };
82
+ const runtime = getRuntime();
83
+ runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
84
+ for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
85
+ return () => {
86
+ const count = runtime.documents.get(targetDocument);
87
+ if (count === void 0) return;
88
+ if (count <= 1) {
89
+ runtime.documents.delete(targetDocument);
90
+ return;
91
+ }
92
+ runtime.documents.set(targetDocument, count - 1);
93
+ };
82
94
  }
95
+ /**
96
+ * Registers a style and injects it into all registered documents.
97
+ *
98
+ * The hash is used as the deduplication key, so calling this repeatedly with
99
+ * the same hash will not add duplicate style tags to a document.
100
+ * Registered styles are retained for the lifetime of the page so they can be
101
+ * replayed into documents that are registered later.
102
+ *
103
+ * @param hash Stable hash for the transformed CSS.
104
+ * @param css CSS text to inject.
105
+ */
83
106
  function registerStyle(hash, css) {
84
- const runtime = getRuntime();
85
- runtime.styles.set(hash, css);
86
- for (const targetDocument of runtime.documents.keys()) {
87
- injectStyle(targetDocument, hash, css);
88
- }
107
+ const runtime = getRuntime();
108
+ runtime.styles.set(hash, css);
109
+ for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
89
110
  }
90
-
91
111
  // packages/boot/src/components/error-boundary/style.module.scss
92
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
93
- registerStyle("4780fe0b1b", "._4d71ad18128c9cb8__error-boundary{align-items:center;box-sizing:border-box;display:flex;justify-content:center;min-height:100%;padding:16px}");
94
- }
95
- var style_module_default = { "error-boundary": "_4d71ad18128c9cb8__error-boundary" };
96
-
112
+ if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("f23470a71f", "._69e0fe7ecf360e98__error-boundary{align-items:center;box-sizing:border-box;display:flex;justify-content:center;min-height:100%;padding:16px}");
113
+ var style_module_default = { "error-boundary": "_69e0fe7ecf360e98__error-boundary" };
97
114
  // packages/boot/src/components/error-boundary/index.tsx
98
- import { jsx, jsxs } from "react/jsx-runtime";
115
+ const COPY_FEEDBACK_TIMEOUT = 2e3;
116
+ const RESULT_ICON = {
117
+ idle: copy,
118
+ copied: check,
119
+ error
120
+ };
99
121
  function CopyErrorButton({ error }) {
100
- const ref = useCopyToClipboard(() => error.stack ?? String(error));
101
- return /* @__PURE__ */ jsx(Button, { __next40pxDefaultSize: true, variant: "secondary", ref, children: __("Copy error") });
122
+ const [feedback, setFeedback] = useState({
123
+ result: "idle",
124
+ id: 0
125
+ });
126
+ useEffect(() => {
127
+ if (feedback.result === "idle") return;
128
+ const timeoutId = setTimeout(() => setFeedback({
129
+ result: "idle",
130
+ id: 0
131
+ }), COPY_FEEDBACK_TIMEOUT);
132
+ return () => clearTimeout(timeoutId);
133
+ }, [feedback]);
134
+ function report(result, message) {
135
+ setFeedback((current) => ({
136
+ result,
137
+ id: current.id + 1
138
+ }));
139
+ speak(message);
140
+ }
141
+ const ref = useCopyToClipboard(() => error.stack ?? String(error), () => report("copied", __("Copied to clipboard")), () => report("error", __("Couldn't copy to clipboard.")));
142
+ return /* @__PURE__ */ jsx(Button, {
143
+ __next40pxDefaultSize: true,
144
+ variant: "secondary",
145
+ ref,
146
+ icon: RESULT_ICON[feedback.result],
147
+ children: __("Copy error")
148
+ });
102
149
  }
150
+ /**
151
+ * Contains a failure to one surface, so a screen keeps working around it.
152
+ *
153
+ * Wrapping each surface separately means a stage that throws leaves the
154
+ * navigation, the canvas and the way to save reachable, rather than taking the
155
+ * whole screen down with it.
156
+ */
103
157
  var ErrorBoundary = class extends Component {
104
- constructor(props) {
105
- super(props);
106
- this.state = { error: null };
107
- }
108
- static getDerivedStateFromError(error) {
109
- return { error };
110
- }
111
- render() {
112
- const { error } = this.state;
113
- if (!error) {
114
- return this.props.children;
115
- }
116
- return /* @__PURE__ */ jsx("div", { className: style_module_default["error-boundary"], children: /* @__PURE__ */ jsxs(EmptyState.Root, { children: [
117
- /* @__PURE__ */ jsx(EmptyState.Icon, { icon: caution }),
118
- /* @__PURE__ */ jsx(EmptyState.Title, { children: __("Something went wrong") }),
119
- /* @__PURE__ */ jsx(EmptyState.Description, { children: __(
120
- "This part of the screen could not be displayed. Reloading the page may help."
121
- ) }),
122
- /* @__PURE__ */ jsx(EmptyState.Actions, { children: /* @__PURE__ */ jsx(CopyErrorButton, { error }) })
123
- ] }) });
124
- }
158
+ constructor(props) {
159
+ super(props);
160
+ this.state = { error: null };
161
+ }
162
+ static getDerivedStateFromError(error) {
163
+ return { error };
164
+ }
165
+ render() {
166
+ const { error } = this.state;
167
+ if (!error) return this.props.children;
168
+ return /* @__PURE__ */ jsx("div", {
169
+ className: style_module_default["error-boundary"],
170
+ children: /* @__PURE__ */ jsxs(EmptyState.Root, { children: [
171
+ /* @__PURE__ */ jsx(EmptyState.Icon, { icon: caution }),
172
+ /* @__PURE__ */ jsx(EmptyState.Title, { children: __("Something went wrong") }),
173
+ /* @__PURE__ */ jsx(EmptyState.Description, { children: __("This part of the screen could not be displayed. Reloading the page may help.") }),
174
+ /* @__PURE__ */ jsx(EmptyState.Actions, { children: /* @__PURE__ */ jsx(CopyErrorButton, { error }) })
175
+ ] })
176
+ });
177
+ }
125
178
  };
126
- export {
127
- ErrorBoundary as default
128
- };
129
- //# sourceMappingURL=index.mjs.map
179
+ export { ErrorBoundary as default };
180
+
181
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/error-boundary/index.tsx", "../../../../style-runtime/src/index.ts", "../../../src/components/error-boundary/style.module.scss"],
4
- "sourcesContent": ["import type { ReactNode } from 'react';\nimport { Component } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { EmptyState } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { caution } from '@wordpress/icons';\nimport styles from './style.module.scss';\n\ninterface Props {\n\tchildren: ReactNode;\n}\n\ninterface State {\n\terror: Error | null;\n}\n\nfunction CopyErrorButton( { error }: { error: Error } ) {\n\tconst ref = useCopyToClipboard( () => error.stack ?? String( error ) );\n\n\treturn (\n\t\t<Button __next40pxDefaultSize variant=\"secondary\" ref={ ref }>\n\t\t\t{ __( 'Copy error' ) }\n\t\t</Button>\n\t);\n}\n\n/**\n * Contains a failure to one surface, so a screen keeps working around it.\n *\n * Wrapping each surface separately means a stage that throws leaves the\n * navigation, the canvas and the way to save reachable, rather than taking the\n * whole screen down with it.\n */\nexport default class ErrorBoundary extends Component< Props, State > {\n\tconstructor( props: Props ) {\n\t\tsuper( props );\n\t\tthis.state = { error: null };\n\t}\n\n\tstatic getDerivedStateFromError( error: Error ): State {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error } = this.state;\n\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn (\n\t\t\t<div className={ styles[ 'error-boundary' ] }>\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ caution } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'Something went wrong' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t\t<EmptyState.Description>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This part of the screen could not be displayed. Reloading the page may help.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</EmptyState.Description>\n\t\t\t\t\t<EmptyState.Actions>\n\t\t\t\t\t\t<CopyErrorButton error={ error } />\n\t\t\t\t\t</EmptyState.Actions>\n\t\t\t\t</EmptyState.Root>\n\t\t\t</div>\n\t\t);\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(\"4780fe0b1b\", \"._4d71ad18128c9cb8__error-boundary{align-items:center;box-sizing:border-box;display:flex;justify-content:center;min-height:100%;padding:16px}\");\n}\nexport default {\"error-boundary\":\"_4d71ad18128c9cb8__error-boundary\"};\n"],
5
- "mappings": ";AACA,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,0BAA0B;AACnC,SAAS,eAAe;;;ACIxB,IAAM,uBAAuB;AAU7B,SAAS,aAAa;AACrB,QAAM,cAAc;A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C,SAAI,WAAY,qBAAQ,gBAAiB,GACzC,+BAAC,WAAW,MAAX,EACA;AAAA,0BAAC,WAAW,MAAX,EAAgB,MAAO,SAAU;AAAA,MAClC,oBAAC,WAAW,OAAX,EACE,aAAI,sBAAuB,GAC9B;AAAA,MACA,oBAAC,WAAW,aAAX,EACE;AAAA,QACD;AAAA,MACD,GACD;AAAA,MACA,oBAAC,WAAW,SAAX,EACA,8BAAC,mBAAgB,OAAgB,GAClC;AAAA,OACD,GACD;AAAA,EAEF;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":["errorIcon","styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/error-boundary/style.module.scss","../../../src/components/error-boundary/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(\"f23470a71f\", \"._69e0fe7ecf360e98__error-boundary{align-items:center;box-sizing:border-box;display:flex;justify-content:center;min-height:100%;padding:16px}\");\n}\nexport default {\"error-boundary\":\"_69e0fe7ecf360e98__error-boundary\"};\n","import type { ReactNode } from 'react';\nimport { speak } from '@wordpress/a11y';\nimport { Component, useEffect, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { EmptyState } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { caution, check, copy, error as errorIcon } from '@wordpress/icons';\nimport styles from './style.module.scss';\n\ninterface Props {\n\tchildren: ReactNode;\n}\n\ninterface State {\n\terror: Error | null;\n}\n\nconst COPY_FEEDBACK_TIMEOUT = 2000;\n\ntype CopyResult = 'idle' | 'copied' | 'error';\n\nconst RESULT_ICON = {\n\tidle: copy,\n\tcopied: check,\n\terror: errorIcon,\n};\n\nfunction CopyErrorButton( { error }: { error: Error } ) {\n\t// Bump the id on every result so a repeat of the same outcome restarts\n\t// the time the icon stays visible.\n\tconst [ feedback, setFeedback ] = useState< {\n\t\tresult: CopyResult;\n\t\tid: number;\n\t} >( { result: 'idle', id: 0 } );\n\n\tuseEffect( () => {\n\t\tif ( feedback.result === 'idle' ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeoutId = setTimeout(\n\t\t\t() => setFeedback( { result: 'idle', id: 0 } ),\n\t\t\tCOPY_FEEDBACK_TIMEOUT\n\t\t);\n\t\treturn () => clearTimeout( timeoutId );\n\t}, [ feedback ] );\n\n\tfunction report( result: Exclude< CopyResult, 'idle' >, message: string ) {\n\t\tsetFeedback( ( current ) => ( {\n\t\t\tresult,\n\t\t\tid: current.id + 1,\n\t\t} ) );\n\t\tspeak( message );\n\t}\n\n\tconst ref = useCopyToClipboard(\n\t\t() => error.stack ?? String( error ),\n\t\t() => report( 'copied', __( 'Copied to clipboard' ) ),\n\t\t() => report( 'error', __( \"Couldn't copy to clipboard.\" ) )\n\t);\n\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tvariant=\"secondary\"\n\t\t\tref={ ref }\n\t\t\ticon={ RESULT_ICON[ feedback.result ] }\n\t\t>\n\t\t\t{ __( 'Copy error' ) }\n\t\t</Button>\n\t);\n}\n\n/**\n * Contains a failure to one surface, so a screen keeps working around it.\n *\n * Wrapping each surface separately means a stage that throws leaves the\n * navigation, the canvas and the way to save reachable, rather than taking the\n * whole screen down with it.\n */\nexport default class ErrorBoundary extends Component< Props, State > {\n\tconstructor( props: Props ) {\n\t\tsuper( props );\n\t\tthis.state = { error: null };\n\t}\n\n\tstatic getDerivedStateFromError( error: Error ): State {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error } = this.state;\n\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn (\n\t\t\t<div className={ styles[ 'error-boundary' ] }>\n\t\t\t\t<EmptyState.Root>\n\t\t\t\t\t<EmptyState.Icon icon={ caution } />\n\t\t\t\t\t<EmptyState.Title>\n\t\t\t\t\t\t{ __( 'Something went wrong' ) }\n\t\t\t\t\t</EmptyState.Title>\n\t\t\t\t\t<EmptyState.Description>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This part of the screen could not be displayed. Reloading the page may help.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</EmptyState.Description>\n\t\t\t\t\t<EmptyState.Actions>\n\t\t\t\t\t\t<CopyErrorButton error={ error } />\n\t\t\t\t\t</EmptyState.Actions>\n\t\t\t\t</EmptyState.Root>\n\t\t\t</div>\n\t\t);\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,gBA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1,144 +1,141 @@
1
- // packages/boot/src/components/navigation/drilldown-item/index.tsx
2
1
  import clsx from "clsx";
3
- import {
4
- FlexBlock,
5
- __experimentalItem as Item,
6
- __experimentalHStack as HStack,
7
- Icon as WCIcon
8
- } from "@wordpress/components";
2
+ import { FlexBlock, Icon, __experimentalHStack, __experimentalItem } from "@wordpress/components";
9
3
  import { isRTL } from "@wordpress/i18n";
10
- import { chevronRightSmall, chevronLeftSmall } from "@wordpress/icons";
4
+ import { chevronLeftSmall, chevronRightSmall } from "@wordpress/icons";
11
5
  import { wrapIcon } from "../items.mjs";
12
-
6
+ import { jsx, jsxs } from "react/jsx-runtime";
13
7
  // packages/style-runtime/src/index.ts
14
- var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
8
+ const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
9
+ /**
10
+ * Returns the shared style runtime registry.
11
+ *
12
+ * The registry is stored on `globalThis` so separately bundled copies of this
13
+ * package can coordinate through the same document and style maps.
14
+ *
15
+ * @return The shared runtime registry.
16
+ */
15
17
  function getRuntime() {
16
- const globalScope = globalThis;
17
- if (globalScope.__wpStyleRuntime) {
18
- return globalScope.__wpStyleRuntime;
19
- }
20
- globalScope.__wpStyleRuntime = {
21
- documents: /* @__PURE__ */ new Map(),
22
- styles: /* @__PURE__ */ new Map(),
23
- injectedStyles: /* @__PURE__ */ new WeakMap()
24
- };
25
- if (typeof document !== "undefined") {
26
- registerDocument(document);
27
- }
28
- return globalScope.__wpStyleRuntime;
18
+ const globalScope = globalThis;
19
+ if (globalScope.__wpStyleRuntime) return globalScope.__wpStyleRuntime;
20
+ globalScope.__wpStyleRuntime = {
21
+ documents: /* @__PURE__ */ new Map(),
22
+ styles: /* @__PURE__ */ new Map(),
23
+ injectedStyles: /* @__PURE__ */ new WeakMap()
24
+ };
25
+ if (typeof document !== "undefined") registerDocument(document);
26
+ return globalScope.__wpStyleRuntime;
29
27
  }
28
+ /**
29
+ * Checks whether a document already contains a style tag for a hash.
30
+ *
31
+ * @param targetDocument Document to inspect.
32
+ * @param hash Stable hash for the transformed CSS.
33
+ *
34
+ * @return Whether the style hash already exists in the document.
35
+ */
30
36
  function documentContainsStyleHash(targetDocument, hash) {
31
- if (!targetDocument.head) {
32
- return false;
33
- }
34
- for (const style of targetDocument.head.querySelectorAll(
35
- `style[${STYLE_HASH_ATTRIBUTE}]`
36
- )) {
37
- if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
38
- return true;
39
- }
40
- }
41
- return false;
37
+ if (!targetDocument.head) return false;
38
+ for (const style of targetDocument.head.querySelectorAll(`style[${STYLE_HASH_ATTRIBUTE}]`)) if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) return true;
39
+ return false;
42
40
  }
41
+ /**
42
+ * Injects a registered style into a document, unless that document already
43
+ * contains a style tag for the same hash.
44
+ *
45
+ * @param targetDocument Document to inject the style into.
46
+ * @param hash Stable hash for the transformed CSS.
47
+ * @param css CSS text to inject.
48
+ */
43
49
  function injectStyle(targetDocument, hash, css) {
44
- if (!targetDocument.head) {
45
- return;
46
- }
47
- const runtime = getRuntime();
48
- let injectedStyles = runtime.injectedStyles.get(targetDocument);
49
- if (!injectedStyles) {
50
- injectedStyles = /* @__PURE__ */ new Set();
51
- runtime.injectedStyles.set(targetDocument, injectedStyles);
52
- }
53
- if (injectedStyles.has(hash)) {
54
- return;
55
- }
56
- if (documentContainsStyleHash(targetDocument, hash)) {
57
- injectedStyles.add(hash);
58
- return;
59
- }
60
- const style = targetDocument.createElement("style");
61
- style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
62
- style.appendChild(targetDocument.createTextNode(css));
63
- targetDocument.head.appendChild(style);
64
- injectedStyles.add(hash);
50
+ if (!targetDocument.head) return;
51
+ const runtime = getRuntime();
52
+ let injectedStyles = runtime.injectedStyles.get(targetDocument);
53
+ if (!injectedStyles) {
54
+ injectedStyles = /* @__PURE__ */ new Set();
55
+ runtime.injectedStyles.set(targetDocument, injectedStyles);
56
+ }
57
+ if (injectedStyles.has(hash)) return;
58
+ if (documentContainsStyleHash(targetDocument, hash)) {
59
+ injectedStyles.add(hash);
60
+ return;
61
+ }
62
+ const style = targetDocument.createElement("style");
63
+ style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
64
+ style.appendChild(targetDocument.createTextNode(css));
65
+ targetDocument.head.appendChild(style);
66
+ injectedStyles.add(hash);
65
67
  }
68
+ /**
69
+ * Registers a document as a style injection target.
70
+ *
71
+ * Existing registered styles are replayed into the document immediately.
72
+ * Documents are reference-counted so multiple providers can safely register the
73
+ * same document without one cleanup removing it while another registration is
74
+ * still active.
75
+ *
76
+ * @param targetDocument Document to receive registered styles.
77
+ * @return Cleanup function that unregisters this document registration.
78
+ */
66
79
  function registerDocument(targetDocument) {
67
- const runtime = getRuntime();
68
- runtime.documents.set(
69
- targetDocument,
70
- (runtime.documents.get(targetDocument) ?? 0) + 1
71
- );
72
- for (const [hash, css] of runtime.styles) {
73
- injectStyle(targetDocument, hash, css);
74
- }
75
- return () => {
76
- const count = runtime.documents.get(targetDocument);
77
- if (count === void 0) {
78
- return;
79
- }
80
- if (count <= 1) {
81
- runtime.documents.delete(targetDocument);
82
- return;
83
- }
84
- runtime.documents.set(targetDocument, count - 1);
85
- };
80
+ const runtime = getRuntime();
81
+ runtime.documents.set(targetDocument, (runtime.documents.get(targetDocument) ?? 0) + 1);
82
+ for (const [hash, css] of runtime.styles) injectStyle(targetDocument, hash, css);
83
+ return () => {
84
+ const count = runtime.documents.get(targetDocument);
85
+ if (count === void 0) return;
86
+ if (count <= 1) {
87
+ runtime.documents.delete(targetDocument);
88
+ return;
89
+ }
90
+ runtime.documents.set(targetDocument, count - 1);
91
+ };
86
92
  }
93
+ /**
94
+ * Registers a style and injects it into all registered documents.
95
+ *
96
+ * The hash is used as the deduplication key, so calling this repeatedly with
97
+ * the same hash will not add duplicate style tags to a document.
98
+ * Registered styles are retained for the lifetime of the page so they can be
99
+ * replayed into documents that are registered later.
100
+ *
101
+ * @param hash Stable hash for the transformed CSS.
102
+ * @param css CSS text to inject.
103
+ */
87
104
  function registerStyle(hash, css) {
88
- const runtime = getRuntime();
89
- runtime.styles.set(hash, css);
90
- for (const targetDocument of runtime.documents.keys()) {
91
- injectStyle(targetDocument, hash, css);
92
- }
105
+ const runtime = getRuntime();
106
+ runtime.styles.set(hash, css);
107
+ for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
93
108
  }
94
-
95
109
  // packages/boot/src/components/navigation/navigation-item/style.module.scss
96
- if (typeof process === "undefined" || process.env.NODE_ENV !== "test") {
97
- registerStyle("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}");
98
- }
99
- var style_module_default = { "item": "d5331ded354c389a__item", "is-compact": "_44ce5374f19a05f7__is-compact" };
100
-
110
+ if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("1f139f6281", "._42242b9e34dc6a19__item._42242b9e34dc6a19__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)}._42242b9e34dc6a19__item._42242b9e34dc6a19__item:focus,._42242b9e34dc6a19__item._42242b9e34dc6a19__item:hover,._42242b9e34dc6a19__item._42242b9e34dc6a19__item[aria-current=true]{color:var(--wpds-color-foreground-interactive-brand-active,color-mix(in oklch,var(--wp-admin-theme-color,#3858e9) 52%,#000))}._42242b9e34dc6a19__item._42242b9e34dc6a19__item svg:last-child{padding:4px}._42242b9e34dc6a19__item._42242b9e34dc6a19__item[aria-current=page],._42242b9e34dc6a19__item._42242b9e34dc6a19__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)}._42242b9e34dc6a19__item._42242b9e34dc6a19__item:focus-visible{transform:translateZ(0)}._42242b9e34dc6a19__item._5feca241f78b1f09__is-compact{min-height:24px}");
111
+ var style_module_default = {
112
+ "item": "_42242b9e34dc6a19__item",
113
+ "is-compact": "_5feca241f78b1f09__is-compact"
114
+ };
101
115
  // packages/boot/src/components/navigation/drilldown-item/index.tsx
102
- import { jsx, jsxs } from "react/jsx-runtime";
103
- function DrilldownItem({
104
- className,
105
- id,
106
- icon,
107
- shouldShowPlaceholder = true,
108
- children,
109
- onNavigate
110
- }) {
111
- const handleClick = (e) => {
112
- e.preventDefault();
113
- onNavigate({ id, direction: "forward" });
114
- };
115
- return /* @__PURE__ */ jsx(
116
- Item,
117
- {
118
- className: clsx(style_module_default.item, className),
119
- onClick: handleClick,
120
- children: /* @__PURE__ */ jsxs(
121
- HStack,
122
- {
123
- justify: "flex-start",
124
- spacing: 2,
125
- style: { flexGrow: "1" },
126
- children: [
127
- wrapIcon(icon, shouldShowPlaceholder),
128
- /* @__PURE__ */ jsx(FlexBlock, { children }),
129
- /* @__PURE__ */ jsx(
130
- WCIcon,
131
- {
132
- icon: isRTL() ? chevronLeftSmall : chevronRightSmall
133
- }
134
- )
135
- ]
136
- }
137
- )
138
- }
139
- );
116
+ function DrilldownItem({ className, id, icon, shouldShowPlaceholder = true, children, onNavigate }) {
117
+ const handleClick = (e) => {
118
+ e.preventDefault();
119
+ onNavigate({
120
+ id,
121
+ direction: "forward"
122
+ });
123
+ };
124
+ return /* @__PURE__ */ jsx(__experimentalItem, {
125
+ className: clsx(style_module_default.item, className),
126
+ onClick: handleClick,
127
+ children: /* @__PURE__ */ jsxs(__experimentalHStack, {
128
+ justify: "flex-start",
129
+ spacing: 2,
130
+ style: { flexGrow: "1" },
131
+ children: [
132
+ wrapIcon(icon, shouldShowPlaceholder),
133
+ /* @__PURE__ */ jsx(FlexBlock, { children }),
134
+ /* @__PURE__ */ jsx(Icon, { icon: isRTL() ? chevronLeftSmall : chevronRightSmall })
135
+ ]
136
+ })
137
+ });
140
138
  }
141
- export {
142
- DrilldownItem as default
143
- };
144
- //# sourceMappingURL=index.mjs.map
139
+ export { DrilldownItem as default };
140
+
141
+ //# sourceMappingURL=index.mjs.map