@wordpress/block-editor
Version:
138 lines (136 loc) • 4.95 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/hooks/custom-class-name.js
var custom_class_name_exports = {};
__export(custom_class_name_exports, {
addAttribute: () => addAttribute,
addSaveProps: () => addSaveProps,
addTransforms: () => addTransforms,
default: () => custom_class_name_default
});
module.exports = __toCommonJS(custom_class_name_exports);
var import_clsx = __toESM(require("clsx"));
var import_hooks = require("@wordpress/hooks");
var import_components = require("@wordpress/components");
var import_i18n = require("@wordpress/i18n");
var import_blocks = require("@wordpress/blocks");
var import_components2 = require("../components");
var import_block_editing_mode = require("../components/block-editing-mode");
var import_jsx_runtime = require("react/jsx-runtime");
function addAttribute(settings) {
if ((0, import_blocks.hasBlockSupport)(settings, "customClassName", true)) {
settings.attributes = {
...settings.attributes,
className: {
type: "string"
}
};
}
return settings;
}
function CustomClassNameControlsPure({ className, setAttributes }) {
const blockEditingMode = (0, import_block_editing_mode.useBlockEditingMode)();
if (blockEditingMode !== "default") {
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components2.InspectorControls, { group: "advanced", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.TextControl,
{
__nextHasNoMarginBottom: true,
__next40pxDefaultSize: true,
autoComplete: "off",
label: (0, import_i18n.__)("Additional CSS class(es)"),
value: className || "",
onChange: (nextValue) => {
setAttributes({
className: nextValue !== "" ? nextValue : void 0
});
},
help: (0, import_i18n.__)("Separate multiple classes with spaces.")
}
) });
}
var custom_class_name_default = {
edit: CustomClassNameControlsPure,
addSaveProps,
attributeKeys: ["className"],
hasSupport(name) {
return (0, import_blocks.hasBlockSupport)(name, "customClassName", true);
}
};
function addSaveProps(extraProps, blockType, attributes) {
if ((0, import_blocks.hasBlockSupport)(blockType, "customClassName", true) && attributes.className) {
extraProps.className = (0, import_clsx.default)(
extraProps.className,
attributes.className
);
}
return extraProps;
}
function addTransforms(result, source, index, results) {
if (!(0, import_blocks.hasBlockSupport)(result.name, "customClassName", true)) {
return result;
}
if (results.length === 1 && result.innerBlocks.length === source.length) {
return result;
}
if (results.length === 1 && source.length > 1 || results.length > 1 && source.length === 1) {
return result;
}
if (source[index]) {
const originClassName = source[index]?.attributes.className;
if (originClassName && result.attributes.className === void 0) {
return {
...result,
attributes: {
...result.attributes,
className: originClassName
}
};
}
}
return result;
}
(0, import_hooks.addFilter)(
"blocks.registerBlockType",
"core/editor/custom-class-name/attribute",
addAttribute
);
(0, import_hooks.addFilter)(
"blocks.switchToBlockType.transformedBlock",
"core/customClassName/addTransforms",
addTransforms
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
addAttribute,
addSaveProps,
addTransforms
});
//# sourceMappingURL=custom-class-name.js.map