@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
204 lines (203 loc) • 9.25 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_i18n = require("@wordpress/i18n");
let _wordpress_element = require("@wordpress/element");
let _wordpress_components = require("@wordpress/components");
let _wordpress_data = require("@wordpress/data");
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_block_editor = require("@wordpress/block-editor");
let __screen_header_tsx = require("./screen-header.cjs");
let __element_preview_tsx = require("./element-preview.cjs");
__element_preview_tsx = __toESM(__element_preview_tsx);
let __element_block_overrides_tsx = require("./element-block-overrides.cjs");
__element_block_overrides_tsx = __toESM(__element_block_overrides_tsx);
let __hooks_ts = require("./hooks.cjs");
let __lock_unlock_ts = require("./lock-unlock.cjs");
let __utils_ts = require("./utils.cjs");
let __screen_block_tsx = require("./screen-block.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/global-styles-ui/src/screen-element.tsx
const { useSettingsForBlockElement, useHasBackgroundPanel, useHasBorderPanel, useHasDimensionsPanel, useHasTypographyPanel, BackgroundPanel: StylesBackgroundPanel, BorderPanel: StylesBorderPanel, DimensionsPanel: StylesDimensionsPanel, TypographyPanel: StylesTypographyPanel, AdvancedPanel: StylesAdvancedPanel, getBlockTypesForElement } = (0, __lock_unlock_ts.unlock)(_wordpress_block_editor.privateApis);
const ELEMENTS = {
text: {
description: (0, _wordpress_i18n.__)("Manage the fonts used on the site."),
title: (0, _wordpress_i18n.__)("Text")
},
link: {
description: (0, _wordpress_i18n.__)("Manage the appearance of links."),
title: (0, _wordpress_i18n.__)("Link")
},
caption: {
description: (0, _wordpress_i18n.__)("Manage the appearance of captions."),
title: (0, _wordpress_i18n.__)("Caption")
},
cite: {
description: (0, _wordpress_i18n.__)("Manage the appearance of citations."),
title: (0, _wordpress_i18n.__)("Citation")
},
heading: {
description: (0, _wordpress_i18n.__)("Manage the appearance of all headings."),
title: (0, _wordpress_i18n.__)("All headings")
},
h1: {
description: (0, _wordpress_i18n.__)("Manage the appearance of level 1 headings."),
title: (0, _wordpress_i18n.__)("Heading 1")
},
h2: {
description: (0, _wordpress_i18n.__)("Manage the appearance of level 2 headings."),
title: (0, _wordpress_i18n.__)("Heading 2")
},
h3: {
description: (0, _wordpress_i18n.__)("Manage the appearance of level 3 headings."),
title: (0, _wordpress_i18n.__)("Heading 3")
},
h4: {
description: (0, _wordpress_i18n.__)("Manage the appearance of level 4 headings."),
title: (0, _wordpress_i18n.__)("Heading 4")
},
h5: {
description: (0, _wordpress_i18n.__)("Manage the appearance of level 5 headings."),
title: (0, _wordpress_i18n.__)("Heading 5")
},
h6: {
description: (0, _wordpress_i18n.__)("Manage the appearance of level 6 headings."),
title: (0, _wordpress_i18n.__)("Heading 6")
},
textInput: {
description: (0, _wordpress_i18n.__)("Manage the appearance of inputs."),
title: (0, _wordpress_i18n.__)("Form input")
},
select: {
description: (0, _wordpress_i18n.__)("Manage the appearance of selects."),
title: (0, _wordpress_i18n.__)("Form select")
},
button: {
description: (0, _wordpress_i18n.__)("Manage the appearance of buttons."),
title: (0, _wordpress_i18n.__)("Form button")
}
};
/**
* Renders every style panel for an element. The element's settings are
* resolved once here and shared by all the panels, as are the styles that the
* screen resolves for them.
*
* @param props
* @param props.element The element being styled.
* @param props.label Its display name, used in the custom CSS help text.
* @param props.style The element's user styles in the selected state.
* @param props.inheritedStyle The element's merged styles in the selected state.
* @param props.setStyle Saves the element's user styles in the selected state.
*/
function ElementStylePanels({ element, label, style, inheritedStyle, setStyle }) {
const isRoot = element === "text";
const [rawSettings] = (0, __hooks_ts.useSetting)("");
const settings = useSettingsForBlockElement(rawSettings, void 0, element);
const hasTypographyPanel = useHasTypographyPanel(settings);
const hasBackgroundPanel = useHasBackgroundPanel(settings) && !isRoot;
const hasDimensionsPanel = useHasDimensionsPanel(settings) && !isRoot;
const hasBorderPanel = useHasBorderPanel(settings) && !isRoot;
const canEditCSS = (0, __hooks_ts.useCanEditCSS)();
const onChangeBorders = (newStyle) => setStyle((0, __screen_block_tsx.normalizeBorderStyle)(newStyle));
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
hasTypographyPanel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StylesTypographyPanel, {
inheritedValue: inheritedStyle,
value: style,
onChange: setStyle,
settings
}),
hasBackgroundPanel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StylesBackgroundPanel, {
inheritedValue: inheritedStyle,
value: style,
onChange: setStyle,
settings,
defaultValues: __screen_block_tsx.BACKGROUND_BLOCK_DEFAULT_VALUES
}),
hasDimensionsPanel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StylesDimensionsPanel, {
inheritedValue: inheritedStyle,
value: style,
onChange: setStyle,
settings
}),
hasBorderPanel && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StylesBorderPanel, {
inheritedValue: inheritedStyle,
value: style,
onChange: onChangeBorders,
settings
}),
canEditCSS && !isRoot && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.PanelBody, {
title: (0, _wordpress_i18n.__)("Advanced"),
initialOpen: false,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StylesAdvancedPanel, {
value: style,
onChange: setStyle,
inheritedValue: inheritedStyle,
help: (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Add your own CSS to customize the appearance of %s. You do not need to include a CSS selector, just add the property and value."), label)
})
})
] });
}
function ScreenElement({ element: elementProp, showStateControls = true }) {
const { params } = (0, _wordpress_components.useNavigator)();
const element = elementProp ?? params.element;
const [selectedPseudoState, setSelectedPseudoState] = (0, _wordpress_element.useState)("default");
const pseudoStates = (0, _wordpress_element.useMemo)(() => showStateControls ? (0, __utils_ts.getValidPseudoStates)(element) : [], [element, showStateControls]);
const allBlockTypes = (0, _wordpress_data.useSelect)((select) => select(_wordpress_blocks.store).getBlockTypes(), []);
const elementBlockTypes = (0, _wordpress_element.useMemo)(() => getBlockTypesForElement(element).map((name) => allBlockTypes.find((blockType) => blockType.name === name)).filter((blockType) => !!blockType), [element, allBlockTypes]);
const state = selectedPseudoState === "default" ? void 0 : selectedPseudoState;
const prefix = element === "text" ? "" : `elements.${element}`;
const [style] = (0, __hooks_ts.useStyle)(prefix, "", "user", false, state);
const [inheritedStyle, setStyle] = (0, __hooks_ts.useStyle)(prefix, "", "merged", false, state);
if (!Object.hasOwn(ELEMENTS, element)) return null;
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__screen_header_tsx.ScreenHeader, {
title: ELEMENTS[element].title,
description: ELEMENTS[element].description,
pseudoStates,
selectedPseudoState,
onChangePseudoState: setSelectedPseudoState
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__element_preview_tsx.default, {
element,
state,
stateStyles: state ? inheritedStyle : void 0
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ElementStylePanels, {
element,
label: ELEMENTS[element].title,
style,
inheritedStyle,
setStyle
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__element_block_overrides_tsx.default, {
element,
blockTypes: elementBlockTypes
})
] });
}
exports.ELEMENTS = ELEMENTS;
exports.default = ScreenElement;
//# sourceMappingURL=screen-element.cjs.map