芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/www/wp-content/plugins/blocksy-companion/static/js/helpers/reach/dialog.js
import Component from '@reach/component-component' import Portal from './portal' import { checkStyles, wrapEvent } from '@reach/utils' import createFocusTrap from 'focus-trap' import { createElement, useEffect, useState, Fragment } from '@wordpress/element' let createAriaHider = dialogNode => { let originalValues = [] let rootNodes = [] Array.prototype.forEach.call( document.querySelectorAll('body > *'), node => { if (node === dialogNode.parentNode) { return } let attr = node.getAttribute('aria-hidden') let alreadyHidden = attr !== null && attr !== 'false' if (alreadyHidden) { return } originalValues.push(attr) rootNodes.push(node) node.setAttribute('aria-hidden', 'true') } ) return () => { rootNodes.forEach((node, index) => { let originalValue = originalValues[index] if (originalValue === null) { node.removeAttribute('aria-hidden') } else { node.setAttribute('aria-hidden', originalValue) } }) } } let k = () => {} let checkDialogStyles = () => checkStyles('dialog') let portalDidMount = (refs, initialFocusRef) => { refs.disposeAriaHider = createAriaHider(refs.overlayNode) refs.trap = createFocusTrap(refs.overlayNode, { initialFocus: initialFocusRef ? () => initialFocusRef.current : undefined, fallbackFocus: refs.contentNode, escapeDeactivates: false, clickOutsideDeactivates: false }) // refs.trap.activate() } let contentWillUnmount = ({ refs }) => { refs.trap.deactivate() refs.disposeAriaHider() } let FocusContext = React.createContext() let DialogOverlay = React.forwardRef( ( { container, isOpen = true, onDismiss = k, initialFocusRef, onClick, onKeyDown, ...props }, forwardRef ) => (
{isOpen ? (
{ portalDidMount(refs, initialFocusRef) }} willUnmount={contentWillUnmount}> {({ refs }) => (
(refs.contentNode = node)}>
{ event.stopPropagation() onDismiss() })} onKeyDown={wrapEvent(onKeyDown, event => { if (event.key === 'Escape') { event.stopPropagation() onDismiss() } })} ref={node => { refs.overlayNode = node forwardRef && forwardRef(node) }} {...props} /> )} ) : null} ) ) DialogOverlay.propTypes = { initialFocusRef: () => {} } let stopPropagation = event => event.stopPropagation() let DialogContent = React.forwardRef( ({ onClick, onKeyDown, ...props }, forwardRef) => (
{contentRef => (
{ contentRef(node) forwardRef && forwardRef(node) }} {...props} /> )} ) ) let Dialog = ({ container, isOpen, onDismiss = k, ...props }) => (
) export { DialogOverlay, DialogContent, Dialog }