fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

View File

@@ -0,0 +1,124 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.useNavigateRegions = useNavigateRegions;
var _react = require("react");
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
var _keycodes = require("@wordpress/keycodes");
/**
* WordPress dependencies
*/
const defaultShortcuts = {
previous: [{
modifier: 'ctrlShift',
character: '`'
}, {
modifier: 'ctrlShift',
character: '~'
}, {
modifier: 'access',
character: 'p'
}],
next: [{
modifier: 'ctrl',
character: '`'
}, {
modifier: 'access',
character: 'n'
}]
};
function useNavigateRegions(shortcuts = defaultShortcuts) {
const ref = (0, _element.useRef)(null);
const [isFocusingRegions, setIsFocusingRegions] = (0, _element.useState)(false);
function focusRegion(offset) {
var _ref$current$querySel;
const regions = Array.from((_ref$current$querySel = ref.current?.querySelectorAll('[role="region"][tabindex="-1"]')) !== null && _ref$current$querySel !== void 0 ? _ref$current$querySel : []);
if (!regions.length) {
return;
}
let nextRegion = regions[0];
// Based off the current element, use closest to determine the wrapping region since this operates up the DOM. Also, match tabindex to avoid edge cases with regions we do not want.
const wrappingRegion = ref.current?.ownerDocument?.activeElement?.closest('[role="region"][tabindex="-1"]');
const selectedIndex = wrappingRegion ? regions.indexOf(wrappingRegion) : -1;
if (selectedIndex !== -1) {
let nextIndex = selectedIndex + offset;
nextIndex = nextIndex === -1 ? regions.length - 1 : nextIndex;
nextIndex = nextIndex === regions.length ? 0 : nextIndex;
nextRegion = regions[nextIndex];
}
nextRegion.focus();
setIsFocusingRegions(true);
}
const clickRef = (0, _compose.useRefEffect)(element => {
function onClick() {
setIsFocusingRegions(false);
}
element.addEventListener('click', onClick);
return () => {
element.removeEventListener('click', onClick);
};
}, [setIsFocusingRegions]);
return {
ref: (0, _compose.useMergeRefs)([ref, clickRef]),
className: isFocusingRegions ? 'is-focusing-regions' : '',
onKeyDown(event) {
if (shortcuts.previous.some(({
modifier,
character
}) => {
return _keycodes.isKeyboardEvent[modifier](event, character);
})) {
focusRegion(-1);
} else if (shortcuts.next.some(({
modifier,
character
}) => {
return _keycodes.isKeyboardEvent[modifier](event, character);
})) {
focusRegion(1);
}
}
};
}
/**
* `navigateRegions` is a React [higher-order component](https://facebook.github.io/react/docs/higher-order-components.html)
* adding keyboard navigation to switch between the different DOM elements marked as "regions" (role="region").
* These regions should be focusable (By adding a tabIndex attribute for example). For better accessibility,
* these elements must be properly labelled to briefly describe the purpose of the content in the region.
* For more details, see "Landmark Roles" in the [WAI-ARIA specification](https://www.w3.org/TR/wai-aria/)
* and "Landmark Regions" in the [ARIA Authoring Practices Guide](https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/).
*
* ```jsx
* import { navigateRegions } from '@wordpress/components';
*
* const MyComponentWithNavigateRegions = navigateRegions( () => (
* <div>
* <div role="region" tabIndex="-1" aria-label="Header">
* Header
* </div>
* <div role="region" tabIndex="-1" aria-label="Content">
* Content
* </div>
* <div role="region" tabIndex="-1" aria-label="Sidebar">
* Sidebar
* </div>
* </div>
* ) );
* ```
*/
var _default = (0, _compose.createHigherOrderComponent)(Component => ({
shortcuts,
...props
}) => (0, _react.createElement)("div", {
...useNavigateRegions(shortcuts)
}, (0, _react.createElement)(Component, {
...props
})), 'navigateRegions');
exports.default = _default;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _compose = require("@wordpress/compose");
/**
* WordPress dependencies
*/
/**
* `withConstrainedTabbing` is a React [higher-order component](https://facebook.github.io/react/docs/higher-order-components.html)
* adding the ability to constrain keyboard navigation with the Tab key within a component.
* For accessibility reasons, some UI components need to constrain Tab navigation, for example
* modal dialogs or similar UI. Use of this component is recommended only in cases where a way to
* navigate away from the wrapped component is implemented by other means, usually by pressing
* the Escape key or using a specific UI control, e.g. a "Close" button.
*/
const withConstrainedTabbing = (0, _compose.createHigherOrderComponent)(WrappedComponent => function ComponentWithConstrainedTabbing(props) {
const ref = (0, _compose.useConstrainedTabbing)();
return (0, _react.createElement)("div", {
ref: ref,
tabIndex: -1
}, (0, _react.createElement)(WrappedComponent, {
...props
}));
}, 'withConstrainedTabbing');
var _default = withConstrainedTabbing;
exports.default = _default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_compose","require","withConstrainedTabbing","createHigherOrderComponent","WrappedComponent","ComponentWithConstrainedTabbing","props","ref","useConstrainedTabbing","_react","createElement","tabIndex","_default","exports","default"],"sources":["@wordpress/components/src/higher-order/with-constrained-tabbing/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateHigherOrderComponent,\n\tuseConstrainedTabbing,\n} from '@wordpress/compose';\n\n/**\n * `withConstrainedTabbing` is a React [higher-order component](https://facebook.github.io/react/docs/higher-order-components.html)\n * adding the ability to constrain keyboard navigation with the Tab key within a component.\n * For accessibility reasons, some UI components need to constrain Tab navigation, for example\n * modal dialogs or similar UI. Use of this component is recommended only in cases where a way to\n * navigate away from the wrapped component is implemented by other means, usually by pressing\n * the Escape key or using a specific UI control, e.g. a \"Close\" button.\n */\nconst withConstrainedTabbing = createHigherOrderComponent(\n\t( WrappedComponent ) =>\n\t\tfunction ComponentWithConstrainedTabbing( props ) {\n\t\t\tconst ref = useConstrainedTabbing();\n\t\t\treturn (\n\t\t\t\t<div ref={ ref } tabIndex={ -1 }>\n\t\t\t\t\t<WrappedComponent { ...props } />\n\t\t\t\t</div>\n\t\t\t);\n\t\t},\n\t'withConstrainedTabbing'\n);\n\nexport default withConstrainedTabbing;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAAG,IAAAC,mCAA0B,EACtDC,gBAAgB,IACjB,SAASC,+BAA+BA,CAAEC,KAAK,EAAG;EACjD,MAAMC,GAAG,GAAG,IAAAC,8BAAqB,EAAC,CAAC;EACnC,OACC,IAAAC,MAAA,CAAAC,aAAA;IAAKH,GAAG,EAAGA,GAAK;IAACI,QAAQ,EAAG,CAAC;EAAG,GAC/B,IAAAF,MAAA,CAAAC,aAAA,EAACN,gBAAgB;IAAA,GAAME;EAAK,CAAI,CAC5B,CAAC;AAER,CAAC,EACF,wBACD,CAAC;AAAC,IAAAM,QAAA,GAEaV,sBAAsB;AAAAW,OAAA,CAAAC,OAAA,GAAAF,QAAA"}

