@wordpress/block-editor 11.3.0 → 11.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/block-actions/index.js +7 -2
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/iframe/index.js +5 -3
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +2 -1
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/menu.js +4 -1
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +3 -1
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +16 -4
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/hooks/position.js +5 -2
- package/build/hooks/position.js.map +1 -1
- package/build/store/private-selectors.js +14 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/selectors.js +0 -14
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-actions/index.js +7 -2
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/iframe/index.js +6 -4
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +2 -1
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +4 -1
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +2 -1
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +16 -4
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/hooks/position.js +5 -2
- package/build-module/hooks/position.js.map +1 -1
- package/build-module/store/private-selectors.js +12 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/selectors.js +0 -12
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +30 -30
- package/src/components/block-actions/index.js +9 -0
- package/src/components/iframe/index.js +8 -2
- package/src/components/inserter/block-patterns-tab.js +2 -1
- package/src/components/inserter/menu.js +8 -1
- package/src/components/off-canvas-editor/block-contents.js +2 -1
- package/src/components/off-canvas-editor/index.js +18 -3
- package/src/hooks/position.js +4 -0
- package/src/store/private-selectors.js +10 -0
- package/src/store/selectors.js +0 -10
- package/src/store/test/private-selectors.js +29 -1
- package/src/store/test/selectors.js +0 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/position.js"],"names":["POSITION_SUPPORT_KEY","OPTION_CLASSNAME","DEFAULT_OPTION","key","value","name","className","STICKY_OPTION","__experimentalHint","FIXED_OPTION","POSITION_SIDES","VALID_POSITION_TYPES","getPositionCSS","selector","style","output","type","positionType","position","includes","forEach","side","undefined","hasStickyPositionSupport","blockType","support","sticky","hasFixedPositionSupport","fixed","hasPositionSupport","hasPositionValue","props","attributes","hasStickyOrFixedPositionValue","resetPosition","setAttributes","top","right","bottom","left","useIsPositionDisabled","blockName","allowFixed","allowSticky","isDisabled","PositionPanel","clientId","hasParents","select","getBlockParents","blockEditorStore","parents","length","options","availableOptions","push","onChangeType","next","placementValue","newStyle","selectedOption","find","option","Platform","web","selectedItem","native","withInspectorControls","BlockEdit","positionSupport","showPositionControls","withPositionStyles","BlockListBlock","hasPositionBlockSupport","allowPositionStyles","id","element","BlockList","__unstableElementContext","positionSelector","css"],"mappings":";;;;;;;;;;;;;;;;;;AAaA;;;;AAVA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;AAOA,MAAMA,oBAAoB,GAAG,UAA7B;AAEA,MAAMC,gBAAgB,GACrB,gEADD;AAGA,MAAMC,cAAc,GAAG;AACtBC,EAAAA,GAAG,EAAE,SADiB;AAEtBC,EAAAA,KAAK,EAAE,EAFe;AAGtBC,EAAAA,IAAI,EAAE,cAAI,SAAJ,CAHgB;AAItBC,EAAAA,SA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M,IAAAA,GAAG,GACFpE,cAAc,CAAE;AACfC,MAAAA,QAAQ,EAAEkE,gBADK;AAEfjE,MAAAA,KAAK,EAAEkB,UAAF,aAAEA,UAAF,uBAAEA,UAAU,CAAElB;AAFJ,KAAF,CAAd,IAGO,EAJR;AAKA,GAvBiC,CAyBlC;;;AACA,QAAMR,SAAS,GAAG,yBAAYyB,KAAZ,aAAYA,KAAZ,uBAAYA,KAAK,CAAEzB,SAAnB,EAA8B;AAC/C,KAAG,gBAAgBqE,EAAI,EAAvB,GAA4BD,mBAAmB,IAAI,CAAC,CAAEM,GADP,CACY;;AADZ,GAA9B,CAAlB;AAIA,SACC,qDACGN,mBAAmB,IACpBE,OADC,IAED,CAAC,CAAEI,GAFF,IAGD,2BAAc,2CAASA,GAAT,CAAd,EAAsCJ,OAAtC,CAJF,EAKC,4BAAC,cAAD,6BAAqB7C,KAArB;AAA6B,IAAA,SAAS,EAAGzB;AAAzC,KALD,CADD;AASA,CAxCgC,CAA3B;;AA2CP,sBACC,uBADD,EAEC,2CAFD,EAGCiE,kBAHD;AAKA,sBACC,kBADD,EAEC,8CAFD,EAGCJ,qBAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { BaseControl, CustomSelectControl } from '@wordpress/components';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tuseContext,\n\tuseMemo,\n\tcreatePortal,\n\tPlatform,\n} from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport useSetting from '../components/use-setting';\nimport InspectorControls from '../components/inspector-controls';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nconst POSITION_SUPPORT_KEY = 'position';\n\nconst OPTION_CLASSNAME =\n\t'block-editor-hooks__position-selection__select-control__option';\n\nconst DEFAULT_OPTION = {\n\tkey: 'default',\n\tvalue: '',\n\tname: __( 'Default' ),\n\tclassName: OPTION_CLASSNAME,\n};\n\nconst STICKY_OPTION = {\n\tkey: 'sticky',\n\tvalue: 'sticky',\n\tname: __( 'Sticky' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will stick to the top of the window instead of scrolling.'\n\t),\n};\n\nconst FIXED_OPTION = {\n\tkey: 'fixed',\n\tvalue: 'fixed',\n\tname: __( 'Fixed' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will not move when the page is scrolled.'\n\t),\n};\n\nconst POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nconst VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];\n\n/**\n * Get calculated position CSS.\n *\n * @param {Object} props Component props.\n * @param {string} props.selector Selector to use.\n * @param {Object} props.style Style object.\n * @return {string} The generated CSS rules.\n */\nexport function getPositionCSS( { selector, style } ) {\n\tlet output = '';\n\n\tconst { type: positionType } = style?.position || {};\n\n\tif ( ! VALID_POSITION_TYPES.includes( positionType ) ) {\n\t\treturn output;\n\t}\n\n\toutput += `${ selector } {`;\n\toutput += `position: ${ positionType };`;\n\n\tPOSITION_SIDES.forEach( ( side ) => {\n\t\tif ( style?.position?.[ side ] !== undefined ) {\n\t\t\toutput += `${ side }: ${ style.position[ side ] };`;\n\t\t}\n\t} );\n\n\tif ( positionType === 'sticky' || positionType === 'fixed' ) {\n\t\t// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.\n\t\toutput += `z-index: 10`;\n\t}\n\toutput += `}`;\n\n\treturn output;\n}\n\n/**\n * Determines if there is sticky position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasStickyPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.sticky );\n}\n\n/**\n * Determines if there is fixed position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasFixedPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.fixed );\n}\n\n/**\n * Determines if there is position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! support;\n}\n\n/**\n * Checks if there is a current value in the position block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a position value set.\n */\nexport function hasPositionValue( props ) {\n\treturn props.attributes.style?.position?.type !== undefined;\n}\n\n/**\n * Checks if the block is currently set to a sticky or fixed position.\n * This check is helpful for determining how to position block toolbars or other elements.\n *\n * @param {Object} attributes Block attributes.\n * @return {boolean} Whether or not the block is set to a sticky or fixed position.\n */\nexport function hasStickyOrFixedPositionValue( attributes ) {\n\tconst positionType = attributes.style?.position?.type;\n\treturn positionType === 'sticky' || positionType === 'fixed';\n}\n\n/**\n * Resets the position block support attributes. This can be used when disabling\n * the position support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPosition( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: undefined,\n\t\t\t\ttop: undefined,\n\t\t\t\tright: undefined,\n\t\t\t\tbottom: undefined,\n\t\t\t\tleft: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if position settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPositionDisabled( { name: blockName } = {} ) {\n\tconst allowFixed = useSetting( 'position.fixed' );\n\tconst allowSticky = useSetting( 'position.sticky' );\n\tconst isDisabled = ! allowFixed && ! allowSticky;\n\n\treturn ! hasPositionSupport( blockName ) || isDisabled;\n}\n\n/*\n * Position controls rendered in an inspector control panel.\n *\n * @param {Object} props\n *\n * @return {WPElement} Position panel.\n */\nexport function PositionPanel( props ) {\n\tconst {\n\t\tattributes: { style = {} },\n\t\tclientId,\n\t\tname: blockName,\n\t\tsetAttributes,\n\t} = props;\n\n\tconst allowFixed = hasFixedPositionSupport( blockName );\n\tconst allowSticky = hasStickyPositionSupport( blockName );\n\tconst value = style?.position?.type;\n\n\tconst { hasParents } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParents } = select( blockEditorStore );\n\t\t\tconst parents = getBlockParents( clientId );\n\t\t\treturn {\n\t\t\t\thasParents: parents.length,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst options = useMemo( () => {\n\t\tconst availableOptions = [ DEFAULT_OPTION ];\n\t\t// Only display sticky option if the block has no parents (is at the root of the document),\n\t\t// or if the block already has a sticky position value set.\n\t\tif (\n\t\t\t( allowSticky && ! hasParents ) ||\n\t\t\tvalue === STICKY_OPTION.value\n\t\t) {\n\t\t\tavailableOptions.push( STICKY_OPTION );\n\t\t}\n\t\tif ( allowFixed || value === FIXED_OPTION.value ) {\n\t\t\tavailableOptions.push( FIXED_OPTION );\n\t\t}\n\t\treturn availableOptions;\n\t}, [ allowFixed, allowSticky, hasParents, value ] );\n\n\tconst onChangeType = ( next ) => {\n\t\t// For now, use a hard-coded `0px` value for the position.\n\t\t// `0px` is preferred over `0` as it can be used in `calc()` functions.\n\t\t// In the future, it could be useful to allow for an offset value.\n\t\tconst placementValue = '0px';\n\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: next,\n\t\t\t\ttop:\n\t\t\t\t\tnext === 'sticky' || next === 'fixed'\n\t\t\t\t\t\t? placementValue\n\t\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tconst selectedOption = value\n\t\t? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION\n\t\t: DEFAULT_OPTION;\n\n\t// Only display position controls if there is at least one option to choose from.\n\treturn Platform.select( {\n\t\tweb:\n\t\t\toptions.length > 1 ? (\n\t\t\t\t<InspectorControls group=\"position\">\n\t\t\t\t\t<BaseControl className=\"block-editor-hooks__position-selection\">\n\t\t\t\t\t\t<CustomSelectControl\n\t\t\t\t\t\t\t__nextUnconstrainedWidth\n\t\t\t\t\t\t\t__next36pxDefaultSize\n\t\t\t\t\t\t\tclassName=\"block-editor-hooks__position-selection__select-control\"\n\t\t\t\t\t\t\tlabel={ __( 'Position' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tdescribedBy={ sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Currently selected position.\n\t\t\t\t\t\t\t\t__( 'Currently selected position: %s' ),\n\t\t\t\t\t\t\t\tselectedOption.name\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\t\tvalue={ selectedOption }\n\t\t\t\t\t\t\t__experimentalShowSelectedHint\n\t\t\t\t\t\t\tonChange={ ( { selectedItem } ) => {\n\t\t\t\t\t\t\t\tonChangeType( selectedItem.value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t</InspectorControls>\n\t\t\t) : null,\n\t\tnative: null,\n\t} );\n}\n\n/**\n * Override the default edit UI to include position controls.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withInspectorControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name: blockName } = props;\n\t\tconst positionSupport = hasBlockSupport(\n\t\t\tblockName,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst showPositionControls =\n\t\t\tpositionSupport && ! useIsPositionDisabled( props );\n\n\t\treturn [\n\t\t\tshowPositionControls && (\n\t\t\t\t<PositionPanel key=\"position\" { ...props } />\n\t\t\t),\n\t\t\t<BlockEdit key=\"edit\" { ...props } />,\n\t\t];\n\t},\n\t'withInspectorControls'\n);\n\n/**\n * Override the default block element to add the position styles.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withPositionStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst hasPositionBlockSupport = hasBlockSupport(\n\t\t\tname,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst allowPositionStyles =\n\t\t\thasPositionBlockSupport && ! useIsPositionDisabled( props );\n\n\t\tconst id = useInstanceId( BlockListBlock );\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\t// Higher specificity to override defaults in editor UI.\n\t\tconst positionSelector = `.wp-container-${ id }.wp-container-${ id }`;\n\n\t\t// Get CSS string for the current position values.\n\t\tlet css;\n\t\tif ( allowPositionStyles ) {\n\t\t\tcss =\n\t\t\t\tgetPositionCSS( {\n\t\t\t\t\tselector: positionSelector,\n\t\t\t\t\tstyle: attributes?.style,\n\t\t\t\t} ) || '';\n\t\t}\n\n\t\t// Attach a `wp-container-` id-based class name.\n\t\tconst className = classnames( props?.className, {\n\t\t\t[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t} );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ allowPositionStyles &&\n\t\t\t\t\telement &&\n\t\t\t\t\t!! css &&\n\t\t\t\t\tcreatePortal( <style>{ css }</style>, element ) }\n\t\t\t\t<BlockListBlock { ...props } className={ className } />\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/position/with-position-styles',\n\twithPositionStyles\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/position/with-inspector-controls',\n\twithInspectorControls\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/position.js"],"names":["POSITION_SUPPORT_KEY","OPTION_CLASSNAME","DEFAULT_OPTION","key","value","name","className","STICKY_OPTION","__experimentalHint","FIXED_OPTION","POSITION_SIDES","VALID_POSITION_TYPES","getPositionCSS","selector","style","output","type","positionType","position","includes","forEach","side","undefined","hasStickyPositionSupport","blockType","support","sticky","hasFixedPositionSupport","fixed","hasPositionSupport","hasPositionValue","props","attributes","hasStickyOrFixedPositionValue","resetPosition","setAttributes","top","right","bottom","left","useIsPositionDisabled","blockName","allowFixed","allowSticky","isDisabled","PositionPanel","clientId","hasParents","select","getBlockParents","blockEditorStore","parents","length","options","availableOptions","push","onChangeType","next","placementValue","newStyle","selectedOption","find","option","Platform","web","selectedItem","native","withInspectorControls","BlockEdit","positionSupport","showPositionControls","withPositionStyles","BlockListBlock","hasPositionBlockSupport","allowPositionStyles","id","element","BlockList","__unstableElementContext","positionSelector","css"],"mappings":";;;;;;;;;;;;;;;;;;AAaA;;;;AAVA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAOA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AA5BA;AACA;AACA;;AAGA;AACA;AACA;;AAcA;AACA;AACA;AAOA,MAAMA,oBAAoB,GAAG,UAA7B;AAEA,MAAMC,gBAAgB,GACrB,gEADD;AAGA,MAAMC,cAAc,GAAG;AACtBC,EAAAA,GAAG,EAAE,SADiB;AAEtBC,EAAAA,KAAK,EAAE,EAFe;AAGtBC,EAAAA,IAAI,EAAE,cAAI,SAAJ,CAHgB;AAItBC,EAAAA,SAAS,EAAEL;AAJW,CAAvB;AAOA,MAAMM,aAAa,GAAG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MAAAA,QAAQ,EAAEkE,gBADK;AAEfjE,MAAAA,KAAK,EAAEkB,UAAF,aAAEA,UAAF,uBAAEA,UAAU,CAAElB;AAFJ,KAAF,CAAd,IAGO,EAJR;AAKA,GAvBiC,CAyBlC;;;AACA,QAAMR,SAAS,GAAG,yBAAYyB,KAAZ,aAAYA,KAAZ,uBAAYA,KAAK,CAAEzB,SAAnB,EAA8B;AAC/C,KAAG,gBAAgBqE,EAAI,EAAvB,GAA4BD,mBAAmB,IAAI,CAAC,CAAEM,GADP;AACY;AAC3D,KAAG,eAAehD,UAAhB,aAAgBA,UAAhB,6CAAgBA,UAAU,CAAElB,KAA5B,gFAAgB,mBAAmBI,QAAnC,0DAAgB,sBAA6BF,IAAM,EAArD,GACC0D,mBAAmB,IACnB,CAAC,CAAEM,GADH,IAEA,CAAC,EAAEhD,UAAF,aAAEA,UAAF,qCAAEA,UAAU,CAAElB,KAAd,wEAAE,mBAAmBI,QAArB,kDAAE,sBAA6BF,IAA/B;AAL6C,GAA9B,CAAlB;AAQA,SACC,qDACG0D,mBAAmB,IACpBE,OADC,IAED,CAAC,CAAEI,GAFF,IAGD,2BAAc,2CAASA,GAAT,CAAd,EAAsCJ,OAAtC,CAJF,EAKC,4BAAC,cAAD,6BAAqB7C,KAArB;AAA6B,IAAA,SAAS,EAAGzB;AAAzC,KALD,CADD;AASA,CA5CgC,CAA3B;;AA+CP,sBACC,uBADD,EAEC,2CAFD,EAGCiE,kBAHD;AAKA,sBACC,kBADD,EAEC,8CAFD,EAGCJ,qBAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { BaseControl, CustomSelectControl } from '@wordpress/components';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tuseContext,\n\tuseMemo,\n\tcreatePortal,\n\tPlatform,\n} from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport useSetting from '../components/use-setting';\nimport InspectorControls from '../components/inspector-controls';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nconst POSITION_SUPPORT_KEY = 'position';\n\nconst OPTION_CLASSNAME =\n\t'block-editor-hooks__position-selection__select-control__option';\n\nconst DEFAULT_OPTION = {\n\tkey: 'default',\n\tvalue: '',\n\tname: __( 'Default' ),\n\tclassName: OPTION_CLASSNAME,\n};\n\nconst STICKY_OPTION = {\n\tkey: 'sticky',\n\tvalue: 'sticky',\n\tname: __( 'Sticky' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will stick to the top of the window instead of scrolling.'\n\t),\n};\n\nconst FIXED_OPTION = {\n\tkey: 'fixed',\n\tvalue: 'fixed',\n\tname: __( 'Fixed' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will not move when the page is scrolled.'\n\t),\n};\n\nconst POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nconst VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];\n\n/**\n * Get calculated position CSS.\n *\n * @param {Object} props Component props.\n * @param {string} props.selector Selector to use.\n * @param {Object} props.style Style object.\n * @return {string} The generated CSS rules.\n */\nexport function getPositionCSS( { selector, style } ) {\n\tlet output = '';\n\n\tconst { type: positionType } = style?.position || {};\n\n\tif ( ! VALID_POSITION_TYPES.includes( positionType ) ) {\n\t\treturn output;\n\t}\n\n\toutput += `${ selector } {`;\n\toutput += `position: ${ positionType };`;\n\n\tPOSITION_SIDES.forEach( ( side ) => {\n\t\tif ( style?.position?.[ side ] !== undefined ) {\n\t\t\toutput += `${ side }: ${ style.position[ side ] };`;\n\t\t}\n\t} );\n\n\tif ( positionType === 'sticky' || positionType === 'fixed' ) {\n\t\t// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.\n\t\toutput += `z-index: 10`;\n\t}\n\toutput += `}`;\n\n\treturn output;\n}\n\n/**\n * Determines if there is sticky position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasStickyPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.sticky );\n}\n\n/**\n * Determines if there is fixed position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasFixedPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.fixed );\n}\n\n/**\n * Determines if there is position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! support;\n}\n\n/**\n * Checks if there is a current value in the position block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a position value set.\n */\nexport function hasPositionValue( props ) {\n\treturn props.attributes.style?.position?.type !== undefined;\n}\n\n/**\n * Checks if the block is currently set to a sticky or fixed position.\n * This check is helpful for determining how to position block toolbars or other elements.\n *\n * @param {Object} attributes Block attributes.\n * @return {boolean} Whether or not the block is set to a sticky or fixed position.\n */\nexport function hasStickyOrFixedPositionValue( attributes ) {\n\tconst positionType = attributes.style?.position?.type;\n\treturn positionType === 'sticky' || positionType === 'fixed';\n}\n\n/**\n * Resets the position block support attributes. This can be used when disabling\n * the position support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPosition( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: undefined,\n\t\t\t\ttop: undefined,\n\t\t\t\tright: undefined,\n\t\t\t\tbottom: undefined,\n\t\t\t\tleft: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if position settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPositionDisabled( { name: blockName } = {} ) {\n\tconst allowFixed = useSetting( 'position.fixed' );\n\tconst allowSticky = useSetting( 'position.sticky' );\n\tconst isDisabled = ! allowFixed && ! allowSticky;\n\n\treturn ! hasPositionSupport( blockName ) || isDisabled;\n}\n\n/*\n * Position controls rendered in an inspector control panel.\n *\n * @param {Object} props\n *\n * @return {WPElement} Position panel.\n */\nexport function PositionPanel( props ) {\n\tconst {\n\t\tattributes: { style = {} },\n\t\tclientId,\n\t\tname: blockName,\n\t\tsetAttributes,\n\t} = props;\n\n\tconst allowFixed = hasFixedPositionSupport( blockName );\n\tconst allowSticky = hasStickyPositionSupport( blockName );\n\tconst value = style?.position?.type;\n\n\tconst { hasParents } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParents } = select( blockEditorStore );\n\t\t\tconst parents = getBlockParents( clientId );\n\t\t\treturn {\n\t\t\t\thasParents: parents.length,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst options = useMemo( () => {\n\t\tconst availableOptions = [ DEFAULT_OPTION ];\n\t\t// Only display sticky option if the block has no parents (is at the root of the document),\n\t\t// or if the block already has a sticky position value set.\n\t\tif (\n\t\t\t( allowSticky && ! hasParents ) ||\n\t\t\tvalue === STICKY_OPTION.value\n\t\t) {\n\t\t\tavailableOptions.push( STICKY_OPTION );\n\t\t}\n\t\tif ( allowFixed || value === FIXED_OPTION.value ) {\n\t\t\tavailableOptions.push( FIXED_OPTION );\n\t\t}\n\t\treturn availableOptions;\n\t}, [ allowFixed, allowSticky, hasParents, value ] );\n\n\tconst onChangeType = ( next ) => {\n\t\t// For now, use a hard-coded `0px` value for the position.\n\t\t// `0px` is preferred over `0` as it can be used in `calc()` functions.\n\t\t// In the future, it could be useful to allow for an offset value.\n\t\tconst placementValue = '0px';\n\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: next,\n\t\t\t\ttop:\n\t\t\t\t\tnext === 'sticky' || next === 'fixed'\n\t\t\t\t\t\t? placementValue\n\t\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tconst selectedOption = value\n\t\t? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION\n\t\t: DEFAULT_OPTION;\n\n\t// Only display position controls if there is at least one option to choose from.\n\treturn Platform.select( {\n\t\tweb:\n\t\t\toptions.length > 1 ? (\n\t\t\t\t<InspectorControls group=\"position\">\n\t\t\t\t\t<BaseControl className=\"block-editor-hooks__position-selection\">\n\t\t\t\t\t\t<CustomSelectControl\n\t\t\t\t\t\t\t__nextUnconstrainedWidth\n\t\t\t\t\t\t\t__next36pxDefaultSize\n\t\t\t\t\t\t\tclassName=\"block-editor-hooks__position-selection__select-control\"\n\t\t\t\t\t\t\tlabel={ __( 'Position' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tdescribedBy={ sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Currently selected position.\n\t\t\t\t\t\t\t\t__( 'Currently selected position: %s' ),\n\t\t\t\t\t\t\t\tselectedOption.name\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\t\tvalue={ selectedOption }\n\t\t\t\t\t\t\t__experimentalShowSelectedHint\n\t\t\t\t\t\t\tonChange={ ( { selectedItem } ) => {\n\t\t\t\t\t\t\t\tonChangeType( selectedItem.value );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BaseControl>\n\t\t\t\t</InspectorControls>\n\t\t\t) : null,\n\t\tnative: null,\n\t} );\n}\n\n/**\n * Override the default edit UI to include position controls.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withInspectorControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name: blockName } = props;\n\t\tconst positionSupport = hasBlockSupport(\n\t\t\tblockName,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst showPositionControls =\n\t\t\tpositionSupport && ! useIsPositionDisabled( props );\n\n\t\treturn [\n\t\t\tshowPositionControls && (\n\t\t\t\t<PositionPanel key=\"position\" { ...props } />\n\t\t\t),\n\t\t\t<BlockEdit key=\"edit\" { ...props } />,\n\t\t];\n\t},\n\t'withInspectorControls'\n);\n\n/**\n * Override the default block element to add the position styles.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withPositionStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst hasPositionBlockSupport = hasBlockSupport(\n\t\t\tname,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst allowPositionStyles =\n\t\t\thasPositionBlockSupport && ! useIsPositionDisabled( props );\n\n\t\tconst id = useInstanceId( BlockListBlock );\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\t// Higher specificity to override defaults in editor UI.\n\t\tconst positionSelector = `.wp-container-${ id }.wp-container-${ id }`;\n\n\t\t// Get CSS string for the current position values.\n\t\tlet css;\n\t\tif ( allowPositionStyles ) {\n\t\t\tcss =\n\t\t\t\tgetPositionCSS( {\n\t\t\t\t\tselector: positionSelector,\n\t\t\t\t\tstyle: attributes?.style,\n\t\t\t\t} ) || '';\n\t\t}\n\n\t\t// Attach a `wp-container-` id-based class name.\n\t\tconst className = classnames( props?.className, {\n\t\t\t[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t\t[ `is-position-${ attributes?.style?.position?.type }` ]:\n\t\t\t\tallowPositionStyles &&\n\t\t\t\t!! css &&\n\t\t\t\t!! attributes?.style?.position?.type,\n\t\t} );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ allowPositionStyles &&\n\t\t\t\t\telement &&\n\t\t\t\t\t!! css &&\n\t\t\t\t\tcreatePortal( <style>{ css }</style>, element ) }\n\t\t\t\t<BlockListBlock { ...props } className={ className } />\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/position/with-position-styles',\n\twithPositionStyles\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/position/with-inspector-controls',\n\twithInspectorControls\n);\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getLastInsertedBlocksClientIds = getLastInsertedBlocksClientIds;
|
|
6
7
|
exports.isBlockInterfaceHidden = isBlockInterfaceHidden;
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -15,4 +16,17 @@ exports.isBlockInterfaceHidden = isBlockInterfaceHidden;
|
|
|
15
16
|
function isBlockInterfaceHidden(state) {
|
|
16
17
|
return state.isBlockInterfaceHidden;
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Gets the client ids of the last inserted blocks.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} state Global application state.
|
|
23
|
+
* @return {Array|undefined} Client Ids of the last inserted block(s).
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function getLastInsertedBlocksClientIds(state) {
|
|
28
|
+
var _state$lastBlockInser;
|
|
29
|
+
|
|
30
|
+
return state === null || state === void 0 ? void 0 : (_state$lastBlockInser = state.lastBlockInserted) === null || _state$lastBlockInser === void 0 ? void 0 : _state$lastBlockInser.clientIds;
|
|
31
|
+
}
|
|
18
32
|
//# sourceMappingURL=private-selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/store/private-selectors.js"],"names":["isBlockInterfaceHidden","state"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/store/private-selectors.js"],"names":["isBlockInterfaceHidden","state","getLastInsertedBlocksClientIds","lastBlockInserted","clientIds"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACD,sBAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,8BAAT,CAAyCD,KAAzC,EAAiD;AAAA;;AACvD,SAAOA,KAAP,aAAOA,KAAP,gDAAOA,KAAK,CAAEE,iBAAd,0DAAO,sBAA0BC,SAAjC;AACA","sourcesContent":["/**\n * Returns true if the block interface is hidden, or false otherwise.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the block toolbar is hidden.\n */\nexport function isBlockInterfaceHidden( state ) {\n\treturn state.isBlockInterfaceHidden;\n}\n\n/**\n * Gets the client ids of the last inserted blocks.\n *\n * @param {Object} state Global application state.\n * @return {Array|undefined} Client Ids of the last inserted block(s).\n */\nexport function getLastInsertedBlocksClientIds( state ) {\n\treturn state?.lastBlockInserted?.clientIds;\n}\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -52,7 +52,6 @@ exports.getClientIdsWithDescendants = exports.getClientIdsOfDescendants = export
|
|
|
52
52
|
exports.getDraggedBlockClientIds = getDraggedBlockClientIds;
|
|
53
53
|
exports.getFirstMultiSelectedBlockClientId = getFirstMultiSelectedBlockClientId;
|
|
54
54
|
exports.getInserterItems = exports.getGlobalBlockCount = void 0;
|
|
55
|
-
exports.getLastInsertedBlocksClientIds = getLastInsertedBlocksClientIds;
|
|
56
55
|
exports.getLastMultiSelectedBlockClientId = getLastMultiSelectedBlockClientId;
|
|
57
56
|
exports.getLowestCommonAncestorWithSelectedBlock = getLowestCommonAncestorWithSelectedBlock;
|
|
58
57
|
exports.getMultiSelectedBlockClientIds = getMultiSelectedBlockClientIds;
|
|
@@ -2716,19 +2715,6 @@ function wasBlockJustInserted(state, clientId, source) {
|
|
|
2716
2715
|
} = state;
|
|
2717
2716
|
return ((_lastBlockInserted$cl = lastBlockInserted.clientIds) === null || _lastBlockInserted$cl === void 0 ? void 0 : _lastBlockInserted$cl.includes(clientId)) && lastBlockInserted.source === source;
|
|
2718
2717
|
}
|
|
2719
|
-
/**
|
|
2720
|
-
* Gets the client ids of the last inserted blocks.
|
|
2721
|
-
*
|
|
2722
|
-
* @param {Object} state Global application state.
|
|
2723
|
-
* @return {Array|undefined} Client Ids of the last inserted block(s).
|
|
2724
|
-
*/
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
function getLastInsertedBlocksClientIds(state) {
|
|
2728
|
-
var _state$lastBlockInser;
|
|
2729
|
-
|
|
2730
|
-
return state === null || state === void 0 ? void 0 : (_state$lastBlockInser = state.lastBlockInserted) === null || _state$lastBlockInser === void 0 ? void 0 : _state$lastBlockInser.clientIds;
|
|
2731
|
-
}
|
|
2732
2718
|
/**
|
|
2733
2719
|
* Tells if the block is visible on the canvas or not.
|
|
2734
2720
|
*
|