@wordpress/block-library
Version:
Block library for the WordPress editor.
110 lines (109 loc) • 5.11 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_data = require("@wordpress/data");
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_element = require("@wordpress/element");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_components = require("@wordpress/components");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_compose = require("@wordpress/compose");
let ___utils_js = require("../utils.cjs");
let __pattern_selection_jsx = require("./pattern-selection.cjs");
let __query_toolbar_jsx = require("./query-toolbar.cjs");
__query_toolbar_jsx = __toESM(__query_toolbar_jsx);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/query/edit/query-placeholder.jsx
function QueryPlaceholder({ attributes, clientId, name, openPatternSelectionModal, isSelected }) {
const [isStartingBlank, setIsStartingBlank] = (0, _wordpress_element.useState)(false);
const [containerWidth, setContainerWidth] = (0, _wordpress_element.useState)(0);
const resizeObserverRef = (0, _wordpress_compose.useResizeObserver)(([entry]) => {
setContainerWidth(entry.contentRect.width);
});
const isSmallContainer = containerWidth > 0 && containerWidth < 160;
const { blockType, activeBlockVariation } = (0, _wordpress_data.useSelect)((select) => {
const { getActiveBlockVariation, getBlockType } = select(_wordpress_blocks.store);
return {
blockType: getBlockType(name),
activeBlockVariation: getActiveBlockVariation(name, attributes)
};
}, [name, attributes]);
const hasPatterns = !!(0, __pattern_selection_jsx.useBlockPatterns)(clientId, attributes).length;
const icon = activeBlockVariation?.icon?.src || activeBlockVariation?.icon || blockType?.icon?.src;
const label = activeBlockVariation?.title || blockType?.title;
const blockProps = (0, _wordpress_block_editor.useBlockProps)({ ref: resizeObserverRef });
if (isStartingBlank) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QueryVariationPicker, {
clientId,
attributes,
icon,
label
});
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
...blockProps,
children: [isSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__query_toolbar_jsx.default, {
clientId,
attributes,
hasInnerBlocks: false
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.Placeholder, {
className: "block-editor-media-placeholder",
icon: !isSmallContainer && icon,
label: !isSmallContainer && label,
instructions: !isSmallContainer && (0, _wordpress_i18n.__)("Choose a pattern for the query loop or start blank."),
withIllustration: isSmallContainer,
children: [!!hasPatterns && !isSmallContainer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
__next40pxDefaultSize: true,
variant: "primary",
onClick: openPatternSelectionModal,
children: (0, _wordpress_i18n.__)("Choose")
}), !isSmallContainer && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
__next40pxDefaultSize: true,
variant: "secondary",
onClick: () => {
setIsStartingBlank(true);
},
children: (0, _wordpress_i18n.__)("Start blank")
})]
})]
});
}
function QueryVariationPicker({ clientId, attributes, icon, label }) {
const scopeVariations = (0, ___utils_js.useScopedBlockVariations)(attributes);
const { replaceInnerBlocks } = (0, _wordpress_data.useDispatch)(_wordpress_block_editor.store);
const blockProps = (0, _wordpress_block_editor.useBlockProps)();
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
...blockProps,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.__experimentalBlockVariationPicker, {
icon,
label,
variations: scopeVariations,
onSelect: (variation) => {
if (variation.innerBlocks) replaceInnerBlocks(clientId, (0, _wordpress_blocks.createBlocksFromInnerBlocksTemplate)(variation.innerBlocks), false);
}
})
});
}
exports.default = QueryPlaceholder;
//# sourceMappingURL=query-placeholder.cjs.map