@wordpress/components
Version:
UI components for WordPress.
1 lines • 5.08 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/resizable-box/index.tsx"],"sourcesContent":["import { forwardRef } from '@wordpress/element';\nimport clsx from 'clsx';\nimport { Resizable } from 're-resizable';\nimport type { ResizableProps } from 're-resizable';\nimport type { ForwardedRef } from 'react';\nimport ResizeTooltip from './resize-tooltip';\n\nconst HANDLE_CLASS_NAME = 'components-resizable-box__handle';\nconst SIDE_HANDLE_CLASS_NAME = 'components-resizable-box__side-handle';\nconst CORNER_HANDLE_CLASS_NAME = 'components-resizable-box__corner-handle';\n\nconst HANDLE_CLASSES = {\n\ttop: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tSIDE_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-top'\n\t),\n\tright: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tSIDE_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-right'\n\t),\n\tbottom: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tSIDE_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-bottom'\n\t),\n\tleft: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tSIDE_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-left'\n\t),\n\ttopLeft: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tCORNER_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-top',\n\t\t'components-resizable-box__handle-left'\n\t),\n\ttopRight: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tCORNER_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-top',\n\t\t'components-resizable-box__handle-right'\n\t),\n\tbottomRight: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tCORNER_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-bottom',\n\t\t'components-resizable-box__handle-right'\n\t),\n\tbottomLeft: clsx(\n\t\tHANDLE_CLASS_NAME,\n\t\tCORNER_HANDLE_CLASS_NAME,\n\t\t'components-resizable-box__handle-bottom',\n\t\t'components-resizable-box__handle-left'\n\t),\n};\n\n// Removes the inline styles in the drag handles, so the stylesheet controls\n// their size, position, and stacking.\nconst HANDLE_STYLES_OVERRIDES = {\n\twidth: undefined,\n\theight: undefined,\n\ttop: undefined,\n\tright: undefined,\n\tbottom: undefined,\n\tleft: undefined,\n\tzIndex: undefined,\n};\nconst HANDLE_STYLES = {\n\ttop: HANDLE_STYLES_OVERRIDES,\n\tright: HANDLE_STYLES_OVERRIDES,\n\tbottom: HANDLE_STYLES_OVERRIDES,\n\tleft: HANDLE_STYLES_OVERRIDES,\n\ttopLeft: HANDLE_STYLES_OVERRIDES,\n\ttopRight: HANDLE_STYLES_OVERRIDES,\n\tbottomRight: HANDLE_STYLES_OVERRIDES,\n\tbottomLeft: HANDLE_STYLES_OVERRIDES,\n};\n\ntype ResizableBoxProps = ResizableProps & {\n\tshowHandle?: boolean;\n\t__experimentalShowTooltip?: boolean;\n\t__experimentalTooltipProps?: Parameters< typeof ResizeTooltip >[ 0 ];\n};\n\nfunction UnforwardedResizableBox(\n\t{\n\t\tclassName,\n\t\tchildren,\n\t\tshowHandle = true,\n\t\t__experimentalShowTooltip: showTooltip = false,\n\t\t__experimentalTooltipProps: tooltipProps = {},\n\t\t...props\n\t}: ResizableBoxProps,\n\tref: ForwardedRef< Resizable >\n) {\n\treturn (\n\t\t<Resizable\n\t\t\tclassName={ clsx(\n\t\t\t\t'components-resizable-box__container',\n\t\t\t\tshowHandle && 'has-show-handle',\n\t\t\t\tclassName\n\t\t\t) }\n\t\t\t// Add a focusable element within the drag handle. Unfortunately,\n\t\t\t// `re-resizable` does not make them properly focusable by default,\n\t\t\t// causing focus to move the block wrapper which triggers block\n\t\t\t// drag.\n\t\t\thandleComponent={ Object.fromEntries(\n\t\t\t\tObject.keys( HANDLE_CLASSES ).map( ( key ) => [\n\t\t\t\t\tkey,\n\t\t\t\t\t<div key={ key } tabIndex={ -1 } />,\n\t\t\t\t] )\n\t\t\t) }\n\t\t\thandleClasses={ HANDLE_CLASSES }\n\t\t\thandleStyles={ HANDLE_STYLES }\n\t\t\tref={ ref }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children }\n\t\t\t{ showTooltip && <ResizeTooltip { ...tooltipProps } /> }\n\t\t</Resizable>\n\t);\n}\n\n/**\n * `ResizableBox` wraps content in a container with draggable handles, letting\n * users interactively resize it along one or more edges or corners.\n */\nexport const ResizableBox = forwardRef( UnforwardedResizableBox );\nResizableBox.displayName = 'ResizableBox';\n\nexport default ResizableBox;\n"],"mappings":";;;;;;AAOA,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,2BAA2B;AAEjC,MAAM,iBAAiB;CACtB,KAAK,KACJ,mBACA,wBACA,sCACD;CACA,OAAO,KACN,mBACA,wBACA,wCACD;CACA,QAAQ,KACP,mBACA,wBACA,yCACD;CACA,MAAM,KACL,mBACA,wBACA,uCACD;CACA,SAAS,KACR,mBACA,0BACA,wCACA,uCACD;CACA,UAAU,KACT,mBACA,0BACA,wCACA,wCACD;CACA,aAAa,KACZ,mBACA,0BACA,2CACA,wCACD;CACA,YAAY,KACX,mBACA,0BACA,2CACA,uCACD;AACD;AAIA,MAAM,0BAA0B;CAC/B,OAAO,KAAA;CACP,QAAQ,KAAA;CACR,KAAK,KAAA;CACL,OAAO,KAAA;CACP,QAAQ,KAAA;CACR,MAAM,KAAA;CACN,QAAQ,KAAA;AACT;AACA,MAAM,gBAAgB;CACrB,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,UAAU;CACV,aAAa;CACb,YAAY;AACb;AAQA,SAAS,wBACR,EACC,WACA,UACA,aAAa,MACb,2BAA2B,cAAc,OACzC,4BAA4B,eAAe,CAAC,GAC5C,GAAG,SAEJ,KACC;CACD,OACC,qBAAC,WAAD;EACC,WAAY,KACX,uCACA,cAAc,mBACd,SACD;EAKA,iBAAkB,OAAO,YACxB,OAAO,KAAM,cAAe,CAAC,CAAC,KAAO,QAAS,CAC7C,KACA,oBAAC,OAAD,EAAiB,UAAW,GAAM,GAAvB,GAAuB,CACnC,CAAE,CACH;EACA,eAAgB;EAChB,cAAe;EACT;EACN,GAAK;EAnBN,UAAA,CAqBG,UACA,eAAe,oBAAC,eAAD,EAAe,GAAK,aAAgB,CAAA,CAC3C;;AAEb;;;;;AAMA,MAAa,eAAe,WAAY,uBAAwB;AAChE,aAAa,cAAc"}