@wordpress/notices
Version:
State management for notices.
112 lines (110 loc) • 3.17 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/notices/src/store/actions.ts
var actions_exports = {};
__export(actions_exports, {
createErrorNotice: () => createErrorNotice,
createInfoNotice: () => createInfoNotice,
createNotice: () => createNotice,
createSuccessNotice: () => createSuccessNotice,
createWarningNotice: () => createWarningNotice,
removeAllNotices: () => removeAllNotices,
removeNotice: () => removeNotice,
removeNotices: () => removeNotices
});
module.exports = __toCommonJS(actions_exports);
var import_constants = require("./constants.cjs");
var uniqueId = 0;
function createNotice(status = import_constants.DEFAULT_STATUS, content, options = {}) {
const {
speak = true,
isDismissible = true,
context = import_constants.DEFAULT_CONTEXT,
id = `${context}${++uniqueId}`,
actions = [],
type = "default",
__unstableHTML,
icon = null,
explicitDismiss = false,
onDismiss
} = options;
content = String(content);
return {
type: "CREATE_NOTICE",
context,
notice: {
id,
status,
content,
spokenMessage: speak ? content : null,
__unstableHTML,
isDismissible,
actions,
type,
icon,
explicitDismiss,
onDismiss
}
};
}
function createSuccessNotice(content, options) {
return createNotice("success", content, options);
}
function createInfoNotice(content, options) {
return createNotice("info", content, options);
}
function createErrorNotice(content, options) {
return createNotice("error", content, options);
}
function createWarningNotice(content, options) {
return createNotice("warning", content, options);
}
function removeNotice(id, context = import_constants.DEFAULT_CONTEXT) {
return {
type: "REMOVE_NOTICE",
id,
context
};
}
function removeAllNotices(noticeType = "default", context = import_constants.DEFAULT_CONTEXT) {
return {
type: "REMOVE_ALL_NOTICES",
noticeType,
context
};
}
function removeNotices(ids, context = import_constants.DEFAULT_CONTEXT) {
return {
type: "REMOVE_NOTICES",
ids,
context
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createErrorNotice,
createInfoNotice,
createNotice,
createSuccessNotice,
createWarningNotice,
removeAllNotices,
removeNotice,
removeNotices
});
//# sourceMappingURL=actions.cjs.map