@wordpress/block-editor
Version:
246 lines (244 loc) • 9.34 kB
JavaScript
;
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 __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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/components/inner-blocks/index.js
var inner_blocks_exports = {};
__export(inner_blocks_exports, {
default: () => inner_blocks_default,
useInnerBlocksProps: () => useInnerBlocksProps
});
module.exports = __toCommonJS(inner_blocks_exports);
var import_clsx = __toESM(require("clsx"));
var import_compose = require("@wordpress/compose");
var import_element = require("@wordpress/element");
var import_data = require("@wordpress/data");
var import_blocks = require("@wordpress/blocks");
var import_button_block_appender = __toESM(require("./button-block-appender"));
var import_default_block_appender = __toESM(require("./default-block-appender"));
var import_use_nested_settings_update = __toESM(require("./use-nested-settings-update"));
var import_use_inner_block_template_sync = __toESM(require("./use-inner-block-template-sync"));
var import_use_block_context = __toESM(require("./use-block-context"));
var import_block_list = require("../block-list");
var import_block_context = require("../block-context");
var import_context = require("../block-edit/context");
var import_use_block_sync = __toESM(require("../provider/use-block-sync"));
var import_store = require("../../store");
var import_use_block_drop_zone = __toESM(require("../use-block-drop-zone"));
var import_lock_unlock = require("../../lock-unlock");
var import_jsx_runtime = require("react/jsx-runtime");
var EMPTY_OBJECT = {};
function BlockContext({ children, clientId }) {
const context = (0, import_use_block_context.default)(clientId);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_context.BlockContextProvider, { value: context, children });
}
var BlockListItemsMemo = (0, import_element.memo)(import_block_list.BlockListItems);
function UncontrolledInnerBlocks(props) {
const {
clientId,
allowedBlocks,
prioritizedInserterBlocks,
defaultBlock,
directInsert,
__experimentalDefaultBlock,
__experimentalDirectInsert,
template,
templateLock,
wrapperRef,
templateInsertUpdatesSelection,
__experimentalCaptureToolbars: captureToolbars,
__experimentalAppenderTagName,
renderAppender,
orientation,
placeholder,
layout,
name,
blockType,
parentLock,
defaultLayout
} = props;
(0, import_use_nested_settings_update.default)(
clientId,
parentLock,
allowedBlocks,
prioritizedInserterBlocks,
defaultBlock,
directInsert,
__experimentalDefaultBlock,
__experimentalDirectInsert,
templateLock,
captureToolbars,
orientation,
layout
);
(0, import_use_inner_block_template_sync.default)(
clientId,
template,
templateLock,
templateInsertUpdatesSelection
);
const defaultLayoutBlockSupport = (0, import_blocks.getBlockSupport)(name, "layout") || (0, import_blocks.getBlockSupport)(name, "__experimentalLayout") || EMPTY_OBJECT;
const { allowSizingOnChildren = false } = defaultLayoutBlockSupport;
const usedLayout = layout || defaultLayoutBlockSupport;
const memoedLayout = (0, import_element.useMemo)(
() => ({
// Default layout will know about any content/wide size defined by the theme.
...defaultLayout,
...usedLayout,
...allowSizingOnChildren && {
allowSizingOnChildren: true
}
}),
[defaultLayout, usedLayout, allowSizingOnChildren]
);
const items = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
BlockListItemsMemo,
{
rootClientId: clientId,
renderAppender,
__experimentalAppenderTagName,
layout: memoedLayout,
wrapperRef,
placeholder
}
);
if (!blockType?.providesContext || Object.keys(blockType.providesContext).length === 0) {
return items;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockContext, { clientId, children: items });
}
function ControlledInnerBlocks(props) {
(0, import_use_block_sync.default)(props);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UncontrolledInnerBlocks, { ...props });
}
var ForwardedInnerBlocks = (0, import_element.forwardRef)((props, ref) => {
const innerBlocksProps = useInnerBlocksProps({ ref }, props);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-inner-blocks", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...innerBlocksProps }) });
});
function useInnerBlocksProps(props = {}, options = {}) {
const {
__unstableDisableLayoutClassNames,
__unstableDisableDropZone,
dropZoneElement
} = options;
const {
clientId,
layout = null,
__unstableLayoutClassNames: layoutClassNames = ""
} = (0, import_context.useBlockEditContext)();
const selected = (0, import_data.useSelect)(
(select) => {
const {
getBlockName,
isZoomOut,
getTemplateLock,
getBlockRootClientId,
getBlockEditingMode,
getBlockSettings,
getSectionRootClientId
} = (0, import_lock_unlock.unlock)(select(import_store.store));
if (!clientId) {
const sectionRootClientId = getSectionRootClientId();
return {
isDropZoneDisabled: isZoomOut() && sectionRootClientId !== ""
};
}
const { hasBlockSupport, getBlockType } = select(import_blocks.store);
const blockName = getBlockName(clientId);
const blockEditingMode = getBlockEditingMode(clientId);
const parentClientId2 = getBlockRootClientId(clientId);
const [defaultLayout2] = getBlockSettings(clientId, "layout");
let _isDropZoneDisabled = blockEditingMode === "disabled";
if (isZoomOut()) {
const sectionRootClientId = getSectionRootClientId();
_isDropZoneDisabled = clientId !== sectionRootClientId;
}
return {
__experimentalCaptureToolbars: hasBlockSupport(
blockName,
"__experimentalExposeControlsToChildren",
false
),
name: blockName,
blockType: getBlockType(blockName),
parentLock: getTemplateLock(parentClientId2),
parentClientId: parentClientId2,
isDropZoneDisabled: _isDropZoneDisabled,
defaultLayout: defaultLayout2
};
},
[clientId]
);
const {
__experimentalCaptureToolbars,
name,
blockType,
parentLock,
parentClientId,
isDropZoneDisabled,
defaultLayout
} = selected;
const blockDropZoneRef = (0, import_use_block_drop_zone.default)({
dropZoneElement,
rootClientId: clientId,
parentClientId
});
const ref = (0, import_compose.useMergeRefs)([
props.ref,
__unstableDisableDropZone || isDropZoneDisabled || layout?.isManualPlacement && window.__experimentalEnableGridInteractivity ? null : blockDropZoneRef
]);
const innerBlocksProps = {
__experimentalCaptureToolbars,
layout,
name,
blockType,
parentLock,
defaultLayout,
...options
};
const InnerBlocks = innerBlocksProps.value && innerBlocksProps.onChange ? ControlledInnerBlocks : UncontrolledInnerBlocks;
return {
...props,
ref,
className: (0, import_clsx.default)(
props.className,
"block-editor-block-list__layout",
__unstableDisableLayoutClassNames ? "" : layoutClassNames
),
children: clientId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InnerBlocks, { ...innerBlocksProps, clientId }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_list.BlockListItems, { ...options })
};
}
useInnerBlocksProps.save = import_blocks.__unstableGetInnerBlocksProps;
ForwardedInnerBlocks.DefaultBlockAppender = import_default_block_appender.default;
ForwardedInnerBlocks.ButtonBlockAppender = import_button_block_appender.default;
ForwardedInnerBlocks.Content = () => useInnerBlocksProps.save().children;
var inner_blocks_default = ForwardedInnerBlocks;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
useInnerBlocksProps
});
//# sourceMappingURL=index.js.map