View File

@@ -0,0 +1,68 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _es = _interopRequireDefault(require("fast-deep-equal/es6"));
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
var _default = mapNodeToProps => (0, _compose.createHigherOrderComponent)(WrappedComponent => {
return class extends _element.Component {
constructor(props) {
super(props);
this.nodeRef = this.props.node;
this.state = {
fallbackStyles: undefined,
grabStylesCompleted: false
};
this.bindRef = this.bindRef.bind(this);
}
bindRef(node) {
if (!node) {
return;
}
this.nodeRef = node;
}
componentDidMount() {
this.grabFallbackStyles();
}
componentDidUpdate() {
this.grabFallbackStyles();
}
grabFallbackStyles() {
const {
grabStylesCompleted,
fallbackStyles
} = this.state;
if (this.nodeRef && !grabStylesCompleted) {
const newFallbackStyles = mapNodeToProps(this.nodeRef, this.props);
if (!(0, _es.default)(newFallbackStyles, fallbackStyles)) {
this.setState({
fallbackStyles: newFallbackStyles,
grabStylesCompleted: Object.values(newFallbackStyles).every(Boolean)
});
}
}
}
render() {
const wrappedComponent = (0, _react.createElement)(WrappedComponent, {
...this.props,
...this.state.fallbackStyles
});
return this.props.node ? wrappedComponent : (0, _react.createElement)("div", {
ref: this.bindRef
}, " ", wrappedComponent, " ");
}
};
}, 'withFallbackStyles');
exports.default = _default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_es","_interopRequireDefault","require","_element","_compose","_default","mapNodeToProps","createHigherOrderComponent","WrappedComponent","Component","constructor","props","nodeRef","node","state","fallbackStyles","undefined","grabStylesCompleted","bindRef","bind","componentDidMount","grabFallbackStyles","componentDidUpdate","newFallbackStyles","fastDeepEqual","setState","Object","values","every","Boolean","render","wrappedComponent","_react","createElement","ref","exports","default"],"sources":["@wordpress/components/src/higher-order/with-fallback-styles/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\ntype Props = {\n\tnode?: HTMLElement;\n\t[ key: string ]: any;\n};\n\ntype State = {\n\tfallbackStyles?: { [ key: string ]: any };\n\tgrabStylesCompleted: boolean;\n};\n\nexport default (\n\tmapNodeToProps: (\n\t\tnode: HTMLElement,\n\t\tprops: Props\n\t) => { [ key: string ]: any }\n) =>\n\tcreateHigherOrderComponent( ( WrappedComponent ) => {\n\t\treturn class extends Component< Props, State > {\n\t\t\tnodeRef?: HTMLElement;\n\n\t\t\tconstructor( props: Props ) {\n\t\t\t\tsuper( props );\n\t\t\t\tthis.nodeRef = this.props.node;\n\t\t\t\tthis.state = {\n\t\t\t\t\tfallbackStyles: undefined,\n\t\t\t\t\tgrabStylesCompleted: false,\n\t\t\t\t};\n\n\t\t\t\tthis.bindRef = this.bindRef.bind( this );\n\t\t\t}\n\n\t\t\tbindRef( node: HTMLDivElement ) {\n\t\t\t\tif ( ! node ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.nodeRef = node;\n\t\t\t}\n\n\t\t\tcomponentDidMount() {\n\t\t\t\tthis.grabFallbackStyles();\n\t\t\t}\n\n\t\t\tcomponentDidUpdate() {\n\t\t\t\tthis.grabFallbackStyles();\n\t\t\t}\n\n\t\t\tgrabFallbackStyles() {\n\t\t\t\tconst { grabStylesCompleted, fallbackStyles } = this.state;\n\t\t\t\tif ( this.nodeRef && ! grabStylesCompleted ) {\n\t\t\t\t\tconst newFallbackStyles = mapNodeToProps(\n\t\t\t\t\t\tthis.nodeRef,\n\t\t\t\t\t\tthis.props\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t! fastDeepEqual( newFallbackStyles, fallbackStyles )\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.setState( {\n\t\t\t\t\t\t\tfallbackStyles: newFallbackStyles,\n\t\t\t\t\t\t\tgrabStylesCompleted:\n\t\t\t\t\t\t\t\tObject.values( newFallbackStyles ).every(\n\t\t\t\t\t\t\t\t\tBoolean\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\tconst wrappedComponent = (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state.fallbackStyles }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t\treturn this.props.node ? (\n\t\t\t\t\twrappedComponent\n\t\t\t\t) : (\n\t\t\t\t\t<div ref={ this.bindRef }> { wrappedComponent } </div>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withFallbackStyles' );\n"],"mappings":";;;;;;;;AAGA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AATA;AACA;AACA;AAGA;AACA;AACA;AAFA,IAAAG,QAAA,GAiBCC,cAG6B,IAE7B,IAAAC,mCAA0B,EAAIC,gBAAgB,IAAM;EACnD,OAAO,cAAcC,kBAAS,CAAiB;IAG9CC,WAAWA,CAAEC,KAAY,EAAG;MAC3B,KAAK,CAAEA,KAAM,CAAC;MACd,IAAI,CAACC,OAAO,GAAG,IAAI,CAACD,KAAK,CAACE,IAAI;MAC9B,IAAI,CAACC,KAAK,GAAG;QACZC,cAAc,EAAEC,SAAS;QACzBC,mBAAmB,EAAE;MACtB,CAAC;MAED,IAAI,CAACC,OAAO,GAAG,IAAI,CAACA,OAAO,CAACC,IAAI,CAAE,IAAK,CAAC;IACzC;IAEAD,OAAOA,CAAEL,IAAoB,EAAG;MAC/B,IAAK,CAAEA,IAAI,EAAG;QACb;MACD;MACA,IAAI,CAACD,OAAO,GAAGC,IAAI;IACpB;IAEAO,iBAAiBA,CAAA,EAAG;MACnB,IAAI,CAACC,kBAAkB,CAAC,CAAC;IAC1B;IAEAC,kBAAkBA,CAAA,EAAG;MACpB,IAAI,CAACD,kBAAkB,CAAC,CAAC;IAC1B;IAEAA,kBAAkBA,CAAA,EAAG;MACpB,MAAM;QAAEJ,mBAAmB;QAAEF;MAAe,CAAC,GAAG,IAAI,CAACD,KAAK;MAC1D,IAAK,IAAI,CAACF,OAAO,IAAI,CAAEK,mBAAmB,EAAG;QAC5C,MAAMM,iBAAiB,GAAGjB,cAAc,CACvC,IAAI,CAACM,OAAO,EACZ,IAAI,CAACD,KACN,CAAC;QAED,IACC,CAAE,IAAAa,WAAa,EAAED,iBAAiB,EAAER,cAAe,CAAC,EACnD;UACD,IAAI,CAACU,QAAQ,CAAE;YACdV,cAAc,EAAEQ,iBAAiB;YACjCN,mBAAmB,EAClBS,MAAM,CAACC,MAAM,CAAEJ,iBAAkB,CAAC,CAACK,KAAK,CACvCC,OACD;UACF,CAAE,CAAC;QACJ;MACD;IACD;IAEAC,MAAMA,CAAA,EAAG;MACR,MAAMC,gBAAgB,GACrB,IAAAC,MAAA,CAAAC,aAAA,EAACzB,gBAAgB;QAAA,GACX,IAAI,CAACG,KAAK;QAAA,GACV,IAAI,CAACG,KAAK,CAACC;MAAc,CAC9B,CACD;MACD,OAAO,IAAI,CAACJ,KAAK,CAACE,IAAI,GACrBkB,gBAAgB,GAEhB,IAAAC,MAAA,CAAAC,aAAA;QAAKC,GAAG,EAAG,IAAI,CAAChB;MAAS,GAAC,GAAC,EAAEa,gBAAgB,EAAE,GAAM,CACrD;IACF;EACD,CAAC;AACF,CAAC,EAAE,oBAAqB,CAAC;AAAAI,OAAA,CAAAC,OAAA,GAAA/B,QAAA"}

View File

@@ -0,0 +1,136 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = withFilters;
var _react = require("react");
var _element = require("@wordpress/element");
var _hooks = require("@wordpress/hooks");
var _compose = require("@wordpress/compose");
/**
* WordPress dependencies
*/
const ANIMATION_FRAME_PERIOD = 16;
/**
* Creates a higher-order component which adds filtering capability to the
* wrapped component. Filters get applied when the original component is about
* to be mounted. When a filter is added or removed that matches the hook name,
* the wrapped component re-renders.
*
* @param hookName Hook name exposed to be used by filters.
*
* @return Higher-order component factory.
*
* ```jsx
* import { withFilters } from '@wordpress/components';
* import { addFilter } from '@wordpress/hooks';
*
* const MyComponent = ( { title } ) => <h1>{ title }</h1>;
*
* const ComponentToAppend = () => <div>Appended component</div>;
*
* function withComponentAppended( FilteredComponent ) {
* return ( props ) => (
* <>
* <FilteredComponent { ...props } />
* <ComponentToAppend />
* </>
* );
* }
*
* addFilter(
* 'MyHookName',
* 'my-plugin/with-component-appended',
* withComponentAppended
* );
*
* const MyComponentWithFilters = withFilters( 'MyHookName' )( MyComponent );
* ```
*/
function withFilters(hookName) {
return (0, _compose.createHigherOrderComponent)(OriginalComponent => {
const namespace = 'core/with-filters/' + hookName;
/**
* The component definition with current filters applied. Each instance
* reuse this shared reference as an optimization to avoid excessive
* calls to `applyFilters` when many instances exist.
*/
let FilteredComponent;
/**
* Initializes the FilteredComponent variable once, if not already
* assigned. Subsequent calls are effectively a noop.
*/
function ensureFilteredComponent() {
if (FilteredComponent === undefined) {
FilteredComponent = (0, _hooks.applyFilters)(hookName, OriginalComponent);
}
}
class FilteredComponentRenderer extends _element.Component {
constructor(props) {
super(props);
ensureFilteredComponent();
}
componentDidMount() {
FilteredComponentRenderer.instances.push(this);
// If there were previously no mounted instances for components
// filtered on this hook, add the hook handler.
if (FilteredComponentRenderer.instances.length === 1) {
(0, _hooks.addAction)('hookRemoved', namespace, onHooksUpdated);
(0, _hooks.addAction)('hookAdded', namespace, onHooksUpdated);
}
}
componentWillUnmount() {
FilteredComponentRenderer.instances = FilteredComponentRenderer.instances.filter(instance => instance !== this);
// If this was the last of the mounted components filtered on
// this hook, remove the hook handler.
if (FilteredComponentRenderer.instances.length === 0) {
(0, _hooks.removeAction)('hookRemoved', namespace);
(0, _hooks.removeAction)('hookAdded', namespace);
}
}
render() {
return (0, _react.createElement)(FilteredComponent, {
...this.props
});
}
}
FilteredComponentRenderer.instances = [];
/**
* Updates the FilteredComponent definition, forcing a render for each
* mounted instance. This occurs a maximum of once per animation frame.
*/
const throttledForceUpdate = (0, _compose.debounce)(() => {
// Recreate the filtered component, only after delay so that it's
// computed once, even if many filters added.
FilteredComponent = (0, _hooks.applyFilters)(hookName, OriginalComponent);
// Force each instance to render.
FilteredComponentRenderer.instances.forEach(instance => {
instance.forceUpdate();
});
}, ANIMATION_FRAME_PERIOD);
/**
* When a filter is added or removed for the matching hook name, each
* mounted instance should re-render with the new filters having been
* applied to the original component.
*
* @param updatedHookName Name of the hook that was updated.
*/
function onHooksUpdated(updatedHookName) {
if (updatedHookName === hookName) {
throttledForceUpdate();
}
}
return FilteredComponentRenderer;
}, 'withFilters');
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
/**
* WordPress dependencies
*/
var _default = (0, _compose.createHigherOrderComponent)(WrappedComponent => props => {
const [handleFocusOutside, setHandleFocusOutside] = (0, _element.useState)(undefined);
const bindFocusOutsideHandler = (0, _element.useCallback)(node => setHandleFocusOutside(() => node?.handleFocusOutside ? node.handleFocusOutside.bind(node) : undefined), []);
return (0, _react.createElement)("div", {
...(0, _compose.__experimentalUseFocusOutside)(handleFocusOutside)
}, (0, _react.createElement)(WrappedComponent, {
ref: bindFocusOutsideHandler,
...props
}));
}, 'withFocusOutside');
exports.default = _default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_element","require","_compose","_default","createHigherOrderComponent","WrappedComponent","props","handleFocusOutside","setHandleFocusOutside","useState","undefined","bindFocusOutsideHandler","useCallback","node","bind","_react","createElement","useFocusOutside","ref","exports","default"],"sources":["@wordpress/components/src/higher-order/with-focus-outside/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tcreateHigherOrderComponent,\n\t__experimentalUseFocusOutside as useFocusOutside,\n} from '@wordpress/compose';\n\nexport default createHigherOrderComponent(\n\t( WrappedComponent ) => ( props ) => {\n\t\tconst [ handleFocusOutside, setHandleFocusOutside ] = useState<\n\t\t\tundefined | ( ( event: React.FocusEvent ) => void )\n\t\t>( undefined );\n\n\t\tconst bindFocusOutsideHandler = useCallback<\n\t\t\t( node: React.FocusEvent ) => void\n\t\t>(\n\t\t\t( node: any ) =>\n\t\t\t\tsetHandleFocusOutside( () =>\n\t\t\t\t\tnode?.handleFocusOutside\n\t\t\t\t\t\t? node.handleFocusOutside.bind( node )\n\t\t\t\t\t\t: undefined\n\t\t\t\t),\n\t\t\t[]\n\t\t);\n\n\t\treturn (\n\t\t\t<div { ...useFocusOutside( handleFocusOutside ) }>\n\t\t\t\t<WrappedComponent\n\t\t\t\t\tref={ bindFocusOutsideHandler }\n\t\t\t\t\t{ ...props }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t},\n\t'withFocusOutside'\n);\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAJA;AACA;AACA;AAFA,IAAAE,QAAA,GASe,IAAAC,mCAA0B,EACtCC,gBAAgB,IAAQC,KAAK,IAAM;EACpC,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAG,IAAAC,iBAAQ,EAE3DC,SAAU,CAAC;EAEd,MAAMC,uBAAuB,GAAG,IAAAC,oBAAW,EAGxCC,IAAS,IACVL,qBAAqB,CAAE,MACtBK,IAAI,EAAEN,kBAAkB,GACrBM,IAAI,CAACN,kBAAkB,CAACO,IAAI,CAAED,IAAK,CAAC,GACpCH,SACJ,CAAC,EACF,EACD,CAAC;EAED,OACC,IAAAK,MAAA,CAAAC,aAAA;IAAA,GAAU,IAAAC,sCAAe,EAAEV,kBAAmB;EAAC,GAC9C,IAAAQ,MAAA,CAAAC,aAAA,EAACX,gBAAgB;IAChBa,GAAG,EAAGP,uBAAyB;IAAA,GAC1BL;EAAK,CACV,CACG,CAAC;AAER,CAAC,EACD,kBACD,CAAC;AAAAa,OAAA,CAAAC,OAAA,GAAAjB,QAAA"}

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
var _default = (0, _compose.createHigherOrderComponent)(WrappedComponent => props => {
const [handleFocusOutside, setHandleFocusOutside] = (0, _element.useState)();
const bindFocusOutsideHandler = (0, _element.useCallback)(node => setHandleFocusOutside(() => node?.handleFocusOutside ? node.handleFocusOutside.bind(node) : undefined), []);
return (0, _react.createElement)(_reactNative.View, {
...(0, _compose.__experimentalUseFocusOutside)(handleFocusOutside)
}, (0, _react.createElement)(WrappedComponent, {
ref: bindFocusOutsideHandler,
...props
}));
}, 'withFocusOutside');
exports.default = _default;
//# sourceMappingURL=index.native.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_reactNative","require","_element","_compose","_default","createHigherOrderComponent","WrappedComponent","props","handleFocusOutside","setHandleFocusOutside","useState","bindFocusOutsideHandler","useCallback","node","bind","undefined","_react","createElement","View","useFocusOutside","ref","exports","default"],"sources":["@wordpress/components/src/higher-order/with-focus-outside/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n/**\n * WordPress dependencies\n */\nimport { useCallback, useState } from '@wordpress/element';\nimport {\n\tcreateHigherOrderComponent,\n\t__experimentalUseFocusOutside as useFocusOutside,\n} from '@wordpress/compose';\n\nexport default createHigherOrderComponent(\n\t( WrappedComponent ) => ( props ) => {\n\t\tconst [ handleFocusOutside, setHandleFocusOutside ] = useState();\n\t\tconst bindFocusOutsideHandler = useCallback(\n\t\t\t( node ) =>\n\t\t\t\tsetHandleFocusOutside( () =>\n\t\t\t\t\tnode?.handleFocusOutside\n\t\t\t\t\t\t? node.handleFocusOutside.bind( node )\n\t\t\t\t\t\t: undefined\n\t\t\t\t),\n\t\t\t[]\n\t\t);\n\n\t\treturn (\n\t\t\t<View { ...useFocusOutside( handleFocusOutside ) }>\n\t\t\t\t<WrappedComponent\n\t\t\t\t\tref={ bindFocusOutsideHandler }\n\t\t\t\t\t{ ...props }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t);\n\t},\n\t'withFocusOutside'\n);\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AARA;AACA;AACA;AAEA;AACA;AACA;AAFA,IAAAG,QAAA,GASe,IAAAC,mCAA0B,EACtCC,gBAAgB,IAAQC,KAAK,IAAM;EACpC,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAG,IAAAC,iBAAQ,EAAC,CAAC;EAChE,MAAMC,uBAAuB,GAAG,IAAAC,oBAAW,EACxCC,IAAI,IACLJ,qBAAqB,CAAE,MACtBI,IAAI,EAAEL,kBAAkB,GACrBK,IAAI,CAACL,kBAAkB,CAACM,IAAI,CAAED,IAAK,CAAC,GACpCE,SACJ,CAAC,EACF,EACD,CAAC;EAED,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACjB,YAAA,CAAAkB,IAAI;IAAA,GAAM,IAAAC,sCAAe,EAAEX,kBAAmB;EAAC,GAC/C,IAAAQ,MAAA,CAAAC,aAAA,EAACX,gBAAgB;IAChBc,GAAG,EAAGT,uBAAyB;IAAA,GAC1BJ;EAAK,CACV,CACI,CAAC;AAET,CAAC,EACD,kBACD,CAAC;AAAAc,OAAA,CAAAC,OAAA,GAAAlB,QAAA"}

View File

@@ -0,0 +1,73 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Provider = void 0;
var _react = require("react");
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
/**
* WordPress dependencies
*/
/**
* Returns true if the given object is component-like. An object is component-
* like if it is an instance of wp.element.Component, or is a function.
*
* @param object Object to test.
*
* @return Whether object is component-like.
*/
function isComponentLike(object) {
return object instanceof _element.Component || typeof object === 'function';
}
/**
* Higher Order Component used to be used to wrap disposable elements like
* sidebars, modals, dropdowns. When mounting the wrapped component, we track a
* reference to the current active element so we know where to restore focus
* when the component is unmounted.
*
* @param options The component to be enhanced with
* focus return behavior, or an object
* describing the component and the
* focus return characteristics.
*
* @return Higher Order Component with the focus restauration behaviour.
*/
var _default = (0, _compose.createHigherOrderComponent)(
// @ts-expect-error TODO: Reconcile with intended `createHigherOrderComponent` types
options => {
const HoC = ({
onFocusReturn
} = {}) => WrappedComponent => {
const WithFocusReturn = props => {
const ref = (0, _compose.useFocusReturn)(onFocusReturn);
return (0, _react.createElement)("div", {
ref: ref
}, (0, _react.createElement)(WrappedComponent, {
...props
}));
};
return WithFocusReturn;
};
if (isComponentLike(options)) {
const WrappedComponent = options;
return HoC()(WrappedComponent);
}
return HoC(options);
}, 'withFocusReturn');
exports.default = _default;
const Provider = ({
children
}) => {
(0, _deprecated.default)('wp.components.FocusReturnProvider component', {
since: '5.7',
hint: 'This provider is not used anymore. You can just remove it from your codebase'
});
return children;
};
exports.Provider = Provider;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_element","require","_compose","_deprecated","_interopRequireDefault","isComponentLike","object","Component","_default","createHigherOrderComponent","options","HoC","onFocusReturn","WrappedComponent","WithFocusReturn","props","ref","useFocusReturn","_react","createElement","exports","default","Provider","children","deprecated","since","hint"],"sources":["@wordpress/components/src/higher-order/with-focus-return/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { createHigherOrderComponent, useFocusReturn } from '@wordpress/compose';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Returns true if the given object is component-like. An object is component-\n * like if it is an instance of wp.element.Component, or is a function.\n *\n * @param object Object to test.\n *\n * @return Whether object is component-like.\n */\nfunction isComponentLike( object: any ): object is React.ComponentType {\n\treturn object instanceof Component || typeof object === 'function';\n}\n\ntype Props = {\n\tonFocusReturn?: () => void;\n};\n\n/**\n * Higher Order Component used to be used to wrap disposable elements like\n * sidebars, modals, dropdowns. When mounting the wrapped component, we track a\n * reference to the current active element so we know where to restore focus\n * when the component is unmounted.\n *\n * @param options The component to be enhanced with\n * focus return behavior, or an object\n * describing the component and the\n * focus return characteristics.\n *\n * @return Higher Order Component with the focus restauration behaviour.\n */\nexport default createHigherOrderComponent(\n\t// @ts-expect-error TODO: Reconcile with intended `createHigherOrderComponent` types\n\t( options: React.ComponentType | Record< string, unknown > ) => {\n\t\tconst HoC =\n\t\t\t( { onFocusReturn }: Props = {} ) =>\n\t\t\t( WrappedComponent: React.ComponentType ) => {\n\t\t\t\tconst WithFocusReturn = (\n\t\t\t\t\tprops: Record< string, unknown >\n\t\t\t\t) => {\n\t\t\t\t\tconst ref = useFocusReturn( onFocusReturn );\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div ref={ ref }>\n\t\t\t\t\t\t\t<WrappedComponent { ...props } />\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t};\n\n\t\t\t\treturn WithFocusReturn;\n\t\t\t};\n\n\t\tif ( isComponentLike( options ) ) {\n\t\t\tconst WrappedComponent = options;\n\t\t\treturn HoC()( WrappedComponent );\n\t\t}\n\n\t\treturn HoC( options );\n\t},\n\t'withFocusReturn'\n);\n\nexport const Provider = ( { children }: { children: React.ReactNode } ) => {\n\tdeprecated( 'wp.components.FocusReturnProvider component', {\n\t\tsince: '5.7',\n\t\thint: 'This provider is not used anymore. You can just remove it from your codebase',\n\t} );\n\n\treturn children;\n};\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASI,eAAeA,CAAEC,MAAW,EAAkC;EACtE,OAAOA,MAAM,YAAYC,kBAAS,IAAI,OAAOD,MAAM,KAAK,UAAU;AACnE;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAZA,IAAAE,QAAA,GAae,IAAAC,mCAA0B;AACxC;AACEC,OAAwD,IAAM;EAC/D,MAAMC,GAAG,GACRA,CAAE;IAAEC;EAAqB,CAAC,GAAG,CAAC,CAAC,KAC7BC,gBAAqC,IAAM;IAC5C,MAAMC,eAAe,GACpBC,KAAgC,IAC5B;MACJ,MAAMC,GAAG,GAAG,IAAAC,uBAAc,EAAEL,aAAc,CAAC;MAC3C,OACC,IAAAM,MAAA,CAAAC,aAAA;QAAKH,GAAG,EAAGA;MAAK,GACf,IAAAE,MAAA,CAAAC,aAAA,EAACN,gBAAgB;QAAA,GAAME;MAAK,CAAI,CAC5B,CAAC;IAER,CAAC;IAED,OAAOD,eAAe;EACvB,CAAC;EAEF,IAAKT,eAAe,CAAEK,OAAQ,CAAC,EAAG;IACjC,MAAMG,gBAAgB,GAAGH,OAAO;IAChC,OAAOC,GAAG,CAAC,CAAC,CAAEE,gBAAiB,CAAC;EACjC;EAEA,OAAOF,GAAG,CAAED,OAAQ,CAAC;AACtB,CAAC,EACD,iBACD,CAAC;AAAAU,OAAA,CAAAC,OAAA,GAAAb,QAAA;AAEM,MAAMc,QAAQ,GAAGA,CAAE;EAAEC;AAAwC,CAAC,KAAM;EAC1E,IAAAC,mBAAU,EAAE,6CAA6C,EAAE;IAC1DC,KAAK,EAAE,KAAK;IACZC,IAAI,EAAE;EACP,CAAE,CAAC;EAEH,OAAOH,QAAQ;AAChB,CAAC;AAACH,OAAA,CAAAE,QAAA,GAAAA,QAAA"}

View File

@@ -0,0 +1,109 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _uuid = require("uuid");
var _element = require("@wordpress/element");
var _compose = require("@wordpress/compose");
var _list = _interopRequireDefault(require("../../notice/list"));
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Override the default edit UI to include notices if supported.
*
* Wrapping the original component with `withNotices` encapsulates the component
* with the additional props `noticeOperations` and `noticeUI`.
*
* ```jsx
* import { withNotices, Button } from '@wordpress/components';
*
* const MyComponentWithNotices = withNotices(
* ( { noticeOperations, noticeUI } ) => {
* const addError = () =>
* noticeOperations.createErrorNotice( 'Error message' );
* return (
* <div>
* { noticeUI }
* <Button variant="secondary" onClick={ addError }>
* Add error
* </Button>
* </div>
* );
* }
* );
* ```
*
* @param OriginalComponent Original component.
*
* @return Wrapped component.
*/
var _default = (0, _compose.createHigherOrderComponent)(OriginalComponent => {
function Component(props, ref) {
const [noticeList, setNoticeList] = (0, _element.useState)([]);
const noticeOperations = (0, _element.useMemo)(() => {
const createNotice = notice => {
const noticeToAdd = notice.id ? notice : {
...notice,
id: (0, _uuid.v4)()
};
setNoticeList(current => [...current, noticeToAdd]);
};
return {
createNotice,
createErrorNotice: msg => {
// @ts-expect-error TODO: Missing `id`, potentially a bug
createNotice({
status: 'error',
content: msg
});
},
removeNotice: id => {
setNoticeList(current => current.filter(notice => notice.id !== id));
},
removeAllNotices: () => {
setNoticeList([]);
}
};
}, []);
const propsOut = {
...props,
noticeList,
noticeOperations,
noticeUI: noticeList.length > 0 && (0, _react.createElement)(_list.default, {
className: "components-with-notices-ui",
notices: noticeList,
onRemove: noticeOperations.removeNotice
})
};
return isForwardRef ? (0, _react.createElement)(OriginalComponent, {
...propsOut,
ref: ref
}) : (0, _react.createElement)(OriginalComponent, {
...propsOut
});
}
let isForwardRef;
// @ts-expect-error - `render` will only be present when OriginalComponent was wrapped with forwardRef().
const {
render
} = OriginalComponent;
// Returns a forwardRef if OriginalComponent appears to be a forwardRef.
if (typeof render === 'function') {
isForwardRef = true;
return (0, _element.forwardRef)(Component);
}
return Component;
}, 'withNotices');
exports.default = _default;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":[],"sources":["@wordpress/components/src/higher-order/with-notices/types.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { NoticeListProps } from '../../notice/types';\n\nexport type WithNoticeProps = {\n\tnoticeList: NoticeListProps[ 'notices' ];\n\tnoticeOperations: {\n\t\t/**\n\t\t * Function passed down as a prop that adds a new notice.\n\t\t *\n\t\t * @param notice Notice to add.\n\t\t */\n\t\tcreateNotice: (\n\t\t\tnotice: NoticeListProps[ 'notices' ][ number ]\n\t\t) => void;\n\t\t/**\n\t\t * Function passed as a prop that adds a new error notice.\n\t\t *\n\t\t * @param msg Error message of the notice.\n\t\t */\n\t\tcreateErrorNotice: ( msg: string ) => void;\n\t\t/**\n\t\t * Removes a notice by id.\n\t\t *\n\t\t * @param id Id of the notice to remove.\n\t\t */\n\t\tremoveNotice: ( id: string ) => void;\n\t\t/**\n\t\t * Removes all notices\n\t\t */\n\t\tremoveAllNotices: () => void;\n\t};\n\tnoticeUI: false | JSX.Element;\n};\n"],"mappings":""}

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
var _compose = require("@wordpress/compose");
var _a11y = require("@wordpress/a11y");
/**
* WordPress dependencies
*/
/** @typedef {import('react').ComponentType} ComponentType */
/**
* A Higher Order Component used to be provide speak and debounced speak
* functions.
*
* @see https://developer.wordpress.org/block-editor/packages/packages-a11y/#speak
*
* @param {ComponentType} Component The component to be wrapped.
*
* @return {ComponentType} The wrapped component.
*/
var _default = (0, _compose.createHigherOrderComponent)(Component => props => (0, _react.createElement)(Component, {
...props,
speak: _a11y.speak,
debouncedSpeak: (0, _compose.useDebounce)(_a11y.speak, 500)
}), 'withSpokenMessages');
exports.default = _default;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["_compose","require","_a11y","_default","createHigherOrderComponent","Component","props","_react","createElement","speak","debouncedSpeak","useDebounce","exports","default"],"sources":["@wordpress/components/src/higher-order/with-spoken-messages/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, useDebounce } from '@wordpress/compose';\nimport { speak } from '@wordpress/a11y';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * A Higher Order Component used to be provide speak and debounced speak\n * functions.\n *\n * @see https://developer.wordpress.org/block-editor/packages/packages-a11y/#speak\n *\n * @param {ComponentType} Component The component to be wrapped.\n *\n * @return {ComponentType} The wrapped component.\n */\nexport default createHigherOrderComponent(\n\t( Component ) => ( props ) => (\n\t\t<Component\n\t\t\t{ ...props }\n\t\t\tspeak={ speak }\n\t\t\tdebouncedSpeak={ useDebounce( speak, 500 ) }\n\t\t/>\n\t),\n\t'withSpokenMessages'\n);\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAJA;AACA;AACA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AATA,IAAAE,QAAA,GAUe,IAAAC,mCAA0B,EACtCC,SAAS,IAAQC,KAAK,IACvB,IAAAC,MAAA,CAAAC,aAAA,EAACH,SAAS;EAAA,GACJC,KAAK;EACVG,KAAK,EAAGA,WAAO;EACfC,cAAc,EAAG,IAAAC,oBAAW,EAAEF,WAAK,EAAE,GAAI;AAAG,CAC5C,CACD,EACD,oBACD,CAAC;AAAAG,OAAA,CAAAC,OAAA,GAAAV,QAAA"}