@wordpress/block-editor
Version:
150 lines (148 loc) • 6.21 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/block-list/zoom-out-separator.js
var zoom_out_separator_exports = {};
__export(zoom_out_separator_exports, {
ZoomOutSeparator: () => ZoomOutSeparator
});
module.exports = __toCommonJS(zoom_out_separator_exports);
var import_clsx = __toESM(require("clsx"));
var import_components = require("@wordpress/components");
var import_compose = require("@wordpress/compose");
var import_data = require("@wordpress/data");
var import_element = require("@wordpress/element");
var import_i18n = require("@wordpress/i18n");
var import_store = require("../../store");
var import_lock_unlock = require("../../lock-unlock");
var import_jsx_runtime = require("react/jsx-runtime");
function ZoomOutSeparator({
clientId,
rootClientId = "",
position = "top"
}) {
const [isDraggedOver, setIsDraggedOver] = (0, import_element.useState)(false);
const {
sectionRootClientId,
sectionClientIds,
insertionPoint,
blockInsertionPointVisible,
blockInsertionPoint,
blocksBeingDragged
} = (0, import_data.useSelect)((select) => {
const {
getInsertionPoint,
getBlockOrder,
getSectionRootClientId,
isBlockInsertionPointVisible,
getBlockInsertionPoint,
getDraggedBlockClientIds
} = (0, import_lock_unlock.unlock)(select(import_store.store));
const root = getSectionRootClientId();
const sectionRootClientIds = getBlockOrder(root);
return {
sectionRootClientId: root,
sectionClientIds: sectionRootClientIds,
insertionPoint: getInsertionPoint(),
blockInsertionPoint: getBlockInsertionPoint(),
blockInsertionPointVisible: isBlockInsertionPointVisible(),
blocksBeingDragged: getDraggedBlockClientIds()
};
}, []);
const isReducedMotion = (0, import_compose.useReducedMotion)();
if (!clientId) {
return;
}
let isVisible = false;
const isSectionBlock = rootClientId === sectionRootClientId && sectionClientIds && sectionClientIds.includes(clientId);
if (!isSectionBlock) {
return null;
}
const hasTopInsertionPoint = insertionPoint?.index === 0 && clientId === sectionClientIds[insertionPoint.index];
const hasBottomInsertionPoint = insertionPoint && insertionPoint.hasOwnProperty("index") && clientId === sectionClientIds[insertionPoint.index - 1];
if (position === "top") {
isVisible = hasTopInsertionPoint || blockInsertionPointVisible && blockInsertionPoint.index === 0 && clientId === sectionClientIds[blockInsertionPoint.index];
}
if (position === "bottom") {
isVisible = hasBottomInsertionPoint || blockInsertionPointVisible && clientId === sectionClientIds[blockInsertionPoint.index - 1];
}
const blockBeingDraggedClientId = blocksBeingDragged[0];
const isCurrentBlockBeingDragged = blocksBeingDragged.includes(clientId);
const blockBeingDraggedIndex = sectionClientIds.indexOf(
blockBeingDraggedClientId
);
const blockBeingDraggedPreviousSiblingClientId = blockBeingDraggedIndex > 0 ? sectionClientIds[blockBeingDraggedIndex - 1] : null;
const isCurrentBlockPreviousSiblingOfBlockBeingDragged = blockBeingDraggedPreviousSiblingClientId === clientId;
if (isCurrentBlockBeingDragged || isCurrentBlockPreviousSiblingOfBlockBeingDragged) {
isVisible = false;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__unstableAnimatePresence, { children: isVisible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__unstableMotion.div,
{
initial: { height: 0 },
animate: {
// Use a height equal to that of the zoom out frame size.
height: "calc(1 * var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale)"
},
exit: { height: 0 },
transition: {
type: "tween",
duration: isReducedMotion ? 0 : 0.2,
ease: [0.6, 0, 0.4, 1]
},
className: (0, import_clsx.default)(
"block-editor-block-list__zoom-out-separator",
{
"is-dragged-over": isDraggedOver
}
),
"data-is-insertion-point": "true",
onDragOver: () => setIsDraggedOver(true),
onDragLeave: () => setIsDraggedOver(false),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__unstableMotion.div,
{
initial: { opacity: 0 },
animate: { opacity: 1 },
exit: { opacity: 0, transition: { delay: -0.125 } },
transition: {
ease: "linear",
duration: 0.1,
delay: 0.125
},
children: (0, import_i18n.__)("Drop pattern.")
}
)
}
) });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ZoomOutSeparator
});
//# sourceMappingURL=zoom-out-separator.js.map