[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  /******/ (() => { // webpackBootstrap
   2  /******/     "use strict";
   3  /******/     // The require scope
   4  /******/     var __webpack_require__ = {};
   5  /******/     
   6  /************************************************************************/
   7  /******/     /* webpack/runtime/compat get default export */
   8  /******/     (() => {
   9  /******/         // getDefaultExport function for compatibility with non-harmony modules
  10  /******/         __webpack_require__.n = (module) => {
  11  /******/             var getter = module && module.__esModule ?
  12  /******/                 () => (module['default']) :
  13  /******/                 () => (module);
  14  /******/             __webpack_require__.d(getter, { a: getter });
  15  /******/             return getter;
  16  /******/         };
  17  /******/     })();
  18  /******/     
  19  /******/     /* webpack/runtime/define property getters */
  20  /******/     (() => {
  21  /******/         // define getter functions for harmony exports
  22  /******/         __webpack_require__.d = (exports, definition) => {
  23  /******/             for(var key in definition) {
  24  /******/                 if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  25  /******/                     Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  26  /******/                 }
  27  /******/             }
  28  /******/         };
  29  /******/     })();
  30  /******/     
  31  /******/     /* webpack/runtime/hasOwnProperty shorthand */
  32  /******/     (() => {
  33  /******/         __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  34  /******/     })();
  35  /******/     
  36  /******/     /* webpack/runtime/make namespace object */
  37  /******/     (() => {
  38  /******/         // define __esModule on exports
  39  /******/         __webpack_require__.r = (exports) => {
  40  /******/             if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  41  /******/                 Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  42  /******/             }
  43  /******/             Object.defineProperty(exports, '__esModule', { value: true });
  44  /******/         };
  45  /******/     })();
  46  /******/     
  47  /************************************************************************/
  48  var __webpack_exports__ = {};
  49  // ESM COMPAT FLAG
  50  __webpack_require__.r(__webpack_exports__);
  51  
  52  // EXPORTS
  53  __webpack_require__.d(__webpack_exports__, {
  54    DotTip: () => (/* reexport */ dot_tip),
  55    store: () => (/* reexport */ store)
  56  });
  57  
  58  // NAMESPACE OBJECT: ./node_modules/@wordpress/nux/build-module/store/actions.js
  59  var actions_namespaceObject = {};
  60  __webpack_require__.r(actions_namespaceObject);
  61  __webpack_require__.d(actions_namespaceObject, {
  62    disableTips: () => (disableTips),
  63    dismissTip: () => (dismissTip),
  64    enableTips: () => (enableTips),
  65    triggerGuide: () => (triggerGuide)
  66  });
  67  
  68  // NAMESPACE OBJECT: ./node_modules/@wordpress/nux/build-module/store/selectors.js
  69  var selectors_namespaceObject = {};
  70  __webpack_require__.r(selectors_namespaceObject);
  71  __webpack_require__.d(selectors_namespaceObject, {
  72    areTipsEnabled: () => (selectors_areTipsEnabled),
  73    getAssociatedGuide: () => (getAssociatedGuide),
  74    isTipVisible: () => (isTipVisible)
  75  });
  76  
  77  ;// external ["wp","deprecated"]
  78  const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
  79  var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
  80  ;// external ["wp","data"]
  81  const external_wp_data_namespaceObject = window["wp"]["data"];
  82  ;// ./node_modules/@wordpress/nux/build-module/store/reducer.js
  83  /**
  84   * WordPress dependencies
  85   */
  86  
  87  
  88  /**
  89   * Reducer that tracks which tips are in a guide. Each guide is represented by
  90   * an array which contains the tip identifiers contained within that guide.
  91   *
  92   * @param {Array}  state  Current state.
  93   * @param {Object} action Dispatched action.
  94   *
  95   * @return {Array} Updated state.
  96   */
  97  function guides(state = [], action) {
  98    switch (action.type) {
  99      case 'TRIGGER_GUIDE':
 100        return [...state, action.tipIds];
 101    }
 102    return state;
 103  }
 104  
 105  /**
 106   * Reducer that tracks whether or not tips are globally enabled.
 107   *
 108   * @param {boolean} state  Current state.
 109   * @param {Object}  action Dispatched action.
 110   *
 111   * @return {boolean} Updated state.
 112   */
 113  function areTipsEnabled(state = true, action) {
 114    switch (action.type) {
 115      case 'DISABLE_TIPS':
 116        return false;
 117      case 'ENABLE_TIPS':
 118        return true;
 119    }
 120    return state;
 121  }
 122  
 123  /**
 124   * Reducer that tracks which tips have been dismissed. If the state object
 125   * contains a tip identifier, then that tip is dismissed.
 126   *
 127   * @param {Object} state  Current state.
 128   * @param {Object} action Dispatched action.
 129   *
 130   * @return {Object} Updated state.
 131   */
 132  function dismissedTips(state = {}, action) {
 133    switch (action.type) {
 134      case 'DISMISS_TIP':
 135        return {
 136          ...state,
 137          [action.id]: true
 138        };
 139      case 'ENABLE_TIPS':
 140        return {};
 141    }
 142    return state;
 143  }
 144  const preferences = (0,external_wp_data_namespaceObject.combineReducers)({
 145    areTipsEnabled,
 146    dismissedTips
 147  });
 148  /* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
 149    guides,
 150    preferences
 151  }));
 152  
 153  ;// ./node_modules/@wordpress/nux/build-module/store/actions.js
 154  /**
 155   * Returns an action object that, when dispatched, presents a guide that takes
 156   * the user through a series of tips step by step.
 157   *
 158   * @param {string[]} tipIds Which tips to show in the guide.
 159   *
 160   * @return {Object} Action object.
 161   */
 162  function triggerGuide(tipIds) {
 163    return {
 164      type: 'TRIGGER_GUIDE',
 165      tipIds
 166    };
 167  }
 168  
 169  /**
 170   * Returns an action object that, when dispatched, dismisses the given tip. A
 171   * dismissed tip will not show again.
 172   *
 173   * @param {string} id The tip to dismiss.
 174   *
 175   * @return {Object} Action object.
 176   */
 177  function dismissTip(id) {
 178    return {
 179      type: 'DISMISS_TIP',
 180      id
 181    };
 182  }
 183  
 184  /**
 185   * Returns an action object that, when dispatched, prevents all tips from
 186   * showing again.
 187   *
 188   * @return {Object} Action object.
 189   */
 190  function disableTips() {
 191    return {
 192      type: 'DISABLE_TIPS'
 193    };
 194  }
 195  
 196  /**
 197   * Returns an action object that, when dispatched, makes all tips show again.
 198   *
 199   * @return {Object} Action object.
 200   */
 201  function enableTips() {
 202    return {
 203      type: 'ENABLE_TIPS'
 204    };
 205  }
 206  
 207  ;// ./node_modules/@wordpress/nux/build-module/store/selectors.js
 208  /* wp:polyfill */
 209  /**
 210   * WordPress dependencies
 211   */
 212  
 213  
 214  /**
 215   * An object containing information about a guide.
 216   *
 217   * @typedef {Object} NUXGuideInfo
 218   * @property {string[]} tipIds       Which tips the guide contains.
 219   * @property {?string}  currentTipId The guide's currently showing tip.
 220   * @property {?string}  nextTipId    The guide's next tip to show.
 221   */
 222  
 223  /**
 224   * Returns an object describing the guide, if any, that the given tip is a part
 225   * of.
 226   *
 227   * @param {Object} state Global application state.
 228   * @param {string} tipId The tip to query.
 229   *
 230   * @return {?NUXGuideInfo} Information about the associated guide.
 231   */
 232  const getAssociatedGuide = (0,external_wp_data_namespaceObject.createSelector)((state, tipId) => {
 233    for (const tipIds of state.guides) {
 234      if (tipIds.includes(tipId)) {
 235        const nonDismissedTips = tipIds.filter(tId => !Object.keys(state.preferences.dismissedTips).includes(tId));
 236        const [currentTipId = null, nextTipId = null] = nonDismissedTips;
 237        return {
 238          tipIds,
 239          currentTipId,
 240          nextTipId
 241        };
 242      }
 243    }
 244    return null;
 245  }, state => [state.guides, state.preferences.dismissedTips]);
 246  
 247  /**
 248   * Determines whether or not the given tip is showing. Tips are hidden if they
 249   * are disabled, have been dismissed, or are not the current tip in any
 250   * guide that they have been added to.
 251   *
 252   * @param {Object} state Global application state.
 253   * @param {string} tipId The tip to query.
 254   *
 255   * @return {boolean} Whether or not the given tip is showing.
 256   */
 257  function isTipVisible(state, tipId) {
 258    if (!state.preferences.areTipsEnabled) {
 259      return false;
 260    }
 261    if (state.preferences.dismissedTips?.hasOwnProperty(tipId)) {
 262      return false;
 263    }
 264    const associatedGuide = getAssociatedGuide(state, tipId);
 265    if (associatedGuide && associatedGuide.currentTipId !== tipId) {
 266      return false;
 267    }
 268    return true;
 269  }
 270  
 271  /**
 272   * Returns whether or not tips are globally enabled.
 273   *
 274   * @param {Object} state Global application state.
 275   *
 276   * @return {boolean} Whether tips are globally enabled.
 277   */
 278  function selectors_areTipsEnabled(state) {
 279    return state.preferences.areTipsEnabled;
 280  }
 281  
 282  ;// ./node_modules/@wordpress/nux/build-module/store/index.js
 283  /**
 284   * WordPress dependencies
 285   */
 286  
 287  
 288  /**
 289   * Internal dependencies
 290   */
 291  
 292  
 293  
 294  const STORE_NAME = 'core/nux';
 295  
 296  /**
 297   * Store definition for the nux namespace.
 298   *
 299   * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
 300   *
 301   * @type {Object}
 302   */
 303  const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
 304    reducer: reducer,
 305    actions: actions_namespaceObject,
 306    selectors: selectors_namespaceObject,
 307    persist: ['preferences']
 308  });
 309  
 310  // Once we build a more generic persistence plugin that works across types of stores
 311  // we'd be able to replace this with a register call.
 312  (0,external_wp_data_namespaceObject.registerStore)(STORE_NAME, {
 313    reducer: reducer,
 314    actions: actions_namespaceObject,
 315    selectors: selectors_namespaceObject,
 316    persist: ['preferences']
 317  });
 318  
 319  ;// external ["wp","compose"]
 320  const external_wp_compose_namespaceObject = window["wp"]["compose"];
 321  ;// external ["wp","components"]
 322  const external_wp_components_namespaceObject = window["wp"]["components"];
 323  ;// external ["wp","i18n"]
 324  const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
 325  ;// external ["wp","element"]
 326  const external_wp_element_namespaceObject = window["wp"]["element"];
 327  ;// external ["wp","primitives"]
 328  const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
 329  ;// external "ReactJSXRuntime"
 330  const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
 331  ;// ./node_modules/@wordpress/icons/build-module/library/close.js
 332  /**
 333   * WordPress dependencies
 334   */
 335  
 336  
 337  const close_close = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
 338    xmlns: "http://www.w3.org/2000/svg",
 339    viewBox: "0 0 24 24",
 340    children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
 341      d: "m13.06 12 6.47-6.47-1.06-1.06L12 10.94 5.53 4.47 4.47 5.53 10.94 12l-6.47 6.47 1.06 1.06L12 13.06l6.47 6.47 1.06-1.06L13.06 12Z"
 342    })
 343  });
 344  /* harmony default export */ const library_close = (close_close);
 345  
 346  ;// ./node_modules/@wordpress/nux/build-module/components/dot-tip/index.js
 347  /**
 348   * WordPress dependencies
 349   */
 350  
 351  
 352  
 353  
 354  
 355  
 356  
 357  /**
 358   * Internal dependencies
 359   */
 360  
 361  
 362  function onClick(event) {
 363    // Tips are often nested within buttons. We stop propagation so that clicking
 364    // on a tip doesn't result in the button being clicked.
 365    event.stopPropagation();
 366  }
 367  function DotTip({
 368    position = 'middle right',
 369    children,
 370    isVisible,
 371    hasNextTip,
 372    onDismiss,
 373    onDisable
 374  }) {
 375    const anchorParent = (0,external_wp_element_namespaceObject.useRef)(null);
 376    const onFocusOutsideCallback = (0,external_wp_element_namespaceObject.useCallback)(event => {
 377      if (!anchorParent.current) {
 378        return;
 379      }
 380      if (anchorParent.current.contains(event.relatedTarget)) {
 381        return;
 382      }
 383      onDisable();
 384    }, [onDisable, anchorParent]);
 385    if (!isVisible) {
 386      return null;
 387    }
 388    return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.Popover, {
 389      className: "nux-dot-tip",
 390      position: position,
 391      focusOnMount: true,
 392      role: "dialog",
 393      "aria-label": (0,external_wp_i18n_namespaceObject.__)('Editor tips'),
 394      onClick: onClick,
 395      onFocusOutside: onFocusOutsideCallback,
 396      children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
 397        children: children
 398      }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
 399        children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
 400          __next40pxDefaultSize: true,
 401          variant: "link",
 402          onClick: onDismiss,
 403          children: hasNextTip ? (0,external_wp_i18n_namespaceObject.__)('See next tip') : (0,external_wp_i18n_namespaceObject.__)('Got it')
 404        })
 405      }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
 406        size: "small",
 407        className: "nux-dot-tip__disable",
 408        icon: library_close,
 409        label: (0,external_wp_i18n_namespaceObject.__)('Disable tips'),
 410        onClick: onDisable
 411      })]
 412    });
 413  }
 414  /* harmony default export */ const dot_tip = ((0,external_wp_compose_namespaceObject.compose)((0,external_wp_data_namespaceObject.withSelect)((select, {
 415    tipId
 416  }) => {
 417    const {
 418      isTipVisible,
 419      getAssociatedGuide
 420    } = select(store);
 421    const associatedGuide = getAssociatedGuide(tipId);
 422    return {
 423      isVisible: isTipVisible(tipId),
 424      hasNextTip: !!(associatedGuide && associatedGuide.nextTipId)
 425    };
 426  }), (0,external_wp_data_namespaceObject.withDispatch)((dispatch, {
 427    tipId
 428  }) => {
 429    const {
 430      dismissTip,
 431      disableTips
 432    } = dispatch(store);
 433    return {
 434      onDismiss() {
 435        dismissTip(tipId);
 436      },
 437      onDisable() {
 438        disableTips();
 439      }
 440    };
 441  }))(DotTip));
 442  
 443  ;// ./node_modules/@wordpress/nux/build-module/index.js
 444  /**
 445   * WordPress dependencies
 446   */
 447  
 448  
 449  
 450  external_wp_deprecated_default()('wp.nux', {
 451    since: '5.4',
 452    hint: 'wp.components.Guide can be used to show a user guide.',
 453    version: '6.2'
 454  });
 455  
 456  (window.wp = window.wp || {}).nux = __webpack_exports__;
 457  /******/ })()
 458  ;


Generated : Sat Feb 22 08:20:01 2025 Cross-referenced by PHPXref