@wordpress/block-library
Version:
Block library for the WordPress editor.
87 lines (86 loc) • 3.87 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_block_editor = require("@wordpress/block-editor");
let _wordpress_data = require("@wordpress/data");
let _wordpress_element = require("@wordpress/element");
let __controls_jsx = require("./controls.cjs");
__controls_jsx = __toESM(__controls_jsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/tab-panel/edit.jsx
function Edit({ clientId, isSelected }) {
const { activeTabIndex, editorActiveTabIndex, blockIndex, hasInnerBlocksSelected, tabsClientId, tabCount } = (0, _wordpress_data.useSelect)((select) => {
const { getBlockRootClientId, getBlockIndex, hasSelectedInnerBlock, getBlockAttributes, getBlockCount } = select(_wordpress_block_editor.store);
const tabPanelsClientId = getBlockRootClientId(clientId);
const _tabsClientId = getBlockRootClientId(tabPanelsClientId);
const tabsAttributes = getBlockAttributes(_tabsClientId) ?? {};
const _blockIndex = getBlockIndex(clientId);
const _hasInnerBlocksSelected = hasSelectedInnerBlock(clientId, true);
return {
activeTabIndex: tabsAttributes.activeTabIndex,
editorActiveTabIndex: tabsAttributes.editorActiveTabIndex,
blockIndex: _blockIndex,
hasInnerBlocksSelected: _hasInnerBlocksSelected,
tabsClientId: _tabsClientId,
tabCount: getBlockCount(tabPanelsClientId)
};
}, [clientId]);
const activeIndex = editorActiveTabIndex ?? activeTabIndex;
const effectiveActiveIndex = activeIndex < tabCount ? activeIndex : 0;
const { updateBlockAttributes, __unstableMarkNextChangeAsNotPersistent } = (0, _wordpress_data.useDispatch)(_wordpress_block_editor.store);
(0, _wordpress_element.useEffect)(() => {
if ((isSelected || hasInnerBlocksSelected) && tabsClientId && effectiveActiveIndex !== blockIndex) {
__unstableMarkNextChangeAsNotPersistent();
updateBlockAttributes(tabsClientId, { editorActiveTabIndex: blockIndex });
}
}, [
isSelected,
hasInnerBlocksSelected,
tabsClientId,
effectiveActiveIndex,
blockIndex,
updateBlockAttributes,
__unstableMarkNextChangeAsNotPersistent
]);
const isActiveTab = effectiveActiveIndex === blockIndex;
const isDefaultTab = activeTabIndex === blockIndex;
const isSelectedTab = isSelected || hasInnerBlocksSelected || isActiveTab;
const blockProps = (0, _wordpress_block_editor.useBlockProps)({
hidden: !isSelectedTab,
tabIndex: isSelectedTab ? 0 : -1
});
const innerBlocksProps = (0, _wordpress_block_editor.useInnerBlocksProps)(blockProps, {});
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
...innerBlocksProps,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__controls_jsx.default, {
tabsClientId,
blockIndex,
isDefaultTab
}), isSelectedTab && innerBlocksProps.children]
});
}
exports.default = Edit;
//# sourceMappingURL=edit.cjs.map