diff options
Diffstat (limited to 'wp-includes/js/dist/compose.js')
-rw-r--r-- | wp-includes/js/dist/compose.js | 189 |
1 files changed, 149 insertions, 40 deletions
diff --git a/wp-includes/js/dist/compose.js b/wp-includes/js/dist/compose.js index ad81bed..34a0dd1 100644 --- a/wp-includes/js/dist/compose.js +++ b/wp-includes/js/dist/compose.js @@ -2288,6 +2288,7 @@ __webpack_require__.d(__webpack_exports__, { createHigherOrderComponent: () => (/* reexport */ createHigherOrderComponent), debounce: () => (/* reexport */ debounce), ifCondition: () => (/* reexport */ if_condition), + observableMap: () => (/* reexport */ observableMap), pipe: () => (/* reexport */ higher_order_pipe), pure: () => (/* reexport */ higher_order_pure), throttle: () => (/* reexport */ throttle), @@ -2306,6 +2307,7 @@ __webpack_require__.d(__webpack_exports__, { useKeyboardShortcut: () => (/* reexport */ use_keyboard_shortcut), useMediaQuery: () => (/* reexport */ useMediaQuery), useMergeRefs: () => (/* reexport */ useMergeRefs), + useObservableValue: () => (/* reexport */ useObservableValue), usePrevious: () => (/* reexport */ usePrevious), useReducedMotion: () => (/* reexport */ use_reduced_motion), useRefEffect: () => (/* reexport */ useRefEffect), @@ -3111,6 +3113,59 @@ const throttle = (func, wait, options) => { }); }; +;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/observable-map/index.js +/** + * A constructor (factory) for `ObservableMap`, a map-like key/value data structure + * where the individual entries are observable: using the `subscribe` method, you can + * subscribe to updates for a particular keys. Each subscriber always observes one + * specific key and is not notified about any unrelated changes (for different keys) + * in the `ObservableMap`. + * + * @template K The type of the keys in the map. + * @template V The type of the values in the map. + * @return A new instance of the `ObservableMap` type. + */ +function observableMap() { + const map = new Map(); + const listeners = new Map(); + function callListeners(name) { + const list = listeners.get(name); + if (!list) { + return; + } + for (const listener of list) { + listener(); + } + } + return { + get(name) { + return map.get(name); + }, + set(name, value) { + map.set(name, value); + callListeners(name); + }, + delete(name) { + map.delete(name); + callListeners(name); + }, + subscribe(name, listener) { + let list = listeners.get(name); + if (!list) { + list = new Set(); + listeners.set(name, list); + } + list.add(listener); + return () => { + list.delete(listener); + if (list.size === 0) { + listeners.delete(name); + } + }; + } + }; +} + ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/pipe.js /** * Parts of this source were derived and modified from lodash, @@ -3157,7 +3212,7 @@ const throttle = (func, wait, options) => { * * Allows to choose whether to perform left-to-right or right-to-left composition. * - * @see https://docs-lodash.com/v4/flow/ + * @see https://lodash.com/docs/4#flow * * @param {boolean} reverse True if right-to-left, false for left-to-right composition. */ @@ -3175,7 +3230,7 @@ const basePipe = (reverse = false) => (...funcs) => (...args) => { * * This is inspired by `lodash`'s `flow` function. * - * @see https://docs-lodash.com/v4/flow/ + * @see https://lodash.com/docs/4#flow */ const pipe = basePipe(); @@ -3193,15 +3248,14 @@ const pipe = basePipe(); * * This is inspired by `lodash`'s `flowRight` function. * - * @see https://docs-lodash.com/v4/flow-right/ + * @see https://lodash.com/docs/4#flow-right */ const compose = basePipe(true); /* harmony default export */ const higher_order_compose = (compose); -;// CONCATENATED MODULE: external "React" -const external_React_namespaceObject = window["React"]; +;// CONCATENATED MODULE: external "ReactJSXRuntime" +const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/if-condition/index.js - /** * External dependencies */ @@ -3228,12 +3282,13 @@ const external_React_namespaceObject = window["React"]; * * @return Higher-order component. */ + function ifCondition(predicate) { return createHigherOrderComponent(WrappedComponent => props => { if (!predicate(props)) { return null; } - return (0,external_React_namespaceObject.createElement)(WrappedComponent, { + return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { ...props }); }, 'ifCondition'); @@ -3246,7 +3301,6 @@ var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(exte ;// CONCATENATED MODULE: external ["wp","element"] const external_wp_element_namespaceObject = window["wp"]["element"]; ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/pure/index.js - /** * External dependencies */ @@ -3268,6 +3322,7 @@ const external_wp_element_namespaceObject = window["wp"]["element"]; * * @deprecated Use `memo` or `PureComponent` instead. */ + const pure = createHigherOrderComponent(function (WrappedComponent) { if (WrappedComponent.prototype instanceof external_wp_element_namespaceObject.Component) { return class extends WrappedComponent { @@ -3281,7 +3336,7 @@ const pure = createHigherOrderComponent(function (WrappedComponent) { return !external_wp_isShallowEqual_default()(nextProps, this.props); } render() { - return (0,external_React_namespaceObject.createElement)(WrappedComponent, { + return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { ...this.props }); } @@ -3332,7 +3387,6 @@ class Listener { /* harmony default export */ const listener = (Listener); ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/index.js - /** * WordPress dependencies */ @@ -3348,6 +3402,7 @@ class Listener { /** * Listener instance responsible for managing document event handling. */ + const with_global_events_listener = new listener(); /* eslint-disable jsdoc/no-undefined-types */ @@ -3413,14 +3468,14 @@ function withGlobalEvents(eventTypesToHandlers) { } } render() { - return (0,external_React_namespaceObject.createElement)(WrappedComponent, { + return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { ...this.props.ownProps, ref: this.handleRef }); } } return (0,external_wp_element_namespaceObject.forwardRef)((props, ref) => { - return (0,external_React_namespaceObject.createElement)(Wrapper, { + return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Wrapper, { ownProps: props, forwardedRef: ref }); @@ -3470,7 +3525,9 @@ function createId(object) { */ function useInstanceId(object, prefix, preferredId) { return (0,external_wp_element_namespaceObject.useMemo)(() => { - if (preferredId) return preferredId; + if (preferredId) { + return preferredId; + } const id = createId(object); return prefix ? `${prefix}-${id}` : id; }, [object, preferredId, prefix]); @@ -3478,13 +3535,13 @@ function useInstanceId(object, prefix, preferredId) { /* harmony default export */ const use_instance_id = (useInstanceId); ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-instance-id/index.js - /** * Internal dependencies */ + /** * A Higher Order Component used to be provide a unique instance ID by * component. @@ -3493,7 +3550,7 @@ const withInstanceId = createHigherOrderComponent(WrappedComponent => { return props => { const instanceId = use_instance_id(WrappedComponent); // @ts-ignore - return (0,external_React_namespaceObject.createElement)(WrappedComponent, { + return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WrappedComponent, { ...props, instanceId: instanceId }); @@ -3502,7 +3559,6 @@ const withInstanceId = createHigherOrderComponent(WrappedComponent => { /* harmony default export */ const with_instance_id = (withInstanceId); ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-safe-timeout/index.js - /** * WordPress dependencies */ @@ -3552,8 +3608,9 @@ const withSafeTimeout = createHigherOrderComponent(OriginalComponent => { } render() { return ( + /*#__PURE__*/ // @ts-ignore - (0,external_React_namespaceObject.createElement)(OriginalComponent, { + (0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, { ...this.props, setTimeout: this.setTimeout, clearTimeout: this.clearTimeout @@ -3565,7 +3622,6 @@ const withSafeTimeout = createHigherOrderComponent(OriginalComponent => { /* harmony default export */ const with_safe_timeout = (withSafeTimeout); ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-state/index.js - /** * WordPress dependencies */ @@ -3587,6 +3643,7 @@ const withSafeTimeout = createHigherOrderComponent(OriginalComponent => { * * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props. */ + function withState(initialState = {}) { external_wp_deprecated_default()('wp.compose.withState', { since: '5.8', @@ -3600,7 +3657,7 @@ function withState(initialState = {}) { this.state = initialState; } render() { - return (0,external_React_namespaceObject.createElement)(OriginalComponent, { + return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(OriginalComponent, { ...this.props, ...this.state, setState: this.setState @@ -3706,7 +3763,6 @@ function useConstrainedTabbing() { // See https://github.com/WordPress/gutenberg/issues/46041. if ( /** @type {HTMLElement} */target.contains(nextElement)) { event.preventDefault(); - /** @type {HTMLElement} */ nextElement?.focus(); return; } @@ -3897,6 +3953,11 @@ const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; /** + * Internal dependencies + */ + + +/** * Hook used to focus the first tabbable element on mount. * * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode. @@ -3940,14 +4001,7 @@ function useFocusOnMount(focusOnMount = 'firstElement') { (0,external_wp_element_namespaceObject.useEffect)(() => { focusOnMountRef.current = focusOnMount; }, [focusOnMount]); - (0,external_wp_element_namespaceObject.useEffect)(() => { - return () => { - if (timerId.current) { - clearTimeout(timerId.current); - } - }; - }, []); - return (0,external_wp_element_namespaceObject.useCallback)(node => { + return useRefEffect(node => { var _node$ownerDocument$a; if (!node || focusOnMountRef.current === false) { return; @@ -3959,12 +4013,17 @@ function useFocusOnMount(focusOnMount = 'firstElement') { timerId.current = setTimeout(() => { const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0]; if (firstTabbable) { - setFocus( /** @type {HTMLElement} */firstTabbable); + setFocus(firstTabbable); } }, 0); return; } setFocus(node); + return () => { + if (timerId.current) { + clearTimeout(timerId.current); + } + }; }, []); } @@ -4651,6 +4710,7 @@ shortcuts, callback, { * WordPress dependencies */ +const matchMediaCache = new Map(); /** * A new MediaQueryList object for the media query @@ -4659,8 +4719,17 @@ shortcuts, callback, { * @return {MediaQueryList|null} A new object for the media query */ function getMediaQueryList(query) { - if (query && typeof window !== 'undefined' && typeof window.matchMedia === 'function') { - return window.matchMedia(query); + if (!query) { + return null; + } + let match = matchMediaCache.get(query); + if (match) { + return match; + } + if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') { + match = window.matchMedia(query); + matchMediaCache.set(query, match); + return match; } return null; } @@ -4910,7 +4979,6 @@ useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provide /* harmony default export */ const use_viewport_match = (useViewportMatch); ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/index.js - /** * External dependencies */ @@ -4919,6 +4987,7 @@ useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provide * WordPress dependencies */ + // This of course could've been more streamlined with internal state instead of // refs, but then host hooks / components could not opt out of renders. // This could've been exported to its own module, but the current build doesn't @@ -4971,6 +5040,10 @@ function useResolvedElement(subscriber, refOrElement) { callSubscriber(); }, [callSubscriber]); } + +// Declaring my own type here instead of using the one provided by TS (available since 4.2.2), because this way I'm not +// forcing consumers to use a specific TS version. + // We're only using the first element of the size sequences, until future versions of the spec solidify on how // exactly it'll be used for fragments in multi-column scenarios: // From the spec: @@ -5133,7 +5206,7 @@ function useResizeAware() { height: height !== null && height !== void 0 ? height : null }; }, [width, height]); - const resizeListener = (0,external_React_namespaceObject.createElement)("div", { + const resizeListener = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { style: { position: 'absolute', top: 0, @@ -5254,6 +5327,8 @@ function useWarnOnChange(object, prefix = 'Change detection') { } /* harmony default export */ const use_warn_on_change = (useWarnOnChange); +;// CONCATENATED MODULE: external "React" +const external_React_namespaceObject = window["React"]; ;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js @@ -5323,7 +5398,7 @@ var useCallback = (/* unused pure expression or super */ null && (useCallbackOne * including the function to debounce, so please wrap functions created on * render in components in `useCallback`. * - * @see https://docs-lodash.com/v4/debounce/ + * @see https://lodash.com/docs/4#debounce * * @template {(...args: any[]) => void} TFunc * @@ -5352,8 +5427,8 @@ function useDebounce(fn, wait, options) { /** * Helper hook for input fields that need to debounce the value before using it. * - * @param {any} defaultValue The default value to use. - * @return {[string, Function, string]} The input value, the setter and the debounced input value. + * @param defaultValue The default value to use. + * @return The input value, the setter and the debounced input value. */ function useDebouncedInput(defaultValue = '') { const [input, setInput] = (0,external_wp_element_namespaceObject.useState)(defaultValue); @@ -5361,7 +5436,7 @@ function useDebouncedInput(defaultValue = '') { const setDebouncedInput = useDebounce(setDebouncedState, 250); (0,external_wp_element_namespaceObject.useEffect)(() => { setDebouncedInput(input); - }, [input]); + }, [input, setDebouncedInput]); return [input, setInput, debouncedInput]; } @@ -5387,7 +5462,7 @@ function useDebouncedInput(defaultValue = '') { * including the function to throttle, so please wrap functions created on * render in components in `useCallback`. * - * @see https://docs-lodash.com/v4/throttle/ + * @see https://lodash.com/docs/4#throttle * * @template {(...args: any[]) => void} TFunc * @@ -5633,11 +5708,15 @@ function useFocusableIframe() { const { ownerDocument } = element; - if (!ownerDocument) return; + if (!ownerDocument) { + return; + } const { defaultView } = ownerDocument; - if (!defaultView) return; + if (!defaultView) { + return; + } /** * Checks whether the iframe is the activeElement, inferring that it has @@ -5791,6 +5870,33 @@ function useFixedWindowList(elementRef, itemHeight, totalItems, options) { return [fixedListWindow, setFixedListWindow]; } +;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-observable-value/index.js +/** + * WordPress dependencies + */ + + +/** + * Internal dependencies + */ + +/** + * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the + * current value corresponding to the key, or `undefined` when there is no value stored. + * It also observes changes to the value and triggers an update of the calling component + * in case the value changes. + * + * @template K The type of the keys in the map. + * @template V The type of the values in the map. + * @param map The `ObservableMap` to observe. + * @param name The map key to observe. + * @return The value corresponding to the map key requested. + */ +function useObservableValue(map, name) { + const [subscribe, getValue] = (0,external_wp_element_namespaceObject.useMemo)(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]); + return (0,external_wp_element_namespaceObject.useSyncExternalStore)(subscribe, getValue, getValue); +} + ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/index.js // The `createHigherOrderComponent` helper and helper types. @@ -5798,6 +5904,8 @@ function useFixedWindowList(elementRef, itemHeight, totalItems, options) { // The `throttle` helper and its types. +// The `ObservableMap` data structure + // The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash). @@ -5841,6 +5949,7 @@ function useFixedWindowList(elementRef, itemHeight, totalItems, options) { + })(); (window.wp = window.wp || {}).compose = __webpack_exports__; |