@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
252 lines (251 loc) • 12.3 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let _wordpress_components = require("@wordpress/components");
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_data = require("@wordpress/data");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_element = require("@wordpress/element");
let _wordpress_compose = require("@wordpress/compose");
let _wordpress_global_styles_engine = require("@wordpress/global-styles-engine");
let __provider_tsx = require("./provider.cjs");
let __screen_root_tsx = require("./screen-root.cjs");
__screen_root_tsx = __toESM(__screen_root_tsx);
let __screen_block_list_tsx = require("./screen-block-list.cjs");
__screen_block_list_tsx = __toESM(__screen_block_list_tsx);
let __screen_block_tsx = require("./screen-block.cjs");
__screen_block_tsx = __toESM(__screen_block_tsx);
let __screen_typography_tsx = require("./screen-typography.cjs");
__screen_typography_tsx = __toESM(__screen_typography_tsx);
let __screen_element_tsx = require("./screen-element.cjs");
__screen_element_tsx = __toESM(__screen_element_tsx);
let __screen_colors_tsx = require("./screen-colors.cjs");
__screen_colors_tsx = __toESM(__screen_colors_tsx);
let __screen_color_palette_tsx = require("./screen-color-palette.cjs");
__screen_color_palette_tsx = __toESM(__screen_color_palette_tsx);
let __screen_background_tsx = require("./screen-background.cjs");
__screen_background_tsx = __toESM(__screen_background_tsx);
let __screen_shadows_tsx = require("./screen-shadows.cjs");
let __screen_text_shadows_tsx = require("./screen-text-shadows.cjs");
__screen_text_shadows_tsx = __toESM(__screen_text_shadows_tsx);
let __screen_text_shadows_edit_tsx = require("./screen-text-shadows-edit.cjs");
__screen_text_shadows_edit_tsx = __toESM(__screen_text_shadows_edit_tsx);
let __screen_layout_tsx = require("./screen-layout.cjs");
__screen_layout_tsx = __toESM(__screen_layout_tsx);
let __screen_style_variations_tsx = require("./screen-style-variations.cjs");
__screen_style_variations_tsx = __toESM(__screen_style_variations_tsx);
let __screen_css_tsx = require("./screen-css.cjs");
__screen_css_tsx = __toESM(__screen_css_tsx);
let __screen_revisions_index_tsx = require("./screen-revisions/index.cjs");
__screen_revisions_index_tsx = __toESM(__screen_revisions_index_tsx);
let __font_sizes_font_sizes_tsx = require("./font-sizes/font-sizes.cjs");
__font_sizes_font_sizes_tsx = __toESM(__font_sizes_font_sizes_tsx);
let __font_sizes_font_size_tsx = require("./font-sizes/font-size.cjs");
__font_sizes_font_size_tsx = __toESM(__font_sizes_font_size_tsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/global-styles-ui/src/global-styles-ui.tsx
function BlockStylesNavigationScreens({ parentMenu, blockStyles, blockName, selectedViewport, showResponsiveStateControls, showBlockStateControls }) {
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: blockStyles.map((style, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Navigator.Screen, {
path: parentMenu + "/variations/" + style.name,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_block_tsx.default, {
name: blockName,
variation: style.name,
selectedViewport,
showResponsiveStateControls,
showBlockStateControls
})
}, index)) });
}
function ContextScreens({ name, parentMenu = "", selectedViewport, showResponsiveStateControls, showBlockStateControls }) {
const blockStyleVariations = (0, _wordpress_data.useSelect)((select) => {
if (!name) return [];
const { getBlockStyles } = select(_wordpress_blocks.store);
return getBlockStyles(name);
}, [name]);
if (!blockStyleVariations?.length) return null;
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BlockStylesNavigationScreens, {
parentMenu,
blockStyles: blockStyleVariations,
blockName: name || "",
selectedViewport,
showResponsiveStateControls,
showBlockStateControls
});
}
function GlobalStylesUI({ value, baseValue, onChange, path, onPathChange, fontLibraryEnabled = false, serverCSS, serverSettings, selectedViewport, showResponsiveStateControls = true, showBlockStateControls = true }) {
const blocks = (0, _wordpress_blocks.getBlockTypes)();
const mergedValue = (0, _wordpress_element.useMemo)(() => {
return (0, _wordpress_global_styles_engine.mergeGlobalStyles)(baseValue, value);
}, [baseValue, value]);
const [globalStylesCSS, globalSettings] = (0, _wordpress_global_styles_engine.generateGlobalStyles)(mergedValue, [], { styleOptions: { variationStyles: true } });
const styles = (0, _wordpress_element.useMemo)(() => [...serverCSS ?? [], ...globalStylesCSS ?? []], [serverCSS, globalStylesCSS]);
const settings = (0, _wordpress_element.useMemo)(() => {
return {
...serverSettings,
__experimentalFeatures: globalSettings,
styles
};
}, [
globalSettings,
serverSettings,
styles
]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__provider_tsx.GlobalStylesProvider, {
value,
baseValue,
onChange,
fontLibraryEnabled,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockEditorProvider, {
settings,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.Navigator, {
className: "global-styles-ui-sidebar__navigator-provider",
initialPath: path || "/",
children: [
(path || onPathChange) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PathSynchronizer, {
path,
onPathChange
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_root_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/colors",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_colors_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/typography",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_typography_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/typography/text",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_element_tsx.default, { element: "text" })
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/typography/font-sizes",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__font_sizes_font_sizes_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/typography/font-sizes/:origin/:slug",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__font_sizes_font_size_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/layout",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_layout_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/colors/palette",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_color_palette_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/variations",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_style_variations_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/css",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_css_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/revisions/:revisionId?",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_revisions_index_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/shadows",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_shadows_tsx.ScreenShadows, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/shadows/edit/:category/:slug",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_shadows_tsx.ScreenShadowsEdit, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/typography/text-shadows",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_text_shadows_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/typography/text-shadows/edit/:category/:slug",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_text_shadows_edit_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/background",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_background_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/blocks",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_block_list_tsx.default, {})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/blocks/elements/:element",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_element_tsx.default, { showStateControls: showBlockStateControls })
}),
blocks.map((block) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_element.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GlobalStylesNavigationScreen, {
path: "/blocks/" + encodeURIComponent(block.name),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_block_tsx.default, {
name: block.name,
selectedViewport,
showResponsiveStateControls,
showBlockStateControls
})
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContextScreens, {
name: block.name,
parentMenu: "/blocks/" + encodeURIComponent(block.name),
selectedViewport,
showResponsiveStateControls,
showBlockStateControls
})] }, block.name))
]
})
})
});
}
function GlobalStylesNavigationScreen({ path, children }) {
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Navigator.Screen, {
className: "global-styles-ui-sidebar__navigator-screen",
path,
children
});
}
function PathSynchronizer({ path, onPathChange }) {
const navigator = (0, _wordpress_components.useNavigator)();
const { path: childPath } = navigator.location;
const previousParentPath = (0, _wordpress_compose.usePrevious)(path);
const previousChildPath = (0, _wordpress_compose.usePrevious)(childPath);
(0, _wordpress_element.useEffect)(() => {
if (path && path !== childPath) {
if (path !== previousParentPath) navigator.goTo(path);
else if (childPath !== previousChildPath && onPathChange) onPathChange(childPath ?? "/");
}
}, [
onPathChange,
path,
previousChildPath,
previousParentPath,
childPath,
navigator
]);
return null;
}
exports.GlobalStylesUI = GlobalStylesUI;
//# sourceMappingURL=global-styles-ui.cjs.map