@wordpress/block-editor
Version:
90 lines (88 loc) • 3.48 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/utils/use-notify-copy.js
var use_notify_copy_exports = {};
__export(use_notify_copy_exports, {
useNotifyCopy: () => useNotifyCopy
});
module.exports = __toCommonJS(use_notify_copy_exports);
var import_element = require("@wordpress/element");
var import_blocks = require("@wordpress/blocks");
var import_data = require("@wordpress/data");
var import_i18n = require("@wordpress/i18n");
var import_notices = require("@wordpress/notices");
var import_store = require("../store");
function useNotifyCopy() {
const { getBlockName } = (0, import_data.useSelect)(import_store.store);
const { getBlockType } = (0, import_data.useSelect)(import_blocks.store);
const { createSuccessNotice } = (0, import_data.useDispatch)(import_notices.store);
return (0, import_element.useCallback)(
(eventType, selectedBlockClientIds) => {
let notice = "";
if (eventType === "copyStyles") {
notice = (0, import_i18n.__)("Styles copied to clipboard.");
} else if (selectedBlockClientIds.length === 1) {
const clientId = selectedBlockClientIds[0];
const title = getBlockType(getBlockName(clientId))?.title;
if (eventType === "copy") {
notice = (0, import_i18n.sprintf)(
// Translators: %s: Name of the block being copied, e.g. "Paragraph".
(0, import_i18n.__)('Copied "%s" to clipboard.'),
title
);
} else {
notice = (0, import_i18n.sprintf)(
// Translators: %s: Name of the block being cut, e.g. "Paragraph".
(0, import_i18n.__)('Moved "%s" to clipboard.'),
title
);
}
} else if (eventType === "copy") {
notice = (0, import_i18n.sprintf)(
// Translators: %d: Number of blocks being copied.
(0, import_i18n._n)(
"Copied %d block to clipboard.",
"Copied %d blocks to clipboard.",
selectedBlockClientIds.length
),
selectedBlockClientIds.length
);
} else {
notice = (0, import_i18n.sprintf)(
// Translators: %d: Number of blocks being moved.
(0, import_i18n._n)(
"Moved %d block to clipboard.",
"Moved %d blocks to clipboard.",
selectedBlockClientIds.length
),
selectedBlockClientIds.length
);
}
createSuccessNotice(notice, {
type: "snackbar"
});
},
[createSuccessNotice, getBlockName, getBlockType]
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
useNotifyCopy
});
//# sourceMappingURL=use-notify-copy.js.map