@wordpress/block-library
Version:
Block library for the WordPress editor.
133 lines (132 loc) • 6.18 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 clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_components = require("@wordpress/components");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_data = require("@wordpress/data");
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_icons = require("@wordpress/icons");
let __use_enter_js = require("./use-enter.cjs");
let __deprecated_attributes_js = require("./deprecated-attributes.cjs");
__deprecated_attributes_js = __toESM(__deprecated_attributes_js);
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/paragraph/edit.jsx
function ParagraphRTLControl({ direction, setDirection }) {
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
icon: _wordpress_icons.formatLTR,
title: (0, _wordpress_i18n._x)("Left to right", "editor button"),
isActive: direction === "ltr",
onClick: () => {
setDirection(direction === "ltr" ? void 0 : "ltr");
}
});
}
function hasDropCapDisabled(align) {
return align === ((0, _wordpress_i18n.isRTL)() ? "left" : "right") || align === "center";
}
function DropCapControl({ clientId, attributes, setAttributes, name }) {
const [isDropCapFeatureEnabled] = (0, _wordpress_block_editor.useSettings)("typography.dropCap");
const hasSelectedStyleState = (0, _wordpress_data.useSelect)((select) => {
const { hasSelectedBlockStyleState } = select(_wordpress_block_editor.store);
return hasSelectedBlockStyleState(clientId);
}, [clientId]);
const { style, dropCap } = attributes;
if (!isDropCapFeatureEnabled && !dropCap || hasSelectedStyleState) return null;
const textAlign = style?.typography?.textAlign;
let helpText;
if (hasDropCapDisabled(textAlign)) helpText = (0, _wordpress_i18n.__)("Not available for aligned text.");
else if (dropCap) helpText = (0, _wordpress_i18n.__)("Showing large initial letter.");
else helpText = (0, _wordpress_i18n.__)("Show a large initial letter.");
const isDropCapControlEnabledByDefault = (0, _wordpress_blocks.getBlockSupport)(name, "typography.defaultControls.dropCap", false);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.InspectorControls, {
group: "typography",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
hasValue: () => !!dropCap,
label: (0, _wordpress_i18n.__)("Drop cap"),
isShownByDefault: isDropCapControlEnabledByDefault,
onDeselect: () => setAttributes({ dropCap: false }),
resetAllFilter: () => ({ dropCap: false }),
panelId: clientId,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Drop cap"),
checked: !!dropCap,
onChange: () => setAttributes({ dropCap: !dropCap }),
help: helpText,
disabled: hasDropCapDisabled(textAlign)
})
})
});
}
function ParagraphBlock({ attributes, mergeBlocks, onReplace, onRemove, setAttributes, clientId, isSelected: isSingleSelected, name }) {
const { content, direction, dropCap, placeholder, style } = attributes;
const textAlign = style?.typography?.textAlign;
(0, __deprecated_attributes_js.default)(attributes.align, style, setAttributes);
const blockProps = (0, _wordpress_block_editor.useBlockProps)({
ref: (0, __use_enter_js.useOnEnter)({
clientId,
content
}),
className: (0, clsx.default)({ "has-drop-cap": hasDropCapDisabled(textAlign) ? false : dropCap }),
style: { direction },
"aria-label": _wordpress_block_editor.RichText.isEmpty(content) ? (0, _wordpress_i18n.__)("Empty block; start writing or type forward slash to choose a block") : (0, _wordpress_i18n.__)("Block: Paragraph")
});
const blockEditingMode = (0, _wordpress_block_editor.useBlockEditingMode)();
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
blockEditingMode === "default" && (0, _wordpress_i18n.isRTL)() && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, {
group: "block",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ParagraphRTLControl, {
direction,
setDirection: (newDirection) => setAttributes({ direction: newDirection })
})
}),
isSingleSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DropCapControl, {
name,
clientId,
attributes,
setAttributes
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText, {
identifier: "content",
tagName: "p",
...blockProps,
value: content,
onChange: (newContent) => setAttributes({ content: newContent }),
onMerge: mergeBlocks,
onReplace,
onRemove,
"data-empty": _wordpress_block_editor.RichText.isEmpty(content),
placeholder: placeholder || (0, _wordpress_i18n.__)("Type / to choose a block"),
"data-custom-placeholder": placeholder ? true : void 0,
__unstableEmbedURLOnPaste: true,
__unstableAllowPrefixTransformations: true
})
] });
}
exports.default = ParagraphBlock;
//# sourceMappingURL=edit.cjs.map