[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  (function() {
   2  "use strict";
   3  var wp;
   4  (wp ||= {}).notices = (() => {
   5    var __create = Object.create;
   6    var __defProp = Object.defineProperty;
   7    var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
   8    var __getOwnPropNames = Object.getOwnPropertyNames;
   9    var __getProtoOf = Object.getPrototypeOf;
  10    var __hasOwnProp = Object.prototype.hasOwnProperty;
  11    var __commonJS = (cb, mod) => function __require() {
  12      return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  13    };
  14    var __export = (target, all) => {
  15      for (var name in all)
  16        __defProp(target, name, { get: all[name], enumerable: true });
  17    };
  18    var __copyProps = (to, from, except, desc) => {
  19      if (from && typeof from === "object" || typeof from === "function") {
  20        for (let key of __getOwnPropNames(from))
  21          if (!__hasOwnProp.call(to, key) && key !== except)
  22            __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23      }
  24      return to;
  25    };
  26    var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  27      // If the importer is in node compatibility mode or this is not an ESM
  28      // file that has been converted to a CommonJS file using a Babel-
  29      // compatible transform (i.e. "__esModule" has not been set), then set
  30      // "default" to the CommonJS "module.exports" for node compatibility.
  31      isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  32      mod
  33    ));
  34    var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  35  
  36    // package-external:@wordpress/data
  37    var require_data = __commonJS({
  38      "package-external:@wordpress/data"(exports, module) {
  39        module.exports = window.wp.data;
  40      }
  41    });
  42  
  43    // package-external:@wordpress/components
  44    var require_components = __commonJS({
  45      "package-external:@wordpress/components"(exports, module) {
  46        module.exports = window.wp.components;
  47      }
  48    });
  49  
  50    // vendor-external:react/jsx-runtime
  51    var require_jsx_runtime = __commonJS({
  52      "vendor-external:react/jsx-runtime"(exports, module) {
  53        module.exports = window.ReactJSXRuntime;
  54      }
  55    });
  56  
  57    // packages/notices/build-module/index.mjs
  58    var index_exports = {};
  59    __export(index_exports, {
  60      InlineNotices: () => InlineNotices,
  61      SnackbarNotices: () => SnackbarNotices,
  62      store: () => store
  63    });
  64  
  65    // packages/notices/build-module/store/index.mjs
  66    var import_data2 = __toESM(require_data(), 1);
  67  
  68    // packages/notices/build-module/store/reducer.mjs
  69    var import_data = __toESM(require_data(), 1);
  70    var notices = (0, import_data.keyedReducer)("context")((state = [], action) => {
  71      switch (action.type) {
  72        case "CREATE_NOTICE":
  73          return [
  74            ...state.filter(({ id }) => id !== action.notice.id),
  75            action.notice
  76          ];
  77        case "REMOVE_NOTICE":
  78          return state.filter(({ id }) => id !== action.id);
  79        case "REMOVE_NOTICES":
  80          return state.filter(({ id }) => !action.ids.includes(id));
  81        case "REMOVE_ALL_NOTICES":
  82          return state.filter(({ type }) => type !== action.noticeType);
  83        default:
  84          return state;
  85      }
  86    });
  87    var reducer_default = notices;
  88  
  89    // packages/notices/build-module/store/actions.mjs
  90    var actions_exports = {};
  91    __export(actions_exports, {
  92      createErrorNotice: () => createErrorNotice,
  93      createInfoNotice: () => createInfoNotice,
  94      createNotice: () => createNotice,
  95      createSuccessNotice: () => createSuccessNotice,
  96      createWarningNotice: () => createWarningNotice,
  97      removeAllNotices: () => removeAllNotices,
  98      removeNotice: () => removeNotice,
  99      removeNotices: () => removeNotices
 100    });
 101  
 102    // packages/notices/build-module/store/constants.mjs
 103    var DEFAULT_CONTEXT = "global";
 104    var DEFAULT_STATUS = "info";
 105  
 106    // packages/notices/build-module/store/actions.mjs
 107    var uniqueId = 0;
 108    function createNotice(status = DEFAULT_STATUS, content, options = {}) {
 109      const {
 110        speak = true,
 111        isDismissible = true,
 112        context = DEFAULT_CONTEXT,
 113        id = `$context}${++uniqueId}`,
 114        actions = [],
 115        type = "default",
 116        __unstableHTML,
 117        icon = null,
 118        explicitDismiss = false,
 119        onDismiss
 120      } = options;
 121      content = String(content);
 122      return {
 123        type: "CREATE_NOTICE",
 124        context,
 125        notice: {
 126          id,
 127          status,
 128          content,
 129          spokenMessage: speak ? content : null,
 130          __unstableHTML,
 131          isDismissible,
 132          actions,
 133          type,
 134          icon,
 135          explicitDismiss,
 136          onDismiss
 137        }
 138      };
 139    }
 140    function createSuccessNotice(content, options) {
 141      return createNotice("success", content, options);
 142    }
 143    function createInfoNotice(content, options) {
 144      return createNotice("info", content, options);
 145    }
 146    function createErrorNotice(content, options) {
 147      return createNotice("error", content, options);
 148    }
 149    function createWarningNotice(content, options) {
 150      return createNotice("warning", content, options);
 151    }
 152    function removeNotice(id, context = DEFAULT_CONTEXT) {
 153      return {
 154        type: "REMOVE_NOTICE",
 155        id,
 156        context
 157      };
 158    }
 159    function removeAllNotices(noticeType = "default", context = DEFAULT_CONTEXT) {
 160      return {
 161        type: "REMOVE_ALL_NOTICES",
 162        noticeType,
 163        context
 164      };
 165    }
 166    function removeNotices(ids, context = DEFAULT_CONTEXT) {
 167      return {
 168        type: "REMOVE_NOTICES",
 169        ids,
 170        context
 171      };
 172    }
 173  
 174    // packages/notices/build-module/store/selectors.mjs
 175    var selectors_exports = {};
 176    __export(selectors_exports, {
 177      getNotices: () => getNotices
 178    });
 179    var DEFAULT_NOTICES = [];
 180    function getNotices(state, context = DEFAULT_CONTEXT) {
 181      return state[context] || DEFAULT_NOTICES;
 182    }
 183  
 184    // packages/notices/build-module/store/index.mjs
 185    var store = (0, import_data2.createReduxStore)("core/notices", {
 186      reducer: reducer_default,
 187      actions: actions_exports,
 188      selectors: selectors_exports
 189    });
 190    (0, import_data2.register)(store);
 191  
 192    // node_modules/clsx/dist/clsx.mjs
 193    function r(e) {
 194      var t, f, n = "";
 195      if ("string" == typeof e || "number" == typeof e) n += e;
 196      else if ("object" == typeof e) if (Array.isArray(e)) {
 197        var o = e.length;
 198        for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
 199      } else for (f in e) e[f] && (n && (n += " "), n += f);
 200      return n;
 201    }
 202    function clsx() {
 203      for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
 204      return n;
 205    }
 206    var clsx_default = clsx;
 207  
 208    // packages/notices/build-module/components/inline-notices/index.mjs
 209    var import_components = __toESM(require_components(), 1);
 210    var import_data3 = __toESM(require_data(), 1);
 211    var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
 212    function hasRenderableChildren(children) {
 213      return children !== null && children !== void 0 && children !== false && children !== "";
 214    }
 215    function InlineNotices({
 216      children,
 217      className,
 218      pinnedNoticesClassName,
 219      dismissibleNoticesClassName,
 220      context
 221    }) {
 222      const notices2 = (0, import_data3.useSelect)(
 223        (select) => select(store).getNotices(context),
 224        [context]
 225      );
 226      const { removeNotice: removeNotice2 } = (0, import_data3.useDispatch)(store);
 227      const dismissibleNotices = notices2.filter(
 228        ({ isDismissible, type }) => isDismissible && type === "default"
 229      );
 230      const nonDismissibleNotices = notices2.filter(
 231        ({ isDismissible, type }) => !isDismissible && type === "default"
 232      );
 233      const hasPinnedNotices = nonDismissibleNotices.length > 0;
 234      const hasDismissibleNotices = dismissibleNotices.length > 0 || hasRenderableChildren(children);
 235      if (!hasPinnedNotices && !hasDismissibleNotices) {
 236        return null;
 237      }
 238      return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: clsx_default("notices-inline-notices-wrapper", className), children: [
 239        hasPinnedNotices && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
 240          import_components.NoticeList,
 241          {
 242            notices: nonDismissibleNotices,
 243            className: clsx_default(
 244              "components-notices__pinned",
 245              pinnedNoticesClassName
 246            )
 247          }
 248        ),
 249        hasDismissibleNotices && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
 250          import_components.NoticeList,
 251          {
 252            notices: dismissibleNotices,
 253            className: clsx_default(
 254              "components-notices__dismissible",
 255              dismissibleNoticesClassName
 256            ),
 257            onRemove: (id) => removeNotice2(id, context),
 258            children
 259          }
 260        )
 261      ] });
 262    }
 263  
 264    // packages/notices/build-module/components/snackbar-notices/index.mjs
 265    var import_components2 = __toESM(require_components(), 1);
 266    var import_data4 = __toESM(require_data(), 1);
 267    var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
 268    var MAX_VISIBLE_NOTICES = -3;
 269    function SnackbarNotices({
 270      className,
 271      context
 272    }) {
 273      const notices2 = (0, import_data4.useSelect)(
 274        (select) => select(store).getNotices(context),
 275        [context]
 276      );
 277      const { removeNotice: removeNotice2 } = (0, import_data4.useDispatch)(store);
 278      const snackbarNotices = notices2.filter(({ type }) => type === "snackbar").slice(MAX_VISIBLE_NOTICES);
 279      return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
 280        import_components2.SnackbarList,
 281        {
 282          notices: snackbarNotices,
 283          className: clsx_default("components-notices__snackbar", className),
 284          onRemove: (id) => removeNotice2(id, context)
 285        }
 286      );
 287    }
 288    return __toCommonJS(index_exports);
 289  })();
 290  (window.wp ||= {}).notices = wp.notices;
 291  })();


Generated : Sat Aug 8 08:20:21 2026 Cross-referenced by PHPXref