@wordpress/block-editor
Version:
117 lines (115 loc) • 4.57 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/line-height-control/index.js
var line_height_control_exports = {};
__export(line_height_control_exports, {
default: () => line_height_control_default
});
module.exports = __toCommonJS(line_height_control_exports);
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_utils = require("./utils");
var import_jsx_runtime = require("react/jsx-runtime");
var LineHeightControl = ({
/** Start opting into the larger default height that will become the default size in a future version. */
__next40pxDefaultSize = false,
value: lineHeight,
onChange,
__unstableInputWidth = "60px",
...otherProps
}) => {
const isDefined = (0, import_utils.isLineHeightDefined)(lineHeight);
const adjustNextValue = (nextValue, wasTypedOrPasted) => {
if (isDefined) {
return nextValue;
}
const spin = import_utils.STEP * import_utils.SPIN_FACTOR;
switch (`${nextValue}`) {
case `${spin}`:
return import_utils.BASE_DEFAULT_VALUE + spin;
case "0": {
if (wasTypedOrPasted) {
return nextValue;
}
return import_utils.BASE_DEFAULT_VALUE - spin;
}
case "":
return import_utils.BASE_DEFAULT_VALUE;
default:
return nextValue;
}
};
const stateReducer = (state, action) => {
const wasTypedOrPasted = ["insertText", "insertFromPaste"].includes(
action.payload.event.nativeEvent?.inputType
);
const value2 = adjustNextValue(state.value, wasTypedOrPasted);
return { ...state, value: value2 };
};
const value = isDefined ? lineHeight : import_utils.RESET_VALUE;
const handleOnChange = (nextValue, { event }) => {
if (nextValue === "") {
onChange();
return;
}
if (event.type === "click") {
onChange(adjustNextValue(`${nextValue}`, false));
return;
}
onChange(`${nextValue}`);
};
if (!__next40pxDefaultSize && (otherProps.size === void 0 || otherProps.size === "default")) {
(0, import_deprecated.default)(`36px default size for wp.blockEditor.LineHeightControl`, {
since: "6.8",
version: "7.1",
hint: "Set the `__next40pxDefaultSize` prop to true to start opting into the new default size, which will become the default in a future version."
});
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-line-height-control", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.__experimentalNumberControl,
{
...otherProps,
__shouldNotWarnDeprecated36pxSize: true,
__next40pxDefaultSize,
__unstableInputWidth,
__unstableStateReducer: stateReducer,
onChange: handleOnChange,
label: (0, import_i18n.__)("Line height"),
placeholder: import_utils.BASE_DEFAULT_VALUE,
step: import_utils.STEP,
spinFactor: import_utils.SPIN_FACTOR,
value,
min: 0,
spinControls: "custom"
}
) });
};
var line_height_control_default = LineHeightControl;
//# sourceMappingURL=index.js.map