@wordpress/block-library
Version:
Block library for the WordPress editor.
77 lines (76 loc) • 3.65 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_components = require("@wordpress/components");
let _wordpress_icons = require("@wordpress/icons");
let _wordpress_compose = require("@wordpress/compose");
let _wordpress_data = require("@wordpress/data");
let _wordpress_keycodes = require("@wordpress/keycodes");
let __hooks_index_js = require("./hooks/index.cjs");
let __utils_js = require("./utils.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/list-item/edit.jsx
function IndentUI({ clientId }) {
const registry = (0, _wordpress_data.useRegistry)();
const { canIndent, canOutdent } = (0, _wordpress_data.useSelect)((select) => {
const storeSelect = select(_wordpress_block_editor.store);
return {
canIndent: !!(0, __utils_js.getIndentTarget)(storeSelect, clientId),
canOutdent: !!(0, __utils_js.getOutdentTarget)(storeSelect, clientId)
};
}, [clientId]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
icon: (0, _wordpress_i18n.isRTL)() ? _wordpress_icons.formatOutdentRTL : _wordpress_icons.formatOutdent,
title: (0, _wordpress_i18n.__)("Outdent"),
shortcut: _wordpress_keycodes.displayShortcut.shift("Tab"),
description: (0, _wordpress_i18n.__)("Outdent list item"),
disabled: !canOutdent,
onClick: () => (0, __utils_js.outdentListItems)(registry)
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarButton, {
icon: (0, _wordpress_i18n.isRTL)() ? _wordpress_icons.formatIndentRTL : _wordpress_icons.formatIndent,
title: (0, _wordpress_i18n.__)("Indent"),
shortcut: "Tab",
description: (0, _wordpress_i18n.__)("Indent list item"),
disabled: !canIndent,
onClick: () => (0, __utils_js.indentListItems)(registry, clientId)
})] });
}
function ListItemEdit({ attributes, setAttributes, clientId, mergeBlocks }) {
const { placeholder, content } = attributes;
const blockProps = (0, _wordpress_block_editor.useBlockProps)();
const innerBlocksProps = (0, _wordpress_block_editor.useInnerBlocksProps)(blockProps, {
renderAppender: false,
__unstableDisableDropZone: true
});
const useEnterRef = (0, __hooks_index_js.useEnter)(clientId);
const useTabRef = (0, __hooks_index_js.useTab)();
const useMultiSelectTabRef = (0, __hooks_index_js.useMultiSelectTab)(clientId);
const onMerge = (0, __hooks_index_js.useMerge)(clientId, mergeBlocks);
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
...innerBlocksProps,
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.RichText, {
ref: (0, _wordpress_compose.useMergeRefs)([
useEnterRef,
useTabRef,
useMultiSelectTabRef
]),
identifier: "content",
tagName: "div",
onChange: (nextContent) => setAttributes({ content: nextContent }),
value: content,
"aria-label": (0, _wordpress_i18n.__)("List text"),
placeholder: placeholder || (0, _wordpress_i18n.__)("List"),
onMerge
}), innerBlocksProps.children]
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, {
group: "block",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IndentUI, { clientId })
})] });
}
exports.IndentUI = IndentUI;
exports.default = ListItemEdit;
//# sourceMappingURL=edit.cjs.map