@wordpress/block-library
Version:
Block library for the WordPress editor.
81 lines (80 loc) • 3.69 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_block_editor = require("@wordpress/block-editor");
let _wordpress_components = require("@wordpress/components");
let _wordpress_icons = require("@wordpress/icons");
let _wordpress_data = require("@wordpress/data");
let ___tabs_use_tab_actions_js = require("../tabs/use-tab-actions.cjs");
___tabs_use_tab_actions_js = __toESM(___tabs_use_tab_actions_js);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/tab-list/tab-movers.jsx
/**
* Block toolbar buttons that reorder the active tab one position before or after.
* Reordering acts on the underlying core/tab-panel blocks; the tab-list labels
* follow their panel automatically via useTabListItemsSync. The buttons are
* disabled at the first/last position.
*
* @param {Object} props
* @param {string} props.tabsClientId The client ID of the parent tabs block.
* @return {React.JSX.Element} The toolbar control element.
*/
function TabMovers({ tabsClientId }) {
const { moveTab } = (0, ___tabs_use_tab_actions_js.default)(tabsClientId);
const { tabCount, activeIndex } = (0, _wordpress_data.useSelect)((select) => {
if (!tabsClientId) return {
tabCount: 0,
activeIndex: 0
};
const { getBlocks, getBlockAttributes } = select(_wordpress_block_editor.store);
const tabsAttributes = getBlockAttributes(tabsClientId);
return {
tabCount: getBlocks(tabsClientId).find((block) => block.name === "core/tab-panels")?.innerBlocks.length ?? 0,
activeIndex: tabsAttributes?.editorActiveTabIndex ?? tabsAttributes?.activeTabIndex ?? 0
};
}, [tabsClientId]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_block_editor.BlockControls, {
group: "parent",
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
className: "wp-block-tab-list__mover-button",
icon: (0, _wordpress_i18n.isRTL)() ? _wordpress_icons.chevronRight : _wordpress_icons.chevronLeft,
label: (0, _wordpress_i18n.__)("Move tab before"),
onClick: () => moveTab(-1),
disabled: activeIndex <= 0,
accessibleWhenDisabled: true
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
className: "wp-block-tab-list__mover-button",
icon: (0, _wordpress_i18n.isRTL)() ? _wordpress_icons.chevronLeft : _wordpress_icons.chevronRight,
label: (0, _wordpress_i18n.__)("Move tab after"),
onClick: () => moveTab(1),
disabled: activeIndex >= tabCount - 1,
accessibleWhenDisabled: true
})]
});
}
exports.default = TabMovers;
//# sourceMappingURL=tab-movers.cjs.map