| 1 |
"use strict"; |
| 2 |
var wp; |
| 3 |
(wp ||= {}).notices = (() => { |
| 4 |
var __create = Object.create; |
| 5 |
var __defProp = Object.defineProperty; |
| 6 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 7 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
| 8 |
var __getProtoOf = Object.getPrototypeOf; |
| 9 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 10 |
var __commonJS = (cb, mod) => function __require() { |
| 11 |
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 12 |
}; |
| 13 |
var __export = (target, all) => { |
| 14 |
for (var name in all) |
| 15 |
__defProp(target, name, { get: all[name], enumerable: true }); |
| 16 |
}; |
| 17 |
var __copyProps = (to, from, except, desc) => { |
| 18 |
if (from && typeof from === "object" || typeof from === "function") { |
| 19 |
for (let key of __getOwnPropNames(from)) |
| 20 |
if (!__hasOwnProp.call(to, key) && key !== except) |
| 21 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 22 |
} |
| 23 |
return to; |
| 24 |
}; |
| 25 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 26 |
// If the importer is in node compatibility mode or this is not an ESM |
| 27 |
// file that has been converted to a CommonJS file using a Babel- |
| 28 |
// compatible transform (i.e. "__esModule" has not been set), then set |
| 29 |
// "default" to the CommonJS "module.exports" for node compatibility. |
| 30 |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 31 |
mod |
| 32 |
)); |
| 33 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
| 34 |
|
| 35 |
// package-external:@wordpress/data |
| 36 |
var require_data = __commonJS({ |
| 37 |
"package-external:@wordpress/data"(exports, module) { |
| 38 |
module.exports = window.wp.data; |
| 39 |
} |
| 40 |
}); |
| 41 |
|
| 42 |
// packages/notices/build-module/index.js |
| 43 |
var index_exports = {}; |
| 44 |
__export(index_exports, { |
| 45 |
store: () => store |
| 46 |
}); |
| 47 |
|
| 48 |
// packages/notices/build-module/store/index.js |
| 49 |
var import_data = __toESM(require_data()); |
| 50 |
|
| 51 |
// packages/notices/build-module/store/utils/on-sub-key.js |
| 52 |
var onSubKey = (actionProperty) => (reducer) => (state = {}, action) => { |
| 53 |
const key = action[actionProperty]; |
| 54 |
if (key === void 0) { |
| 55 |
return state; |
| 56 |
} |
| 57 |
const nextKeyState = reducer(state[key], action); |
| 58 |
if (nextKeyState === state[key]) { |
| 59 |
return state; |
| 60 |
} |
| 61 |
return { |
| 62 |
...state, |
| 63 |
[key]: nextKeyState |
| 64 |
}; |
| 65 |
}; |
| 66 |
var on_sub_key_default = onSubKey; |
| 67 |
|
| 68 |
// packages/notices/build-module/store/reducer.js |
| 69 |
var notices = on_sub_key_default("context")((state = [], action) => { |
| 70 |
switch (action.type) { |
| 71 |
case "CREATE_NOTICE": |
| 72 |
return [ |
| 73 |
...state.filter(({ id }) => id !== action.notice.id), |
| 74 |
action.notice |
| 75 |
]; |
| 76 |
case "REMOVE_NOTICE": |
| 77 |
return state.filter(({ id }) => id !== action.id); |
| 78 |
case "REMOVE_NOTICES": |
| 79 |
return state.filter(({ id }) => !action.ids.includes(id)); |
| 80 |
case "REMOVE_ALL_NOTICES": |
| 81 |
return state.filter(({ type }) => type !== action.noticeType); |
| 82 |
} |
| 83 |
return state; |
| 84 |
}); |
| 85 |
var reducer_default = notices; |
| 86 |
|
| 87 |
// packages/notices/build-module/store/actions.js |
| 88 |
var actions_exports = {}; |
| 89 |
__export(actions_exports, { |
| 90 |
createErrorNotice: () => createErrorNotice, |
| 91 |
createInfoNotice: () => createInfoNotice, |
| 92 |
createNotice: () => createNotice, |
| 93 |
createSuccessNotice: () => createSuccessNotice, |
| 94 |
createWarningNotice: () => createWarningNotice, |
| 95 |
removeAllNotices: () => removeAllNotices, |
| 96 |
removeNotice: () => removeNotice, |
| 97 |
removeNotices: () => removeNotices |
| 98 |
}); |
| 99 |
|
| 100 |
// packages/notices/build-module/store/constants.js |
| 101 |
var DEFAULT_CONTEXT = "global"; |
| 102 |
var DEFAULT_STATUS = "info"; |
| 103 |
|
| 104 |
// packages/notices/build-module/store/actions.js |
| 105 |
var uniqueId = 0; |
| 106 |
function createNotice(status = DEFAULT_STATUS, content, options = {}) { |
| 107 |
const { |
| 108 |
speak = true, |
| 109 |
isDismissible = true, |
| 110 |
context = DEFAULT_CONTEXT, |
| 111 |
id = `${context}${++uniqueId}`, |
| 112 |
actions = [], |
| 113 |
type = "default", |
| 114 |
__unstableHTML, |
| 115 |
icon = null, |
| 116 |
explicitDismiss = false, |
| 117 |
onDismiss |
| 118 |
} = options; |
| 119 |
content = String(content); |
| 120 |
return { |
| 121 |
type: "CREATE_NOTICE", |
| 122 |
context, |
| 123 |
notice: { |
| 124 |
id, |
| 125 |
status, |
| 126 |
content, |
| 127 |
spokenMessage: speak ? content : null, |
| 128 |
__unstableHTML, |
| 129 |
isDismissible, |
| 130 |
actions, |
| 131 |
type, |
| 132 |
icon, |
| 133 |
explicitDismiss, |
| 134 |
onDismiss |
| 135 |
} |
| 136 |
}; |
| 137 |
} |
| 138 |
function createSuccessNotice(content, options) { |
| 139 |
return createNotice("success", content, options); |
| 140 |
} |
| 141 |
function createInfoNotice(content, options) { |
| 142 |
return createNotice("info", content, options); |
| 143 |
} |
| 144 |
function createErrorNotice(content, options) { |
| 145 |
return createNotice("error", content, options); |
| 146 |
} |
| 147 |
function createWarningNotice(content, options) { |
| 148 |
return createNotice("warning", content, options); |
| 149 |
} |
| 150 |
function removeNotice(id, context = DEFAULT_CONTEXT) { |
| 151 |
return { |
| 152 |
type: "REMOVE_NOTICE", |
| 153 |
id, |
| 154 |
context |
| 155 |
}; |
| 156 |
} |
| 157 |
function removeAllNotices(noticeType = "default", context = DEFAULT_CONTEXT) { |
| 158 |
return { |
| 159 |
type: "REMOVE_ALL_NOTICES", |
| 160 |
noticeType, |
| 161 |
context |
| 162 |
}; |
| 163 |
} |
| 164 |
function removeNotices(ids, context = DEFAULT_CONTEXT) { |
| 165 |
return { |
| 166 |
type: "REMOVE_NOTICES", |
| 167 |
ids, |
| 168 |
context |
| 169 |
}; |
| 170 |
} |
| 171 |
|
| 172 |
// packages/notices/build-module/store/selectors.js |
| 173 |
var selectors_exports = {}; |
| 174 |
__export(selectors_exports, { |
| 175 |
getNotices: () => getNotices |
| 176 |
}); |
| 177 |
var DEFAULT_NOTICES = []; |
| 178 |
function getNotices(state, context = DEFAULT_CONTEXT) { |
| 179 |
return state[context] || DEFAULT_NOTICES; |
| 180 |
} |
| 181 |
|
| 182 |
// packages/notices/build-module/store/index.js |
| 183 |
var store = (0, import_data.createReduxStore)("core/notices", { |
| 184 |
reducer: reducer_default, |
| 185 |
actions: actions_exports, |
| 186 |
selectors: selectors_exports |
| 187 |
}); |
| 188 |
(0, import_data.register)(store); |
| 189 |
return __toCommonJS(index_exports); |
| 190 |
})(); |
| 191 |
//# sourceMappingURL=index.js.map |
| 192 |
|