[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/ -> notices.js (source)

   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    // package-external:@wordpress/components
  43    var require_components = __commonJS({
  44      "package-external:@wordpress/components"(exports, module) {
  45        module.exports = window.wp.components;
  46      }
  47    });
  48  
  49    // vendor-external:react/jsx-runtime
  50    var require_jsx_runtime = __commonJS({
  51      "vendor-external:react/jsx-runtime"(exports, module) {
  52        module.exports = window.ReactJSXRuntime;
  53      }
  54    });
  55  
  56    // packages/notices/build-module/index.mjs
  57    var index_exports = {};
  58    __export(index_exports, {
  59      InlineNotices: () => InlineNotices,
  60      SnackbarNotices: () => SnackbarNotices,
  61      store: () => store
  62    });
  63  
  64    // packages/notices/build-module/store/index.mjs
  65    var import_data2 = __toESM(require_data(), 1);
  66  
  67    // packages/notices/build-module/store/reducer.mjs
  68    var import_data = __toESM(require_data(), 1);
  69    var notices = (0, import_data.keyedReducer)("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        default:
  83          return state;
  84      }
  85    });
  86    var reducer_default = notices;
  87  
  88    // packages/notices/build-module/store/actions.mjs
  89    var actions_exports = {};
  90    __export(actions_exports, {
  91      createErrorNotice: () => createErrorNotice,
  92      createInfoNotice: () => createInfoNotice,
  93      createNotice: () => createNotice,
  94      createSuccessNotice: () => createSuccessNotice,
  95      createWarningNotice: () => createWarningNotice,
  96      removeAllNotices: () => removeAllNotices,
  97      removeNotice: () => removeNotice,
  98      removeNotices: () => removeNotices
  99    });
 100  
 101    // packages/notices/build-module/store/constants.mjs
 102    var DEFAULT_CONTEXT = "global";
 103    var DEFAULT_STATUS = "info";
 104  
 105    // packages/notices/build-module/store/actions.mjs
 106    var uniqueId = 0;
 107    function createNotice(status = DEFAULT_STATUS, content, options = {}) {
 108      const {
 109        speak = true,
 110        isDismissible = true,
 111        context = DEFAULT_CONTEXT,
 112        id = `$context}${++uniqueId}`,
 113        actions = [],
 114        type = "default",
 115        __unstableHTML,
 116        icon = null,
 117        explicitDismiss = false,
 118        onDismiss
 119      } = options;
 120      content = String(content);
 121      return {
 122        type: "CREATE_NOTICE",
 123        context,
 124        notice: {
 125          id,
 126          status,
 127          content,
 128          spokenMessage: speak ? content : null,
 129          __unstableHTML,
 130          isDismissible,
 131          actions,
 132          type,
 133          icon,
 134          explicitDismiss,
 135          onDismiss
 136        }
 137      };
 138    }
 139    function createSuccessNotice(content, options) {
 140      return createNotice("success", content, options);
 141    }
 142    function createInfoNotice(content, options) {
 143      return createNotice("info", content, options);
 144    }
 145    function createErrorNotice(content, options) {
 146      return createNotice("error", content, options);
 147    }
 148    function createWarningNotice(content, options) {
 149      return createNotice("warning", content, options);
 150    }
 151    function removeNotice(id, context = DEFAULT_CONTEXT) {
 152      return {
 153        type: "REMOVE_NOTICE",
 154        id,
 155        context
 156      };
 157    }
 158    function removeAllNotices(noticeType = "default", context = DEFAULT_CONTEXT) {
 159      return {
 160        type: "REMOVE_ALL_NOTICES",
 161        noticeType,
 162        context
 163      };
 164    }
 165    function removeNotices(ids, context = DEFAULT_CONTEXT) {
 166      return {
 167        type: "REMOVE_NOTICES",
 168        ids,
 169        context
 170      };
 171    }
 172  
 173    // packages/notices/build-module/store/selectors.mjs
 174    var selectors_exports = {};
 175    __export(selectors_exports, {
 176      getNotices: () => getNotices
 177    });
 178    var DEFAULT_NOTICES = [];
 179    function getNotices(state, context = DEFAULT_CONTEXT) {
 180      return state[context] || DEFAULT_NOTICES;
 181    }
 182  
 183    // packages/notices/build-module/store/index.mjs
 184    var store = (0, import_data2.createReduxStore)("core/notices", {
 185      reducer: reducer_default,
 186      actions: actions_exports,
 187      selectors: selectors_exports
 188    });
 189    (0, import_data2.register)(store);
 190  
 191    // node_modules/clsx/dist/clsx.mjs
 192    function r(e) {
 193      var t, f, n = "";
 194      if ("string" == typeof e || "number" == typeof e) n += e;
 195      else if ("object" == typeof e) if (Array.isArray(e)) {
 196        var o = e.length;
 197        for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
 198      } else for (f in e) e[f] && (n && (n += " "), n += f);
 199      return n;
 200    }
 201    function clsx() {
 202      for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
 203      return n;
 204    }
 205    var clsx_default = clsx;
 206  
 207    // packages/notices/build-module/components/inline-notices/index.mjs
 208    var import_components = __toESM(require_components(), 1);
 209    var import_data3 = __toESM(require_data(), 1);
 210    var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
 211    function hasRenderableChildren(children) {
 212      return children !== null && children !== void 0 && children !== false && children !== "";
 213    }
 214    function InlineNotices({
 215      children,
 216      className,
 217      pinnedNoticesClassName,
 218      dismissibleNoticesClassName,
 219      context
 220    }) {
 221      const notices2 = (0, import_data3.useSelect)(
 222        (select) => select(store).getNotices(context),
 223        [context]
 224      );
 225      const { removeNotice: removeNotice2 } = (0, import_data3.useDispatch)(store);
 226      const dismissibleNotices = notices2.filter(
 227        ({ isDismissible, type }) => isDismissible && type === "default"
 228      );
 229      const nonDismissibleNotices = notices2.filter(
 230        ({ isDismissible, type }) => !isDismissible && type === "default"
 231      );
 232      const hasPinnedNotices = nonDismissibleNotices.length > 0;
 233      const hasDismissibleNotices = dismissibleNotices.length > 0 || hasRenderableChildren(children);
 234      if (!hasPinnedNotices && !hasDismissibleNotices) {
 235        return null;
 236      }
 237      return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: clsx_default("notices-inline-notices-wrapper", className), children: [
 238        hasPinnedNotices && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
 239          import_components.NoticeList,
 240          {
 241            notices: nonDismissibleNotices,
 242            className: clsx_default(
 243              "components-notices__pinned",
 244              pinnedNoticesClassName
 245            )
 246          }
 247        ),
 248        hasDismissibleNotices && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
 249          import_components.NoticeList,
 250          {
 251            notices: dismissibleNotices,
 252            className: clsx_default(
 253              "components-notices__dismissible",
 254              dismissibleNoticesClassName
 255            ),
 256            onRemove: (id) => removeNotice2(id, context),
 257            children
 258          }
 259        )
 260      ] });
 261    }
 262  
 263    // packages/notices/build-module/components/snackbar-notices/index.mjs
 264    var import_components2 = __toESM(require_components(), 1);
 265    var import_data4 = __toESM(require_data(), 1);
 266    var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
 267    var MAX_VISIBLE_NOTICES = -3;
 268    function SnackbarNotices({
 269      className,
 270      context
 271    }) {
 272      const notices2 = (0, import_data4.useSelect)(
 273        (select) => select(store).getNotices(context),
 274        [context]
 275      );
 276      const { removeNotice: removeNotice2 } = (0, import_data4.useDispatch)(store);
 277      const snackbarNotices = notices2.filter(({ type }) => type === "snackbar").slice(MAX_VISIBLE_NOTICES);
 278      return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
 279        import_components2.SnackbarList,
 280        {
 281          notices: snackbarNotices,
 282          className: clsx_default("components-notices__snackbar", className),
 283          onRemove: (id) => removeNotice2(id, context)
 284        }
 285      );
 286    }
 287    return __toCommonJS(index_exports);
 288  })();


Generated : Fri Jul 10 08:20:14 2026 Cross-referenced by PHPXref