@wordpress/block-editor 12.19.4 → 12.19.5
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 +45 -32
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/block-bindings-toolbar-indicator/index.js +25 -0
- package/build/components/block-bindings-toolbar-indicator/index.js.map +1 -0
- package/build/components/block-list/use-block-props/index.js +8 -1
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -3
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +12 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-toolbar/index.js +14 -5
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +10 -2
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/use-clipboard-handler.js +2 -1
- package/build/components/list-view/use-clipboard-handler.js.map +1 -1
- package/build/components/rich-text/index.js +1 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/url-popover/index.js +3 -3
- package/build/components/url-popover/index.js.map +1 -1
- package/build/components/writing-flow/use-clipboard-handler.js +2 -1
- package/build/components/writing-flow/use-clipboard-handler.js.map +1 -1
- package/build/components/writing-flow/utils.js +23 -6
- package/build/components/writing-flow/utils.js.map +1 -1
- package/build/hooks/block-hooks.js +26 -2
- package/build/hooks/block-hooks.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +171 -46
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/private-apis.js +2 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +40 -6
- package/build/store/actions.js.map +1 -1
- package/build-module/components/block-actions/index.js +45 -32
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/block-bindings-toolbar-indicator/index.js +18 -0
- package/build-module/components/block-bindings-toolbar-indicator/index.js.map +1 -0
- package/build-module/components/block-list/use-block-props/index.js +9 -2
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -3
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +12 -10
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +14 -5
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +11 -3
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/use-clipboard-handler.js +3 -2
- package/build-module/components/list-view/use-clipboard-handler.js.map +1 -1
- package/build-module/components/rich-text/index.js +2 -2
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/url-popover/index.js +3 -3
- package/build-module/components/url-popover/index.js.map +1 -1
- package/build-module/components/writing-flow/use-clipboard-handler.js +3 -2
- package/build-module/components/writing-flow/use-clipboard-handler.js.map +1 -1
- package/build-module/components/writing-flow/utils.js +22 -7
- package/build-module/components/writing-flow/utils.js.map +1 -1
- package/build-module/hooks/block-hooks.js +26 -2
- package/build-module/hooks/block-hooks.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +171 -46
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +40 -6
- package/build-module/store/actions.js.map +1 -1
- package/build-style/content-rtl.css +1 -0
- package/build-style/content.css +1 -0
- package/build-style/default-editor-styles-rtl.css +1 -0
- package/build-style/default-editor-styles.css +1 -0
- package/build-style/style-rtl.css +23 -0
- package/build-style/style.css +23 -0
- package/package.json +8 -8
- package/src/components/block-actions/index.js +57 -47
- package/src/components/block-bindings-toolbar-indicator/index.js +20 -0
- package/src/components/block-bindings-toolbar-indicator/style.scss +14 -0
- package/src/components/block-list/use-block-props/index.js +12 -2
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -7
- package/src/components/block-settings-menu/block-settings-dropdown.js +12 -9
- package/src/components/block-toolbar/index.js +14 -4
- package/src/components/list-view/block-select-button.js +16 -2
- package/src/components/list-view/style.scss +8 -0
- package/src/components/list-view/use-clipboard-handler.js +3 -2
- package/src/components/rich-text/index.js +2 -2
- package/src/components/url-popover/index.js +5 -5
- package/src/components/writing-flow/use-clipboard-handler.js +3 -2
- package/src/components/writing-flow/utils.js +31 -16
- package/src/hooks/block-hooks.js +36 -3
- package/src/hooks/use-bindings-attributes.js +214 -62
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +54 -14
- package/src/style.scss +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dom","require","_data","_compose","_store","_useNotifyCopy","_utils","useClipboardHandler","getBlocksByClientId","getSelectedBlockClientIds","hasMultiSelection","getSettings","__unstableIsFullySelected","__unstableIsSelectionCollapsed","__unstableIsSelectionMergeable","__unstableGetSelectedBlocksWithPartialSelection","canInsertBlockType","useSelect","blockEditorStore","flashBlock","removeBlocks","replaceBlocks","__unstableDeleteSelection","__unstableExpandSelection","insertBlocks","useDispatch","notifyCopy","useNotifyCopy","useRefEffect","node","handler","event","defaultPrevented","selectedBlockClientIds","length","target","ownerDocument","hasSelection","type","documentHasUncollapsedSelection","documentHasSelection","contains","activeElement","preventDefault","isSelectionMergeable","shouldHandleWholeBlocks","expandSelectionIsNeeded","blocks","head","tail","inBetweenBlocks","slice","setClipboardBlocks","contentEditable","__experimentalCanUserUseUnfilteredHTML","canUserUseUnfilteredHTML","getPasteBlocks","selectedBlockClientId","every","block","name","undefined","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-clipboard-handler.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tdocumentHasSelection,\n\tdocumentHasUncollapsedSelection,\n} from '@wordpress/dom';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { useNotifyCopy } from '../../utils/use-notify-copy';\nimport { getPasteBlocks, setClipboardBlocks } from './utils';\n\nexport default function useClipboardHandler() {\n\tconst {\n\t\tgetBlocksByClientId,\n\t\tgetSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSettings,\n\t\t__unstableIsFullySelected,\n\t\t__unstableIsSelectionCollapsed,\n\t\t__unstableIsSelectionMergeable,\n\t\t__unstableGetSelectedBlocksWithPartialSelection,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tflashBlock,\n\t\tremoveBlocks,\n\t\treplaceBlocks,\n\t\t__unstableDeleteSelection,\n\t\t__unstableExpandSelection,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst notifyCopy = useNotifyCopy();\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction handler( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t// This was likely already handled in rich-text/use-paste-handler.js.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\n\t\t\tif ( selectedBlockClientIds.length === 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Always handle multiple selected blocks.\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\tconst { target } = event;\n\t\t\t\tconst { ownerDocument } = target;\n\t\t\t\t// If copying, only consider actual text selection as selection.\n\t\t\t\t// Otherwise, any focus on an input field is considered.\n\t\t\t\tconst hasSelection =\n\t\t\t\t\tevent.type === 'copy' || event.type === 'cut'\n\t\t\t\t\t\t? documentHasUncollapsedSelection( ownerDocument )\n\t\t\t\t\t\t: documentHasSelection( ownerDocument );\n\n\t\t\t\t// Let native copy behaviour take over in input fields.\n\t\t\t\tif ( hasSelection ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! node.contains( event.target.ownerDocument.activeElement ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\tconst isSelectionMergeable = __unstableIsSelectionMergeable();\n\t\t\tconst shouldHandleWholeBlocks =\n\t\t\t\t__unstableIsSelectionCollapsed() || __unstableIsFullySelected();\n\t\t\tconst expandSelectionIsNeeded =\n\t\t\t\t! shouldHandleWholeBlocks && ! isSelectionMergeable;\n\t\t\tif ( event.type === 'copy' || event.type === 'cut' ) {\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tflashBlock( selectedBlockClientIds[ 0 ] );\n\t\t\t\t}\n\t\t\t\t// If we have a partial selection that is not mergeable, just\n\t\t\t\t// expand the selection to the whole blocks.\n\t\t\t\tif ( expandSelectionIsNeeded ) {\n\t\t\t\t\t__unstableExpandSelection();\n\t\t\t\t} else {\n\t\t\t\t\tnotifyCopy( event.type, selectedBlockClientIds );\n\t\t\t\t\tlet blocks;\n\t\t\t\t\t// Check if we have partial selection.\n\t\t\t\t\tif ( shouldHandleWholeBlocks ) {\n\t\t\t\t\t\tblocks = getBlocksByClientId( selectedBlockClientIds );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst [ head, tail ] =\n\t\t\t\t\t\t\t__unstableGetSelectedBlocksWithPartialSelection();\n\t\t\t\t\t\tconst inBetweenBlocks = getBlocksByClientId(\n\t\t\t\t\t\t\tselectedBlockClientIds.slice(\n\t\t\t\t\t\t\t\t1,\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length - 1\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tblocks = [ head, ...inBetweenBlocks, tail ];\n\t\t\t\t\t}\n\n\t\t\t\t\tsetClipboardBlocks( event, blocks );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( event.type === 'cut' ) {\n\t\t\t\t// We need to also check if at the start we needed to\n\t\t\t\t// expand the selection, as in this point we might have\n\t\t\t\t// programmatically fully selected the blocks above.\n\t\t\t\tif ( shouldHandleWholeBlocks && ! expandSelectionIsNeeded ) {\n\t\t\t\t\tremoveBlocks( selectedBlockClientIds );\n\t\t\t\t} else {\n\t\t\t\t\tevent.target.ownerDocument.activeElement.contentEditable = false;\n\t\t\t\t\t__unstableDeleteSelection();\n\t\t\t\t}\n\t\t\t} else if ( event.type === 'paste' ) {\n\t\t\t\tconst {\n\t\t\t\t\t__experimentalCanUserUseUnfilteredHTML:\n\t\t\t\t\t\tcanUserUseUnfilteredHTML,\n\t\t\t\t} = getSettings();\n\t\t\t\tconst blocks = getPasteBlocks(\n\t\t\t\t\tevent,\n\t\t\t\t\tcanUserUseUnfilteredHTML\n\t\t\t\t);\n\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tconst [ selectedBlockClientId ] = selectedBlockClientIds;\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tblocks.every( ( block ) =>\n\t\t\t\t\t\t\tcanInsertBlockType(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tselectedBlockClientId\n\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\t\tinsertBlocks(\n\t\t\t\t\t\t\tblocks,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tselectedBlockClientId\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treplaceBlocks(\n\t\t\t\t\tselectedBlockClientIds,\n\t\t\t\t\tblocks,\n\t\t\t\t\tblocks.length - 1,\n\t\t\t\t\t-1\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tnode.ownerDocument.addEventListener( 'copy', handler );\n\t\tnode.ownerDocument.addEventListener( 'cut', handler );\n\t\tnode.ownerDocument.addEventListener( 'paste', handler );\n\n\t\treturn () => {\n\t\t\tnode.ownerDocument.removeEventListener( 'copy', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'cut', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'paste', handler );\n\t\t};\n\t}, [] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAfA;AACA;AACA;;AAQA;AACA;AACA;;AAKe,SAASM,mBAAmBA,CAAA,EAAG;EAC7C,MAAM;IACLC,mBAAmB;IACnBC,yBAAyB;IACzBC,iBAAiB;IACjBC,WAAW;IACXC,yBAAyB;IACzBC,8BAA8B;IAC9BC,8BAA8B;IAC9BC,+CAA+C;IAC/CC;EACD,CAAC,GAAG,IAAAC,eAAS,EAAEC,YAAiB,CAAC;EACjC,MAAM;IACLC,UAAU;IACVC,YAAY;IACZC,aAAa;IACbC,yBAAyB;IACzBC,yBAAyB;IACzBC;EACD,CAAC,GAAG,IAAAC,iBAAW,EAAEP,YAAiB,CAAC;EACnC,MAAMQ,UAAU,GAAG,IAAAC,4BAAa,EAAC,CAAC;EAElC,OAAO,IAAAC,qBAAY,EAAIC,IAAI,IAAM;IAChC,SAASC,OAAOA,CAAEC,KAAK,EAAG;MACzB,IAAKA,KAAK,CAACC,gBAAgB,EAAG;QAC7B;QACA;MACD;MAEA,MAAMC,sBAAsB,GAAGxB,yBAAyB,CAAC,CAAC;MAE1D,IAAKwB,sBAAsB,CAACC,MAAM,KAAK,CAAC,EAAG;QAC1C;MACD;;MAEA;MACA,IAAK,CAAExB,iBAAiB,CAAC,CAAC,EAAG;QAC5B,MAAM;UAAEyB;QAAO,CAAC,GAAGJ,KAAK;QACxB,MAAM;UAAEK;QAAc,CAAC,GAAGD,MAAM;QAChC;QACA;QACA,MAAME,YAAY,GACjBN,KAAK,CAACO,IAAI,KAAK,MAAM,IAA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,IAAI,CAACO,aAAa,CAAC2B,mBAAmB,CAAE,MAAM,EAAEjC,OAAQ,CAAC;MACzDD,IAAI,CAACO,aAAa,CAAC2B,mBAAmB,CAAE,KAAK,EAAEjC,OAAQ,CAAC;MACxDD,IAAI,CAACO,aAAa,CAAC2B,mBAAmB,CAAE,OAAO,EAAEjC,OAAQ,CAAC;IAC3D,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR"}
|
|
1
|
+
{"version":3,"names":["_dom","require","_data","_compose","_store","_useNotifyCopy","_utils","useClipboardHandler","registry","useRegistry","getBlocksByClientId","getSelectedBlockClientIds","hasMultiSelection","getSettings","__unstableIsFullySelected","__unstableIsSelectionCollapsed","__unstableIsSelectionMergeable","__unstableGetSelectedBlocksWithPartialSelection","canInsertBlockType","useSelect","blockEditorStore","flashBlock","removeBlocks","replaceBlocks","__unstableDeleteSelection","__unstableExpandSelection","insertBlocks","useDispatch","notifyCopy","useNotifyCopy","useRefEffect","node","handler","event","defaultPrevented","selectedBlockClientIds","length","target","ownerDocument","hasSelection","type","documentHasUncollapsedSelection","documentHasSelection","contains","activeElement","preventDefault","isSelectionMergeable","shouldHandleWholeBlocks","expandSelectionIsNeeded","blocks","head","tail","inBetweenBlocks","slice","setClipboardBlocks","contentEditable","__experimentalCanUserUseUnfilteredHTML","canUserUseUnfilteredHTML","getPasteBlocks","selectedBlockClientId","every","block","name","undefined","addEventListener","removeEventListener"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-clipboard-handler.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tdocumentHasSelection,\n\tdocumentHasUncollapsedSelection,\n} from '@wordpress/dom';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { useNotifyCopy } from '../../utils/use-notify-copy';\nimport { getPasteBlocks, setClipboardBlocks } from './utils';\n\nexport default function useClipboardHandler() {\n\tconst registry = useRegistry();\n\tconst {\n\t\tgetBlocksByClientId,\n\t\tgetSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSettings,\n\t\t__unstableIsFullySelected,\n\t\t__unstableIsSelectionCollapsed,\n\t\t__unstableIsSelectionMergeable,\n\t\t__unstableGetSelectedBlocksWithPartialSelection,\n\t\tcanInsertBlockType,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tflashBlock,\n\t\tremoveBlocks,\n\t\treplaceBlocks,\n\t\t__unstableDeleteSelection,\n\t\t__unstableExpandSelection,\n\t\tinsertBlocks,\n\t} = useDispatch( blockEditorStore );\n\tconst notifyCopy = useNotifyCopy();\n\n\treturn useRefEffect( ( node ) => {\n\t\tfunction handler( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t// This was likely already handled in rich-text/use-paste-handler.js.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\n\t\t\tif ( selectedBlockClientIds.length === 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Always handle multiple selected blocks.\n\t\t\tif ( ! hasMultiSelection() ) {\n\t\t\t\tconst { target } = event;\n\t\t\t\tconst { ownerDocument } = target;\n\t\t\t\t// If copying, only consider actual text selection as selection.\n\t\t\t\t// Otherwise, any focus on an input field is considered.\n\t\t\t\tconst hasSelection =\n\t\t\t\t\tevent.type === 'copy' || event.type === 'cut'\n\t\t\t\t\t\t? documentHasUncollapsedSelection( ownerDocument )\n\t\t\t\t\t\t: documentHasSelection( ownerDocument );\n\n\t\t\t\t// Let native copy behaviour take over in input fields.\n\t\t\t\tif ( hasSelection ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! node.contains( event.target.ownerDocument.activeElement ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tevent.preventDefault();\n\n\t\t\tconst isSelectionMergeable = __unstableIsSelectionMergeable();\n\t\t\tconst shouldHandleWholeBlocks =\n\t\t\t\t__unstableIsSelectionCollapsed() || __unstableIsFullySelected();\n\t\t\tconst expandSelectionIsNeeded =\n\t\t\t\t! shouldHandleWholeBlocks && ! isSelectionMergeable;\n\t\t\tif ( event.type === 'copy' || event.type === 'cut' ) {\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tflashBlock( selectedBlockClientIds[ 0 ] );\n\t\t\t\t}\n\t\t\t\t// If we have a partial selection that is not mergeable, just\n\t\t\t\t// expand the selection to the whole blocks.\n\t\t\t\tif ( expandSelectionIsNeeded ) {\n\t\t\t\t\t__unstableExpandSelection();\n\t\t\t\t} else {\n\t\t\t\t\tnotifyCopy( event.type, selectedBlockClientIds );\n\t\t\t\t\tlet blocks;\n\t\t\t\t\t// Check if we have partial selection.\n\t\t\t\t\tif ( shouldHandleWholeBlocks ) {\n\t\t\t\t\t\tblocks = getBlocksByClientId( selectedBlockClientIds );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst [ head, tail ] =\n\t\t\t\t\t\t\t__unstableGetSelectedBlocksWithPartialSelection();\n\t\t\t\t\t\tconst inBetweenBlocks = getBlocksByClientId(\n\t\t\t\t\t\t\tselectedBlockClientIds.slice(\n\t\t\t\t\t\t\t\t1,\n\t\t\t\t\t\t\t\tselectedBlockClientIds.length - 1\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\tblocks = [ head, ...inBetweenBlocks, tail ];\n\t\t\t\t\t}\n\n\t\t\t\t\tsetClipboardBlocks( event, blocks, registry );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( event.type === 'cut' ) {\n\t\t\t\t// We need to also check if at the start we needed to\n\t\t\t\t// expand the selection, as in this point we might have\n\t\t\t\t// programmatically fully selected the blocks above.\n\t\t\t\tif ( shouldHandleWholeBlocks && ! expandSelectionIsNeeded ) {\n\t\t\t\t\tremoveBlocks( selectedBlockClientIds );\n\t\t\t\t} else {\n\t\t\t\t\tevent.target.ownerDocument.activeElement.contentEditable = false;\n\t\t\t\t\t__unstableDeleteSelection();\n\t\t\t\t}\n\t\t\t} else if ( event.type === 'paste' ) {\n\t\t\t\tconst {\n\t\t\t\t\t__experimentalCanUserUseUnfilteredHTML:\n\t\t\t\t\t\tcanUserUseUnfilteredHTML,\n\t\t\t\t} = getSettings();\n\t\t\t\tconst blocks = getPasteBlocks(\n\t\t\t\t\tevent,\n\t\t\t\t\tcanUserUseUnfilteredHTML\n\t\t\t\t);\n\n\t\t\t\tif ( selectedBlockClientIds.length === 1 ) {\n\t\t\t\t\tconst [ selectedBlockClientId ] = selectedBlockClientIds;\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tblocks.every( ( block ) =>\n\t\t\t\t\t\t\tcanInsertBlockType(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tselectedBlockClientId\n\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\t\tinsertBlocks(\n\t\t\t\t\t\t\tblocks,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tselectedBlockClientId\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treplaceBlocks(\n\t\t\t\t\tselectedBlockClientIds,\n\t\t\t\t\tblocks,\n\t\t\t\t\tblocks.length - 1,\n\t\t\t\t\t-1\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tnode.ownerDocument.addEventListener( 'copy', handler );\n\t\tnode.ownerDocument.addEventListener( 'cut', handler );\n\t\tnode.ownerDocument.addEventListener( 'paste', handler );\n\n\t\treturn () => {\n\t\t\tnode.ownerDocument.removeEventListener( 'copy', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'cut', handler );\n\t\t\tnode.ownerDocument.removeEventListener( 'paste', handler );\n\t\t};\n\t}, [] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AAI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CAACO,aAAa,CAAC2B,mBAAmB,CAAE,KAAK,EAAEjC,OAAQ,CAAC;MACxDD,IAAI,CAACO,aAAa,CAAC2B,mBAAmB,CAAE,OAAO,EAAEjC,OAAQ,CAAC;IAC3D,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR"}
|
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getPasteBlocks = getPasteBlocks;
|
|
7
|
+
exports.requiresWrapperOnCopy = void 0;
|
|
7
8
|
exports.setClipboardBlocks = setClipboardBlocks;
|
|
8
9
|
var _dom = require("@wordpress/dom");
|
|
9
10
|
var _blocks2 = require("@wordpress/blocks");
|
|
10
11
|
var _pasting = require("../../utils/pasting");
|
|
12
|
+
var _store = require("../../store");
|
|
11
13
|
/**
|
|
12
14
|
* WordPress dependencies
|
|
13
15
|
*/
|
|
@@ -16,18 +18,33 @@ var _pasting = require("../../utils/pasting");
|
|
|
16
18
|
* Internal dependencies
|
|
17
19
|
*/
|
|
18
20
|
|
|
21
|
+
const requiresWrapperOnCopy = exports.requiresWrapperOnCopy = Symbol('requiresWrapperOnCopy');
|
|
22
|
+
|
|
19
23
|
/**
|
|
20
24
|
* Sets the clipboard data for the provided blocks, with both HTML and plain
|
|
21
25
|
* text representations.
|
|
22
26
|
*
|
|
23
|
-
* @param {ClipboardEvent} event
|
|
24
|
-
* @param {WPBlock[]} blocks
|
|
27
|
+
* @param {ClipboardEvent} event Clipboard event.
|
|
28
|
+
* @param {WPBlock[]} blocks Blocks to set as clipboard data.
|
|
29
|
+
* @param {Object} registry The registry to select from.
|
|
25
30
|
*/
|
|
26
|
-
function setClipboardBlocks(event, blocks) {
|
|
31
|
+
function setClipboardBlocks(event, blocks, registry) {
|
|
27
32
|
let _blocks = blocks;
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
|
|
33
|
+
const [firstBlock] = blocks;
|
|
34
|
+
if (firstBlock) {
|
|
35
|
+
const firstBlockType = registry.select(_blocks2.store).getBlockType(firstBlock.name);
|
|
36
|
+
if (firstBlockType[requiresWrapperOnCopy]) {
|
|
37
|
+
const {
|
|
38
|
+
getBlockRootClientId,
|
|
39
|
+
getBlockName,
|
|
40
|
+
getBlockAttributes
|
|
41
|
+
} = registry.select(_store.store);
|
|
42
|
+
const wrapperBlockClientId = getBlockRootClientId(firstBlock.clientId);
|
|
43
|
+
const wrapperBlockName = getBlockName(wrapperBlockClientId);
|
|
44
|
+
if (wrapperBlockName) {
|
|
45
|
+
_blocks = (0, _blocks2.createBlock)(wrapperBlockName, getBlockAttributes(wrapperBlockClientId), _blocks);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
31
48
|
}
|
|
32
49
|
const serialized = (0, _blocks2.serialize)(_blocks);
|
|
33
50
|
event.clipboardData.setData('text/plain', toPlainText(serialized));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dom","require","_blocks2","_pasting","setClipboardBlocks","event","blocks","_blocks","
|
|
1
|
+
{"version":3,"names":["_dom","require","_blocks2","_pasting","_store","requiresWrapperOnCopy","exports","Symbol","setClipboardBlocks","event","blocks","registry","_blocks","firstBlock","firstBlockType","select","blocksStore","getBlockType","name","getBlockRootClientId","getBlockName","getBlockAttributes","blockEditorStore","wrapperBlockClientId","clientId","wrapperBlockName","createBlock","serialized","serialize","clipboardData","setData","toPlainText","getPasteBlocks","canUserUseUnfilteredHTML","plainText","html","files","getPasteEventData","length","fromTransforms","getBlockTransforms","reduce","accumulator","file","transformation","findTransform","transform","type","isMatch","push","flat","pasteHandler","HTML","mode","replace","stripHTML","trim"],"sources":["@wordpress/block-editor/src/components/writing-flow/utils.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tserialize,\n\tcreateBlock,\n\tpasteHandler,\n\tfindTransform,\n\tgetBlockTransforms,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { getPasteEventData } from '../../utils/pasting';\nimport { store as blockEditorStore } from '../../store';\n\nexport const requiresWrapperOnCopy = Symbol( 'requiresWrapperOnCopy' );\n\n/**\n * Sets the clipboard data for the provided blocks, with both HTML and plain\n * text representations.\n *\n * @param {ClipboardEvent} event Clipboard event.\n * @param {WPBlock[]} blocks Blocks to set as clipboard data.\n * @param {Object} registry The registry to select from.\n */\nexport function setClipboardBlocks( event, blocks, registry ) {\n\tlet _blocks = blocks;\n\n\tconst [ firstBlock ] = blocks;\n\n\tif ( firstBlock ) {\n\t\tconst firstBlockType = registry\n\t\t\t.select( blocksStore )\n\t\t\t.getBlockType( firstBlock.name );\n\n\t\tif ( firstBlockType[ requiresWrapperOnCopy ] ) {\n\t\t\tconst { getBlockRootClientId, getBlockName, getBlockAttributes } =\n\t\t\t\tregistry.select( blockEditorStore );\n\t\t\tconst wrapperBlockClientId = getBlockRootClientId(\n\t\t\t\tfirstBlock.clientId\n\t\t\t);\n\t\t\tconst wrapperBlockName = getBlockName( wrapperBlockClientId );\n\n\t\t\tif ( wrapperBlockName ) {\n\t\t\t\t_blocks = createBlock(\n\t\t\t\t\twrapperBlockName,\n\t\t\t\t\tgetBlockAttributes( wrapperBlockClientId ),\n\t\t\t\t\t_blocks\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst serialized = serialize( _blocks );\n\n\tevent.clipboardData.setData( 'text/plain', toPlainText( serialized ) );\n\tevent.clipboardData.setData( 'text/html', serialized );\n}\n\n/**\n * Returns the blocks to be pasted from the clipboard event.\n *\n * @param {ClipboardEvent} event The clipboard event.\n * @param {boolean} canUserUseUnfilteredHTML Whether the user can or can't post unfiltered HTML.\n * @return {Array|string} A list of blocks or a string, depending on `handlerMode`.\n */\nexport function getPasteBlocks( event, canUserUseUnfilteredHTML ) {\n\tconst { plainText, html, files } = getPasteEventData( event );\n\tlet blocks = [];\n\n\tif ( files.length ) {\n\t\tconst fromTransforms = getBlockTransforms( 'from' );\n\t\tblocks = files\n\t\t\t.reduce( ( accumulator, file ) => {\n\t\t\t\tconst transformation = findTransform(\n\t\t\t\t\tfromTransforms,\n\t\t\t\t\t( transform ) =>\n\t\t\t\t\t\ttransform.type === 'files' &&\n\t\t\t\t\t\ttransform.isMatch( [ file ] )\n\t\t\t\t);\n\t\t\t\tif ( transformation ) {\n\t\t\t\t\taccumulator.push( transformation.transform( [ file ] ) );\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t}, [] )\n\t\t\t.flat();\n\t} else {\n\t\tblocks = pasteHandler( {\n\t\t\tHTML: html,\n\t\t\tplainText,\n\t\t\tmode: 'BLOCKS',\n\t\t\tcanUserUseUnfilteredHTML,\n\t\t} );\n\t}\n\n\treturn blocks;\n}\n\n/**\n * Given a string of HTML representing serialized blocks, returns the plain\n * text extracted after stripping the HTML of any tags and fixing line breaks.\n *\n * @param {string} html Serialized blocks.\n * @return {string} The plain-text content with any html removed.\n */\nfunction toPlainText( html ) {\n\t// Manually handle BR tags as line breaks prior to `stripHTML` call\n\thtml = html.replace( /<br>/g, '\\n' );\n\n\tconst plainText = stripHTML( html ).trim();\n\n\t// Merge any consecutive line breaks\n\treturn plainText.replace( /\\n\\n+/g, '\\n\\n' );\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAYA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAjBA;AACA;AACA;;AAWA;AACA;AACA;;AAIO,MAAMI,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAGE,MAAM,CAAE,uBAAwB,CAAC;;AAEtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,EAAG;EAC7D,IAAIC,OAAO,GAAGF,MAAM;EAEpB,MAAM,CAAEG,UAAU,CAAE,GAAGH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AG,IAAAC,sBAAa,EACnCN,cAAc,EACZO,SAAS,IACVA,SAAS,CAACC,IAAI,KAAK,OAAO,IAC1BD,SAAS,CAACE,OAAO,CAAE,CAAEL,IAAI,CAAG,CAC9B,CAAC;MACD,IAAKC,cAAc,EAAG;QACrBF,WAAW,CAACO,IAAI,CAAEL,cAAc,CAACE,SAAS,CAAE,CAAEH,IAAI,CAAG,CAAE,CAAC;MACzD;MACA,OAAOD,WAAW;IACnB,CAAC,EAAE,EAAG,CAAC,CACNQ,IAAI,CAAC,CAAC;EACT,CAAC,MAAM;IACNxC,MAAM,GAAG,IAAAyC,qBAAY,EAAE;MACtBC,IAAI,EAAEjB,IAAI;MACVD,SAAS;MACTmB,IAAI,EAAE,QAAQ;MACdpB;IACD,CAAE,CAAC;EACJ;EAEA,OAAOvB,MAAM;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASqB,WAAWA,CAAEI,IAAI,EAAG;EAC5B;EACAA,IAAI,GAAGA,IAAI,CAACmB,OAAO,CAAE,OAAO,EAAE,IAAK,CAAC;EAEpC,MAAMpB,SAAS,GAAG,IAAAqB,wBAAS,EAAEpB,IAAK,CAAC,CAACqB,IAAI,CAAC,CAAC;;EAE1C;EACA,OAAOtB,SAAS,CAACoB,OAAO,CAAE,QAAQ,EAAE,MAAO,CAAC;AAC7C"}
|
|
@@ -23,12 +23,21 @@ var _store = require("../store");
|
|
|
23
23
|
const EMPTY_OBJECT = {};
|
|
24
24
|
function BlockHooksControlPure({
|
|
25
25
|
name,
|
|
26
|
-
clientId
|
|
26
|
+
clientId,
|
|
27
|
+
metadata: {
|
|
28
|
+
ignoredHookedBlocks = []
|
|
29
|
+
} = {}
|
|
27
30
|
}) {
|
|
28
31
|
const blockTypes = (0, _data.useSelect)(select => select(_blocks.store).getBlockTypes(), []);
|
|
32
|
+
|
|
33
|
+
// A hooked block added via a filter will not be exposed through a block
|
|
34
|
+
// type's `blockHooks` property; however, if the containing layout has been
|
|
35
|
+
// modified, it will be present in the anchor block's `ignoredHookedBlocks`
|
|
36
|
+
// metadata.
|
|
29
37
|
const hookedBlocksForCurrentBlock = (0, _element.useMemo)(() => blockTypes?.filter(({
|
|
38
|
+
name: blockName,
|
|
30
39
|
blockHooks
|
|
31
|
-
}) => blockHooks && name in blockHooks), [blockTypes, name]);
|
|
40
|
+
}) => blockHooks && name in blockHooks || ignoredHookedBlocks.includes(blockName)), [blockTypes, name, ignoredHookedBlocks]);
|
|
32
41
|
const {
|
|
33
42
|
blockIndex,
|
|
34
43
|
rootClientId,
|
|
@@ -73,6 +82,12 @@ function BlockHooksControlPure({
|
|
|
73
82
|
// inserted and then moved around a bit by the user.
|
|
74
83
|
candidates = getBlocks(clientId);
|
|
75
84
|
break;
|
|
85
|
+
case undefined:
|
|
86
|
+
// If we haven't found a blockHooks field with a relative position for the hooked
|
|
87
|
+
// block, it means that it was added by a filter. In this case, we look for the block
|
|
88
|
+
// both among the current block's siblings and its children.
|
|
89
|
+
candidates = [...getBlocks(rootClientId), ...getBlocks(clientId)];
|
|
90
|
+
break;
|
|
76
91
|
}
|
|
77
92
|
const hookedBlock = candidates?.find(candidate => candidate.name === block.name);
|
|
78
93
|
|
|
@@ -127,6 +142,14 @@ function BlockHooksControlPure({
|
|
|
127
142
|
// Insert as a child of the current block.
|
|
128
143
|
false);
|
|
129
144
|
break;
|
|
145
|
+
case undefined:
|
|
146
|
+
// If we do not know the relative position, it is because the block was
|
|
147
|
+
// added via a filter. In this case, we default to inserting it after the
|
|
148
|
+
// current block.
|
|
149
|
+
insertBlock(block, blockIndex + 1, rootClientId,
|
|
150
|
+
// Insert as a child of the current block's parent
|
|
151
|
+
false);
|
|
152
|
+
break;
|
|
130
153
|
}
|
|
131
154
|
};
|
|
132
155
|
return (0, _react.createElement)(_components2.InspectorControls, null, (0, _react.createElement)(_components.PanelBody, {
|
|
@@ -165,6 +188,7 @@ function BlockHooksControlPure({
|
|
|
165
188
|
}
|
|
166
189
|
var _default = exports.default = {
|
|
167
190
|
edit: BlockHooksControlPure,
|
|
191
|
+
attributeKeys: ['metadata'],
|
|
168
192
|
hasSupport() {
|
|
169
193
|
return true;
|
|
170
194
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_element","_components","_blocks","_data","_components2","_store","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","blockTypes","useSelect","select","blocksStore","getBlockTypes","hookedBlocksForCurrentBlock","useMemo","filter","blockHooks","blockIndex","rootClientId","innerBlocksLength","getBlocks","getBlockIndex","getBlockRootClientId","blockEditorStore","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","useDispatch","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","_react","createElement","InspectorControls","PanelBody","className","title","__","initialOpen","keys","map","vendor","Fragment","key","checked","ToggleControl","label","__experimentalHStack","justify","BlockIcon","icon","onChange","createBlock","_default","exports","default","edit","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControlPure( { name, clientId } ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { blockHooks } ) => blockHooks && name in blockHooks\n\t\t\t),\n\t\t[ blockTypes, name ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\tinnerBlocksLength: getBlocks( clientId )?.length,\n\t\t\t\trootClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to set the toggle to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition = block?.blockHooks?.[ name ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlocks( rootClientId );\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlocks( clientId );\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( candidate ) => candidate.name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// we set the toggle to disabled.\n\t\t\t\t\treturn clientIds;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[ hookedBlocksForCurrentBlock, name, clientId, rootClientId ]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\tif ( ! hookedBlocksForCurrentBlock.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tclientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t<p className=\"block-editor-hooks__block-hooks-helptext\">\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Manage the inclusion of blocks added automatically by plugins.'\n\t\t\t\t\t) }\n\t\t\t\t</p>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[ name ];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock(\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: BlockHooksControlPure,\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAKA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA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AAEgB,MAAM,CAAE,CAACD,GAAG,CAAI1B,KAAK,IAAM;MACjD,MAAM8B,OAAO,IACZ9B,KAAK,CAACxB,IAAI,IAAImB,oBAAoB;MAEnC,OACC,IAAAsB,MAAA,CAAAC,aAAA,EAACjD,WAAA,CAAA8D,aAAa;QACbD,OAAO,EAAGA,OAAS;QACnBD,GAAG,EAAG7B,KAAK,CAACsB,KAAO;QACnBU,KAAK,EACJ,IAAAf,MAAA,CAAAC,aAAA,EAACjD,WAAA,CAAAgE,oBAAM;UAACC,OAAO,EAAC;QAAY,GAC3B,IAAAjB,MAAA,CAAAC,aAAA,EAAC9C,YAAA,CAAA+D,SAAS;UACTC,IAAI,EAAGpC,KAAK,CAACoC;QAAM,CACnB,CAAC,EACF,IAAAnB,MAAA,CAAAC,aAAA,gBAAQlB,KAAK,CAACsB,KAAa,CACpB,CACR;QACDe,QAAQ,EAAGA,CAAA,KAAM;UAChB,IAAK,CAAEP,OAAO,EAAG;YAChB;YACA,MAAM7B,gBAAgB,GACrBD,KAAK,CAACd,UAAU,CAAEV,IAAI,CAAE;YACzBwC,iCAAiC,CAChC,IAAAsB,mBAAW,EAAEtC,KAAK,CAACxB,IAAK,CAAC,EACzByB,gBACD,CAAC;YACD;UACD;;UAEA;UACAQ,WAAW,CACVd,oBAAoB,CACnBK,KAAK,CAACxB,IAAI,CACV,EACD,KACD,CAAC;QACF;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAAC,IAAA+D,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc;EACdC,IAAI,EAAEnE,qBAAqB;EAC3BoE,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
|
|
1
|
+
{"version":3,"names":["_i18n","require","_element","_components","_blocks","_data","_components2","_store","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","metadata","ignoredHookedBlocks","blockTypes","useSelect","select","blocksStore","getBlockTypes","hookedBlocksForCurrentBlock","useMemo","filter","blockName","blockHooks","includes","blockIndex","rootClientId","innerBlocksLength","getBlocks","getBlockIndex","getBlockRootClientId","blockEditorStore","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","undefined","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","useDispatch","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","_react","createElement","InspectorControls","PanelBody","className","title","__","initialOpen","keys","map","vendor","Fragment","key","checked","ToggleControl","label","__experimentalHStack","justify","BlockIcon","icon","onChange","createBlock","_default","exports","default","edit","attributeKeys","hasSupport"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControlPure( {\n\tname,\n\tclientId,\n\tmetadata: { ignoredHookedBlocks = [] } = {},\n} ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\t// A hooked block added via a filter will not be exposed through a block\n\t// type's `blockHooks` property; however, if the containing layout has been\n\t// modified, it will be present in the anchor block's `ignoredHookedBlocks`\n\t// metadata.\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { name: blockName, blockHooks } ) =>\n\t\t\t\t\t( blockHooks && name in blockHooks ) ||\n\t\t\t\t\tignoredHookedBlocks.includes( blockName )\n\t\t\t),\n\t\t[ blockTypes, name, ignoredHookedBlocks ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\tinnerBlocksLength: getBlocks( clientId )?.length,\n\t\t\t\trootClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to set the toggle to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition = block?.blockHooks?.[ name ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlocks( rootClientId );\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlocks( clientId );\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase undefined:\n\t\t\t\t\t\t\t// If we haven't found a blockHooks field with a relative position for the hooked\n\t\t\t\t\t\t\t// block, it means that it was added by a filter. In this case, we look for the block\n\t\t\t\t\t\t\t// both among the current block's siblings and its children.\n\t\t\t\t\t\t\tcandidates = [\n\t\t\t\t\t\t\t\t...getBlocks( rootClientId ),\n\t\t\t\t\t\t\t\t...getBlocks( clientId ),\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( candidate ) => candidate.name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// we set the toggle to disabled.\n\t\t\t\t\treturn clientIds;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[ hookedBlocksForCurrentBlock, name, clientId, rootClientId ]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\tif ( ! hookedBlocksForCurrentBlock.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tclientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase undefined:\n\t\t\t\t// If we do not know the relative position, it is because the block was\n\t\t\t\t// added via a filter. In this case, we default to inserting it after the\n\t\t\t\t// current block.\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\tblockIndex + 1,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t<p className=\"block-editor-hooks__block-hooks-helptext\">\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Manage the inclusion of blocks added automatically by plugins.'\n\t\t\t\t\t) }\n\t\t\t\t</p>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[ name ];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock(\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport default {\n\tedit: BlockHooksControlPure,\n\tattributeKeys: [ 'metadata' ],\n\thasSupport() {\n\t\treturn true;\n\t},\n};\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAKA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AAjBA;AACA;AACA;;AAWA;AACA;AACA;;AAIA,MAAMO,YAAY,GAAG,CAAC,CAAC;AAEvB,SAASC,qBAAqBA,CAAE;EAC/BC,IAAI;EACJC,QAAQ;EACRC,QAAQ,EAAE;IAAEC,mBAAmB,GAAG;EAAG,CAAC,GAAG,CAAC;AAC3C,CAAC,EAAG;EACH,MAAMC,UAAU,GAAG,IAAAC,eAAS,EACzBC,MAAM,IAAMA,MAAM,CAAEC,aAAY,CAAC,CAACC,aAAa,CAAC,CAAC,EACnD,EACD,CAAC;;EAED;EACA;EACA;EACA;EACA,MAAMC,2BAA2B,GAAG,IAAAC,gBAAO,EAC1C,MACCN,UAAU,EAAEO,MAAM,CACjB,CAAE;IAAEX,IAAI,EAAEY,SAAS;IAAEC;EAAW,CAAC,KAC9BA,UAAU,IAAIb,IAAI,IAAIa,UAAU,IAClCV,mBAAmB,CAACW,QAAQ,CAAEF,SAAU,CAC1C,CAAC,EACF,CA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D,OAAO,EAAGA,OAAS;QACnBD,GAAG,EAAG9B,KAAK,CAACuB,KAAO;QACnBU,KAAK,EACJ,IAAAf,MAAA,CAAAC,aAAA,EAACtD,WAAA,CAAAqE,oBAAM;UAACC,OAAO,EAAC;QAAY,GAC3B,IAAAjB,MAAA,CAAAC,aAAA,EAACnD,YAAA,CAAAoE,SAAS;UACTC,IAAI,EAAGrC,KAAK,CAACqC;QAAM,CACnB,CAAC,EACF,IAAAnB,MAAA,CAAAC,aAAA,gBAAQnB,KAAK,CAACuB,KAAa,CACpB,CACR;QACDe,QAAQ,EAAGA,CAAA,KAAM;UAChB,IAAK,CAAEP,OAAO,EAAG;YAChB;YACA,MAAM9B,gBAAgB,GACrBD,KAAK,CAACf,UAAU,CAAEb,IAAI,CAAE;YACzB6C,iCAAiC,CAChC,IAAAsB,mBAAW,EAAEvC,KAAK,CAAC5B,IAAK,CAAC,EACzB6B,gBACD,CAAC;YACD;UACD;;UAEA;UACAS,WAAW,CACVf,oBAAoB,CACnBK,KAAK,CAAC5B,IAAI,CACV,EACD,KACD,CAAC;QACF;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAAC,IAAAoE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc;EACdC,IAAI,EAAExE,qBAAqB;EAC3ByE,aAAa,EAAE,CAAE,UAAU,CAAE;EAC7BC,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.canBindAttribute = canBindAttribute;
|
|
7
|
+
exports.canBindBlock = canBindBlock;
|
|
7
8
|
var _react = require("react");
|
|
8
9
|
var _blocks = require("@wordpress/blocks");
|
|
9
10
|
var _compose = require("@wordpress/compose");
|
|
10
11
|
var _data = require("@wordpress/data");
|
|
12
|
+
var _element = require("@wordpress/element");
|
|
11
13
|
var _hooks = require("@wordpress/hooks");
|
|
12
|
-
var
|
|
13
|
-
var _context = require("../components/block-edit/context");
|
|
14
|
+
var _richText = require("@wordpress/rich-text");
|
|
14
15
|
var _lockUnlock = require("../lock-unlock");
|
|
15
16
|
/**
|
|
16
17
|
* WordPress dependencies
|
|
@@ -30,68 +31,192 @@ var _lockUnlock = require("../lock-unlock");
|
|
|
30
31
|
* @return {WPHigherOrderComponent} Higher-order component.
|
|
31
32
|
*/
|
|
32
33
|
|
|
33
|
-
const BLOCK_BINDINGS_ALLOWED_BLOCKS =
|
|
34
|
+
const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
|
|
34
35
|
'core/paragraph': ['content'],
|
|
35
36
|
'core/heading': ['content'],
|
|
36
37
|
'core/image': ['url', 'title', 'alt'],
|
|
37
38
|
'core/button': ['url', 'text', 'linkTarget']
|
|
38
39
|
};
|
|
39
|
-
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Based on the given block name,
|
|
43
|
+
* check if it is possible to bind the block.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} blockName - The block name.
|
|
46
|
+
* @return {boolean} Whether it is possible to bind the block to sources.
|
|
47
|
+
*/
|
|
48
|
+
function canBindBlock(blockName) {
|
|
49
|
+
return blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Based on the given block name and attribute name,
|
|
54
|
+
* check if it is possible to bind the block attribute.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} blockName - The block name.
|
|
57
|
+
* @param {string} attributeName - The attribute name.
|
|
58
|
+
* @return {boolean} Whether it is possible to bind the block attribute.
|
|
59
|
+
*/
|
|
60
|
+
function canBindAttribute(blockName, attributeName) {
|
|
61
|
+
return canBindBlock(blockName) && BLOCK_BINDINGS_ALLOWED_BLOCKS[blockName].includes(attributeName);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* This component is responsible for detecting and
|
|
66
|
+
* propagating data changes from the source to the block.
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} props - The component props.
|
|
69
|
+
* @param {string} props.attrName - The attribute name.
|
|
70
|
+
* @param {Object} props.blockProps - The block props with bound attribute.
|
|
71
|
+
* @param {Object} props.source - Source handler.
|
|
72
|
+
* @param {Object} props.args - The arguments to pass to the source.
|
|
73
|
+
* @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
|
|
74
|
+
* @return {null} Data-handling component. Render nothing.
|
|
75
|
+
*/
|
|
76
|
+
const BindingConnector = ({
|
|
77
|
+
args,
|
|
78
|
+
attrName,
|
|
79
|
+
blockProps,
|
|
80
|
+
source,
|
|
81
|
+
onPropValueChange
|
|
82
|
+
}) => {
|
|
40
83
|
const {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = (
|
|
44
|
-
const blockBindingsSources = (0, _lockUnlock.unlock)((0, _data.useSelect)(_blocks.store)).getAllBlockBindingsSources();
|
|
84
|
+
placeholder,
|
|
85
|
+
value: propValue
|
|
86
|
+
} = source.useSource(blockProps, args);
|
|
45
87
|
const {
|
|
46
|
-
|
|
47
|
-
} =
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (htmlAttribute === 'src' || htmlAttribute === 'href') {
|
|
63
|
-
updatedAttributes[attributeName] = null;
|
|
64
|
-
} else {
|
|
65
|
-
updatedAttributes[attributeName] = placeholder;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (metaValue) {
|
|
69
|
-
updatedAttributes[attributeName] = metaValue;
|
|
70
|
-
}
|
|
88
|
+
name: blockName
|
|
89
|
+
} = blockProps;
|
|
90
|
+
const attrValue = blockProps.attributes[attrName];
|
|
91
|
+
const updateBoundAttibute = (0, _element.useCallback)((newAttrValue, prevAttrValue) => {
|
|
92
|
+
/*
|
|
93
|
+
* If the attribute is a RichTextData instance,
|
|
94
|
+
* (core/paragraph, core/heading, core/button, etc.)
|
|
95
|
+
* compare its HTML representation with the new value.
|
|
96
|
+
*
|
|
97
|
+
* To do: it looks like a workaround.
|
|
98
|
+
* Consider improving the attribute and metadata fields types.
|
|
99
|
+
*/
|
|
100
|
+
if (prevAttrValue instanceof _richText.RichTextData) {
|
|
101
|
+
// Bail early if the Rich Text value is the same.
|
|
102
|
+
if (prevAttrValue.toHTMLString() === newAttrValue) {
|
|
103
|
+
return;
|
|
71
104
|
}
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* To preserve the value type,
|
|
108
|
+
* convert the new value to a RichTextData instance.
|
|
109
|
+
*/
|
|
110
|
+
newAttrValue = _richText.RichTextData.fromHTMLString(newAttrValue);
|
|
111
|
+
}
|
|
112
|
+
if (prevAttrValue === newAttrValue) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
onPropValueChange({
|
|
116
|
+
[attrName]: newAttrValue
|
|
72
117
|
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
118
|
+
}, [attrName, onPropValueChange]);
|
|
119
|
+
(0, _element.useLayoutEffect)(() => {
|
|
120
|
+
if (typeof propValue !== 'undefined') {
|
|
121
|
+
updateBoundAttibute(propValue, attrValue);
|
|
122
|
+
} else if (placeholder) {
|
|
123
|
+
/*
|
|
124
|
+
* Placeholder fallback.
|
|
125
|
+
* If the attribute is `src` or `href`,
|
|
126
|
+
* a placeholder can't be used because it is not a valid url.
|
|
127
|
+
* Adding this workaround until
|
|
128
|
+
* attributes and metadata fields types are improved and include `url`.
|
|
129
|
+
*/
|
|
130
|
+
const htmlAttribute = (0, _blocks.getBlockType)(blockName).attributes[attrName].attribute;
|
|
131
|
+
if (htmlAttribute === 'src' || htmlAttribute === 'href') {
|
|
132
|
+
updateBoundAttibute(null);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
updateBoundAttibute(placeholder);
|
|
136
|
+
}
|
|
137
|
+
}, [updateBoundAttibute, propValue, attrValue, placeholder, blockName, attrName]);
|
|
138
|
+
return null;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* BlockBindingBridge acts like a component wrapper
|
|
143
|
+
* that connects the bound attributes of a block
|
|
144
|
+
* to the source handlers.
|
|
145
|
+
* For this, it creates a BindingConnector for each bound attribute.
|
|
146
|
+
*
|
|
147
|
+
* @param {Object} props - The component props.
|
|
148
|
+
* @param {Object} props.blockProps - The BlockEdit props object.
|
|
149
|
+
* @param {Object} props.bindings - The block bindings settings.
|
|
150
|
+
* @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
|
|
151
|
+
* @return {null} Data-handling component. Render nothing.
|
|
152
|
+
*/
|
|
153
|
+
function BlockBindingBridge({
|
|
154
|
+
blockProps,
|
|
155
|
+
bindings,
|
|
156
|
+
onPropValueChange
|
|
157
|
+
}) {
|
|
158
|
+
const blockBindingsSources = (0, _lockUnlock.unlock)((0, _data.useSelect)(_blocks.store)).getAllBlockBindingsSources();
|
|
159
|
+
return (0, _react.createElement)(_react.Fragment, null, Object.entries(bindings).map(([attrName, boundAttribute]) => {
|
|
160
|
+
// Bail early if the block doesn't have a valid source handler.
|
|
161
|
+
const source = blockBindingsSources[boundAttribute.source];
|
|
162
|
+
if (!source?.useSource) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
return (0, _react.createElement)(BindingConnector, {
|
|
166
|
+
key: attrName,
|
|
167
|
+
attrName: attrName,
|
|
168
|
+
source: source,
|
|
169
|
+
blockProps: blockProps,
|
|
170
|
+
args: boundAttribute.args,
|
|
171
|
+
onPropValueChange: onPropValueChange
|
|
172
|
+
});
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
const withBlockBindingSupport = (0, _compose.createHigherOrderComponent)(BlockEdit => props => {
|
|
176
|
+
/*
|
|
177
|
+
* Collect and update the bound attributes
|
|
178
|
+
* in a separate state.
|
|
179
|
+
*/
|
|
180
|
+
const [boundAttributes, setBoundAttributes] = (0, _element.useState)({});
|
|
181
|
+
const updateBoundAttributes = (0, _element.useCallback)(newAttributes => setBoundAttributes(prev => ({
|
|
182
|
+
...prev,
|
|
183
|
+
...newAttributes
|
|
184
|
+
})), []);
|
|
185
|
+
|
|
186
|
+
/*
|
|
187
|
+
* Create binding object filtering
|
|
188
|
+
* only the attributes that can be bound.
|
|
189
|
+
*/
|
|
190
|
+
const bindings = Object.fromEntries(Object.entries(props.attributes.metadata?.bindings || {}).filter(([attrName]) => canBindAttribute(props.name, attrName)));
|
|
191
|
+
return (0, _react.createElement)(_react.Fragment, null, Object.keys(bindings).length > 0 && (0, _react.createElement)(BlockBindingBridge, {
|
|
192
|
+
blockProps: props,
|
|
193
|
+
bindings: bindings,
|
|
194
|
+
onPropValueChange: updateBoundAttributes
|
|
195
|
+
}), (0, _react.createElement)(BlockEdit, {
|
|
76
196
|
...props,
|
|
77
|
-
attributes:
|
|
78
|
-
|
|
79
|
-
|
|
197
|
+
attributes: {
|
|
198
|
+
...props.attributes,
|
|
199
|
+
...boundAttributes
|
|
200
|
+
}
|
|
201
|
+
}));
|
|
202
|
+
}, 'withBlockBindingSupport');
|
|
80
203
|
|
|
81
204
|
/**
|
|
82
205
|
* Filters a registered block's settings to enhance a block's `edit` component
|
|
83
206
|
* to upgrade bound attributes.
|
|
84
207
|
*
|
|
85
|
-
* @param {WPBlockSettings} settings Registered block settings.
|
|
86
|
-
*
|
|
208
|
+
* @param {WPBlockSettings} settings - Registered block settings.
|
|
209
|
+
* @param {string} name - Block name.
|
|
87
210
|
* @return {WPBlockSettings} Filtered block settings.
|
|
88
211
|
*/
|
|
89
|
-
function shimAttributeSource(settings) {
|
|
90
|
-
if (!(
|
|
212
|
+
function shimAttributeSource(settings, name) {
|
|
213
|
+
if (!canBindBlock(name)) {
|
|
91
214
|
return settings;
|
|
92
215
|
}
|
|
93
|
-
|
|
94
|
-
|
|
216
|
+
return {
|
|
217
|
+
...settings,
|
|
218
|
+
edit: withBlockBindingSupport(settings.edit)
|
|
219
|
+
};
|
|
95
220
|
}
|
|
96
221
|
(0, _hooks.addFilter)('blocks.registerBlockType', 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', shimAttributeSource);
|
|
97
222
|
//# sourceMappingURL=use-bindings-attributes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_blocks","require","_compose","_data","_hooks","_store","_context","_lockUnlock","BLOCK_BINDINGS_ALLOWED_BLOCKS","exports","createEditFunctionWithBindingsAttribute","createHigherOrderComponent","BlockEdit","props","clientId","name","blockName","useBlockEditContext","blockBindingsSources","unlock","useSelect","blocksStore","getAllBlockBindingsSources","getBlockAttributes","blockEditorStore","updatedAttributes","metadata","bindings","Object","entries","forEach","attributeName","settings","source","useSource","placeholder","useValue","metaValue","args","htmlAttribute","getBlockType","attributes","attribute","_react","createElement","key","shimAttributeSource","edit","addFilter"],"sources":["@wordpress/block-editor/src/hooks/use-bindings-attributes.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockType, store as blocksStore } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { addFilter } from '@wordpress/hooks';\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { useBlockEditContext } from '../components/block-edit/context';\nimport { unlock } from '../lock-unlock';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Given a binding of block attributes, returns a higher order component that\n * overrides its `attributes` and `setAttributes` props to sync any changes needed.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\n\nexport const BLOCK_BINDINGS_ALLOWED_BLOCKS = {\n\t'core/paragraph': [ 'content' ],\n\t'core/heading': [ 'content' ],\n\t'core/image': [ 'url', 'title', 'alt' ],\n\t'core/button': [ 'url', 'text', 'linkTarget' ],\n};\n\nconst createEditFunctionWithBindingsAttribute = () =>\n\tcreateHigherOrderComponent(\n\t\t( BlockEdit ) => ( props ) => {\n\t\t\tconst { clientId, name: blockName } = useBlockEditContext();\n\t\t\tconst blockBindingsSources = unlock(\n\t\t\t\tuseSelect( blocksStore )\n\t\t\t).getAllBlockBindingsSources();\n\t\t\tconst { getBlockAttributes } = useSelect( blockEditorStore );\n\n\t\t\tconst updatedAttributes = getBlockAttributes( clientId );\n\t\t\tif ( updatedAttributes?.metadata?.bindings ) {\n\t\t\t\tObject.entries( updatedAttributes.metadata.bindings ).forEach(\n\t\t\t\t\t( [ attributeName, settings ] ) => {\n\t\t\t\t\t\tconst source = blockBindingsSources[ settings.source ];\n\n\t\t\t\t\t\tif ( source && source.useSource ) {\n\t\t\t\t\t\t\t// Second argument (`updateMetaValue`) will be used to update the value in the future.\n\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\tplaceholder,\n\t\t\t\t\t\t\t\tuseValue: [ metaValue = null ] = [],\n\t\t\t\t\t\t\t} = source.useSource( props, settings.args );\n\n\t\t\t\t\t\t\tif ( placeholder && ! metaValue ) {\n\t\t\t\t\t\t\t\t// If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.\n\t\t\t\t\t\t\t\t// Adding this workaround until attributes and metadata fields types are improved and include `url`.\n\t\t\t\t\t\t\t\tconst htmlAttribute =\n\t\t\t\t\t\t\t\t\tgetBlockType( blockName ).attributes[\n\t\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t\t].attribute;\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\thtmlAttribute === 'src' ||\n\t\t\t\t\t\t\t\t\thtmlAttribute === 'href'\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tupdatedAttributes[ attributeName ] = null;\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tupdatedAttributes[ attributeName ] =\n\t\t\t\t\t\t\t\t\t\tplaceholder;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif ( metaValue ) {\n\t\t\t\t\t\t\t\tupdatedAttributes[ attributeName ] = metaValue;\n\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\treturn (\n\t\t\t\t<BlockEdit\n\t\t\t\t\tkey=\"edit\"\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tattributes={ updatedAttributes }\n\t\t\t\t/>\n\t\t\t);\n\t\t},\n\t\t'useBoundAttributes'\n\t);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade bound attributes.\n *\n * @param {WPBlockSettings} settings Registered block settings.\n *\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings ) {\n\tif ( ! ( settings.name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {\n\t\treturn settings;\n\t}\n\tsettings.edit = createEditFunctionWithBindingsAttribute()( settings.edit );\n\n\treturn settings;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n"],"mappings":";;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAIA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAZA;AACA;AACA;;AAKA;AACA;AACA;;AAKA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMO,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG;EAC5C,gBAAgB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nCV,aAAa,CACb,CAACW,SAAS;UACZ,IACCH,aAAa,KAAK,KAAK,IACvBA,aAAa,KAAK,MAAM,EACvB;YACDd,iBAAiB,CAAEM,aAAa,CAAE,GAAG,IAAI;UAC1C,CAAC,MAAM;YACNN,iBAAiB,CAAEM,aAAa,CAAE,GACjCI,WAAW;UACb;QACD;QAEA,IAAKE,SAAS,EAAG;UAChBZ,iBAAiB,CAAEM,aAAa,CAAE,GAAGM,SAAS;QAC/C;MACD;IACD,CACD,CAAC;EACF;EAEA,OACC,IAAAM,MAAA,CAAAC,aAAA,EAAChC,SAAS;IACTiC,GAAG,EAAC,MAAM;IAAA,GACLhC,KAAK;IACV4B,UAAU,EAAGhB;EAAmB,CAChC,CAAC;AAEJ,CAAC,EACD,oBACD,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASqB,mBAAmBA,CAAEd,QAAQ,EAAG;EACxC,IAAK,EAAIA,QAAQ,CAACjB,IAAI,IAAIP,6BAA6B,CAAE,EAAG;IAC3D,OAAOwB,QAAQ;EAChB;EACAA,QAAQ,CAACe,IAAI,GAAGrC,uCAAuC,CAAC,CAAC,CAAEsB,QAAQ,CAACe,IAAK,CAAC;EAE1E,OAAOf,QAAQ;AAChB;AAEA,IAAAgB,gBAAS,EACR,0BAA0B,EAC1B,0EAA0E,EAC1EF,mBACD,CAAC"}
|
|
1
|
+
{"version":3,"names":["_blocks","require","_compose","_data","_element","_hooks","_richText","_lockUnlock","BLOCK_BINDINGS_ALLOWED_BLOCKS","canBindBlock","blockName","canBindAttribute","attributeName","includes","BindingConnector","args","attrName","blockProps","source","onPropValueChange","placeholder","value","propValue","useSource","name","attrValue","attributes","updateBoundAttibute","useCallback","newAttrValue","prevAttrValue","RichTextData","toHTMLString","fromHTMLString","useLayoutEffect","htmlAttribute","getBlockType","attribute","BlockBindingBridge","bindings","blockBindingsSources","unlock","useSelect","blocksStore","getAllBlockBindingsSources","_react","createElement","Fragment","Object","entries","map","boundAttribute","key","withBlockBindingSupport","createHigherOrderComponent","BlockEdit","props","boundAttributes","setBoundAttributes","useState","updateBoundAttributes","newAttributes","prev","fromEntries","metadata","filter","keys","length","shimAttributeSource","settings","edit","addFilter"],"sources":["@wordpress/block-editor/src/hooks/use-bindings-attributes.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockType, store as blocksStore } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useLayoutEffect, useCallback, useState } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\nimport { RichTextData } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Given a binding of block attributes, returns a higher order component that\n * overrides its `attributes` and `setAttributes` props to sync any changes needed.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\n\nconst BLOCK_BINDINGS_ALLOWED_BLOCKS = {\n\t'core/paragraph': [ 'content' ],\n\t'core/heading': [ 'content' ],\n\t'core/image': [ 'url', 'title', 'alt' ],\n\t'core/button': [ 'url', 'text', 'linkTarget' ],\n};\n\n/**\n * Based on the given block name,\n * check if it is possible to bind the block.\n *\n * @param {string} blockName - The block name.\n * @return {boolean} Whether it is possible to bind the block to sources.\n */\nexport function canBindBlock( blockName ) {\n\treturn blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;\n}\n\n/**\n * Based on the given block name and attribute name,\n * check if it is possible to bind the block attribute.\n *\n * @param {string} blockName - The block name.\n * @param {string} attributeName - The attribute name.\n * @return {boolean} Whether it is possible to bind the block attribute.\n */\nexport function canBindAttribute( blockName, attributeName ) {\n\treturn (\n\t\tcanBindBlock( blockName ) &&\n\t\tBLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ].includes( attributeName )\n\t);\n}\n\n/**\n * This component is responsible for detecting and\n * propagating data changes from the source to the block.\n *\n * @param {Object} props - The component props.\n * @param {string} props.attrName - The attribute name.\n * @param {Object} props.blockProps - The block props with bound attribute.\n * @param {Object} props.source - Source handler.\n * @param {Object} props.args - The arguments to pass to the source.\n * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.\n * @return {null} Data-handling component. Render nothing.\n */\nconst BindingConnector = ( {\n\targs,\n\tattrName,\n\tblockProps,\n\tsource,\n\tonPropValueChange,\n} ) => {\n\tconst { placeholder, value: propValue } = source.useSource(\n\t\tblockProps,\n\t\targs\n\t);\n\n\tconst { name: blockName } = blockProps;\n\tconst attrValue = blockProps.attributes[ attrName ];\n\n\tconst updateBoundAttibute = useCallback(\n\t\t( newAttrValue, prevAttrValue ) => {\n\t\t\t/*\n\t\t\t * If the attribute is a RichTextData instance,\n\t\t\t * (core/paragraph, core/heading, core/button, etc.)\n\t\t\t * compare its HTML representation with the new value.\n\t\t\t *\n\t\t\t * To do: it looks like a workaround.\n\t\t\t * Consider improving the attribute and metadata fields types.\n\t\t\t */\n\t\t\tif ( prevAttrValue instanceof RichTextData ) {\n\t\t\t\t// Bail early if the Rich Text value is the same.\n\t\t\t\tif ( prevAttrValue.toHTMLString() === newAttrValue ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t/*\n\t\t\t\t * To preserve the value type,\n\t\t\t\t * convert the new value to a RichTextData instance.\n\t\t\t\t */\n\t\t\t\tnewAttrValue = RichTextData.fromHTMLString( newAttrValue );\n\t\t\t}\n\n\t\t\tif ( prevAttrValue === newAttrValue ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tonPropValueChange( { [ attrName ]: newAttrValue } );\n\t\t},\n\t\t[ attrName, onPropValueChange ]\n\t);\n\n\tuseLayoutEffect( () => {\n\t\tif ( typeof propValue !== 'undefined' ) {\n\t\t\tupdateBoundAttibute( propValue, attrValue );\n\t\t} else if ( placeholder ) {\n\t\t\t/*\n\t\t\t * Placeholder fallback.\n\t\t\t * If the attribute is `src` or `href`,\n\t\t\t * a placeholder can't be used because it is not a valid url.\n\t\t\t * Adding this workaround until\n\t\t\t * attributes and metadata fields types are improved and include `url`.\n\t\t\t */\n\t\t\tconst htmlAttribute =\n\t\t\t\tgetBlockType( blockName ).attributes[ attrName ].attribute;\n\n\t\t\tif ( htmlAttribute === 'src' || htmlAttribute === 'href' ) {\n\t\t\t\tupdateBoundAttibute( null );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tupdateBoundAttibute( placeholder );\n\t\t}\n\t}, [\n\t\tupdateBoundAttibute,\n\t\tpropValue,\n\t\tattrValue,\n\t\tplaceholder,\n\t\tblockName,\n\t\tattrName,\n\t] );\n\n\treturn null;\n};\n\n/**\n * BlockBindingBridge acts like a component wrapper\n * that connects the bound attributes of a block\n * to the source handlers.\n * For this, it creates a BindingConnector for each bound attribute.\n *\n * @param {Object} props - The component props.\n * @param {Object} props.blockProps - The BlockEdit props object.\n * @param {Object} props.bindings - The block bindings settings.\n * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.\n * @return {null} Data-handling component. Render nothing.\n */\nfunction BlockBindingBridge( { blockProps, bindings, onPropValueChange } ) {\n\tconst blockBindingsSources = unlock(\n\t\tuseSelect( blocksStore )\n\t).getAllBlockBindingsSources();\n\n\treturn (\n\t\t<>\n\t\t\t{ Object.entries( bindings ).map(\n\t\t\t\t( [ attrName, boundAttribute ] ) => {\n\t\t\t\t\t// Bail early if the block doesn't have a valid source handler.\n\t\t\t\t\tconst source =\n\t\t\t\t\t\tblockBindingsSources[ boundAttribute.source ];\n\t\t\t\t\tif ( ! source?.useSource ) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<BindingConnector\n\t\t\t\t\t\t\tkey={ attrName }\n\t\t\t\t\t\t\tattrName={ attrName }\n\t\t\t\t\t\t\tsource={ source }\n\t\t\t\t\t\t\tblockProps={ blockProps }\n\t\t\t\t\t\t\targs={ boundAttribute.args }\n\t\t\t\t\t\t\tonPropValueChange={ onPropValueChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nconst withBlockBindingSupport = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\t/*\n\t\t * Collect and update the bound attributes\n\t\t * in a separate state.\n\t\t */\n\t\tconst [ boundAttributes, setBoundAttributes ] = useState( {} );\n\t\tconst updateBoundAttributes = useCallback(\n\t\t\t( newAttributes ) =>\n\t\t\t\tsetBoundAttributes( ( prev ) => ( {\n\t\t\t\t\t...prev,\n\t\t\t\t\t...newAttributes,\n\t\t\t\t} ) ),\n\t\t\t[]\n\t\t);\n\n\t\t/*\n\t\t * Create binding object filtering\n\t\t * only the attributes that can be bound.\n\t\t */\n\t\tconst bindings = Object.fromEntries(\n\t\t\tObject.entries( props.attributes.metadata?.bindings || {} ).filter(\n\t\t\t\t( [ attrName ] ) => canBindAttribute( props.name, attrName )\n\t\t\t)\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ Object.keys( bindings ).length > 0 && (\n\t\t\t\t\t<BlockBindingBridge\n\t\t\t\t\t\tblockProps={ props }\n\t\t\t\t\t\tbindings={ bindings }\n\t\t\t\t\t\tonPropValueChange={ updateBoundAttributes }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\n\t\t\t\t<BlockEdit\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tattributes={ { ...props.attributes, ...boundAttributes } }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n\t'withBlockBindingSupport'\n);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade bound attributes.\n *\n * @param {WPBlockSettings} settings - Registered block settings.\n * @param {string} name - Block name.\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings, name ) {\n\tif ( ! canBindBlock( name ) ) {\n\t\treturn settings;\n\t}\n\n\treturn {\n\t\t...settings,\n\t\tedit: withBlockBindingSupport( settings.edit ),\n\t};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n"],"mappings":";;;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAKA,IAAAM,WAAA,GAAAN,OAAA;AAbA;AACA;AACA;;AAQA;AACA;AACA;;AAGA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMO,6BAA6B,GAAG;EACrC,gBAAgB,EAAE,CAAE,SAAS,CAAE;EAC/B,cAAc,EAAE,CAAE,SAAS,CAAE;EAC7B,YAAY,EAAE,CAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAE;EACvC,aAAa,EAAE,CAAE,KAAK,EAAE,MAAM,EAAE,YAAY;AAC7C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAAEC,SAAS,EAAG;EACzC,OAAOA,SAAS,IAAIF,6BAA6B;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,gBAAgBA,CAAED,SAAS,EAAEE,aAAa,EAAG;EAC5D,OACCH,YAAY,CAAEC,SAAU,CAAC,IACzBF,6BAA6B,CAAEE,SAAS,CAAE,CAACG,QAAQ,CAAED,aAAc,CAAC;AAEtE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,gBAAgB,GAAGA,CAAE;EAC1BC,IAAI;EACJC,QAAQ;EACRC,UAAU;EACVC,MAAM;EACNC;AACD,CAAC,KAAM;EACN,MAAM;IAAEC,WAAW;IAAEC,KAAK,EAAEC;E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28
|
var _utils2 = require("./components/duotone/utils");
|
|
29
29
|
var _useFlashEditableBlocks = require("./components/use-flash-editable-blocks");
|
|
30
30
|
var _privateKeys = require("./store/private-keys");
|
|
31
|
+
var _utils3 = require("./components/writing-flow/utils");
|
|
31
32
|
var _richText = require("./components/rich-text/");
|
|
32
33
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
33
34
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -65,6 +66,7 @@ const privateApis = exports.privateApis = {};
|
|
|
65
66
|
usesContextKey: _formatEdit.usesContextKey,
|
|
66
67
|
useFlashEditableBlocks: _useFlashEditableBlocks.useFlashEditableBlocks,
|
|
67
68
|
selectBlockPatternsKey: _privateKeys.selectBlockPatternsKey,
|
|
69
|
+
requiresWrapperOnCopy: _utils3.requiresWrapperOnCopy,
|
|
68
70
|
PrivateRichText: _richText.PrivateRichText
|
|
69
71
|
});
|
|
70
72
|
//# sourceMappingURL=private-apis.js.map
|