@wordpress/block-editor
Version:
88 lines (86 loc) • 3.17 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/components/block-alignment-control/use-available-alignments.js
var use_available_alignments_exports = {};
__export(use_available_alignments_exports, {
default: () => useAvailableAlignments
});
module.exports = __toCommonJS(use_available_alignments_exports);
var import_data = require("@wordpress/data");
var import_layout = require("../block-list/layout");
var import_store = require("../../store");
var import_layouts = require("../../layouts");
var EMPTY_ARRAY = [];
var DEFAULT_CONTROLS = ["none", "left", "center", "right", "wide", "full"];
var WIDE_CONTROLS = ["wide", "full"];
function useAvailableAlignments(controls = DEFAULT_CONTROLS) {
if (!controls.includes("none")) {
controls = ["none", ...controls];
}
const isNoneOnly = controls.length === 1 && controls[0] === "none";
const [wideControlsEnabled, themeSupportsLayout, isBlockBasedTheme] = (0, import_data.useSelect)(
(select) => {
if (isNoneOnly) {
return [false, false, false];
}
const settings = select(import_store.store).getSettings();
return [
settings.alignWide ?? false,
settings.supportsLayout,
settings.__unstableIsBlockBasedTheme
];
},
[isNoneOnly]
);
const layout = (0, import_layout.useLayout)();
if (isNoneOnly) {
return EMPTY_ARRAY;
}
const layoutType = (0, import_layouts.getLayoutType)(layout?.type);
if (themeSupportsLayout) {
const layoutAlignments = layoutType.getAlignments(
layout,
isBlockBasedTheme
);
const alignments2 = layoutAlignments.filter(
(alignment) => controls.includes(alignment.name)
);
if (alignments2.length === 1 && alignments2[0].name === "none") {
return EMPTY_ARRAY;
}
return alignments2;
}
if (layoutType.name !== "default" && layoutType.name !== "constrained") {
return EMPTY_ARRAY;
}
const alignments = controls.filter((control) => {
if (layout.alignments) {
return layout.alignments.includes(control);
}
if (!wideControlsEnabled && WIDE_CONTROLS.includes(control)) {
return false;
}
return DEFAULT_CONTROLS.includes(control);
}).map((name) => ({ name }));
if (alignments.length === 1 && alignments[0].name === "none") {
return EMPTY_ARRAY;
}
return alignments;
}
//# sourceMappingURL=use-available-alignments.js.map