@wordpress/block-editor 12.19.4 → 12.19.6

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.
Files changed (100) hide show
  1. package/build/components/block-actions/index.js +45 -32
  2. package/build/components/block-actions/index.js.map +1 -1
  3. package/build/components/block-bindings-toolbar-indicator/index.js +25 -0
  4. package/build/components/block-bindings-toolbar-indicator/index.js.map +1 -0
  5. package/build/components/block-list/use-block-props/index.js +8 -1
  6. package/build/components/block-list/use-block-props/index.js.map +1 -1
  7. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -3
  8. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  9. package/build/components/block-settings-menu/block-settings-dropdown.js +12 -10
  10. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  11. package/build/components/block-toolbar/index.js +14 -5
  12. package/build/components/block-toolbar/index.js.map +1 -1
  13. package/build/components/global-styles/use-global-styles-output.js +13 -13
  14. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  15. package/build/components/list-view/block-select-button.js +10 -2
  16. package/build/components/list-view/block-select-button.js.map +1 -1
  17. package/build/components/list-view/use-clipboard-handler.js +2 -1
  18. package/build/components/list-view/use-clipboard-handler.js.map +1 -1
  19. package/build/components/rich-text/index.js +1 -1
  20. package/build/components/rich-text/index.js.map +1 -1
  21. package/build/components/url-popover/index.js +3 -3
  22. package/build/components/url-popover/index.js.map +1 -1
  23. package/build/components/use-moving-animation/index.js +4 -0
  24. package/build/components/use-moving-animation/index.js.map +1 -1
  25. package/build/components/writing-flow/use-clipboard-handler.js +2 -1
  26. package/build/components/writing-flow/use-clipboard-handler.js.map +1 -1
  27. package/build/components/writing-flow/utils.js +23 -6
  28. package/build/components/writing-flow/utils.js.map +1 -1
  29. package/build/hooks/block-hooks.js +26 -2
  30. package/build/hooks/block-hooks.js.map +1 -1
  31. package/build/hooks/use-bindings-attributes.js +171 -46
  32. package/build/hooks/use-bindings-attributes.js.map +1 -1
  33. package/build/private-apis.js +2 -0
  34. package/build/private-apis.js.map +1 -1
  35. package/build/store/actions.js +40 -6
  36. package/build/store/actions.js.map +1 -1
  37. package/build-module/components/block-actions/index.js +45 -32
  38. package/build-module/components/block-actions/index.js.map +1 -1
  39. package/build-module/components/block-bindings-toolbar-indicator/index.js +18 -0
  40. package/build-module/components/block-bindings-toolbar-indicator/index.js.map +1 -0
  41. package/build-module/components/block-list/use-block-props/index.js +9 -2
  42. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  43. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -3
  44. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  45. package/build-module/components/block-settings-menu/block-settings-dropdown.js +12 -10
  46. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  47. package/build-module/components/block-toolbar/index.js +14 -5
  48. package/build-module/components/block-toolbar/index.js.map +1 -1
  49. package/build-module/components/global-styles/use-global-styles-output.js +13 -13
  50. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  51. package/build-module/components/list-view/block-select-button.js +11 -3
  52. package/build-module/components/list-view/block-select-button.js.map +1 -1
  53. package/build-module/components/list-view/use-clipboard-handler.js +3 -2
  54. package/build-module/components/list-view/use-clipboard-handler.js.map +1 -1
  55. package/build-module/components/rich-text/index.js +2 -2
  56. package/build-module/components/rich-text/index.js.map +1 -1
  57. package/build-module/components/url-popover/index.js +3 -3
  58. package/build-module/components/url-popover/index.js.map +1 -1
  59. package/build-module/components/use-moving-animation/index.js +4 -0
  60. package/build-module/components/use-moving-animation/index.js.map +1 -1
  61. package/build-module/components/writing-flow/use-clipboard-handler.js +3 -2
  62. package/build-module/components/writing-flow/use-clipboard-handler.js.map +1 -1
  63. package/build-module/components/writing-flow/utils.js +22 -7
  64. package/build-module/components/writing-flow/utils.js.map +1 -1
  65. package/build-module/hooks/block-hooks.js +26 -2
  66. package/build-module/hooks/block-hooks.js.map +1 -1
  67. package/build-module/hooks/use-bindings-attributes.js +171 -46
  68. package/build-module/hooks/use-bindings-attributes.js.map +1 -1
  69. package/build-module/private-apis.js +2 -0
  70. package/build-module/private-apis.js.map +1 -1
  71. package/build-module/store/actions.js +40 -6
  72. package/build-module/store/actions.js.map +1 -1
  73. package/build-style/content-rtl.css +1 -0
  74. package/build-style/content.css +1 -0
  75. package/build-style/default-editor-styles-rtl.css +1 -0
  76. package/build-style/default-editor-styles.css +1 -0
  77. package/build-style/style-rtl.css +23 -0
  78. package/build-style/style.css +23 -0
  79. package/package.json +8 -8
  80. package/src/components/block-actions/index.js +57 -47
  81. package/src/components/block-bindings-toolbar-indicator/index.js +20 -0
  82. package/src/components/block-bindings-toolbar-indicator/style.scss +14 -0
  83. package/src/components/block-list/use-block-props/index.js +12 -2
  84. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +3 -7
  85. package/src/components/block-settings-menu/block-settings-dropdown.js +12 -9
  86. package/src/components/block-toolbar/index.js +14 -4
  87. package/src/components/global-styles/use-global-styles-output.js +11 -11
  88. package/src/components/list-view/block-select-button.js +16 -2
  89. package/src/components/list-view/style.scss +8 -0
  90. package/src/components/list-view/use-clipboard-handler.js +3 -2
  91. package/src/components/rich-text/index.js +2 -2
  92. package/src/components/url-popover/index.js +5 -5
  93. package/src/components/use-moving-animation/index.js +1 -0
  94. package/src/components/writing-flow/use-clipboard-handler.js +3 -2
  95. package/src/components/writing-flow/utils.js +31 -16
  96. package/src/hooks/block-hooks.js +36 -3
  97. package/src/hooks/use-bindings-attributes.js +214 -62
  98. package/src/private-apis.js +2 -0
  99. package/src/store/actions.js +54 -14
  100. package/src/style.scss +1 -0
@@ -1 +1 @@
1
- {"version":3,"names":["__","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockHooks","blockIndex","rootClientId","innerBlocksLength","getBlocks","getBlockIndex","getBlockRootClientId","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","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":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,SAAS,EACTC,aAAa,QACP,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACrE,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,eAAe;AAC5D,SAASL,KAAK,IAAIM,gBAAgB,QAAQ,UAAU;AAEpD,MAAMC,YAAY,GAAG,CAAC,CAAC;AAEvB,SAASC,qBAAqBA,CAAE;EAAEC,IAAI;EAAEC;AAAS,CAAC,EAAG;EACpD,MAAMC,UAAU,GAAGR,SAAS,CACzBS,MAA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ACDU,QAAQ,EAAGA,CAAA,KAAM;UAChB,IAAK,CAAEJ,OAAO,EAAG;YAChB;YACA,MAAMvB,gBAAgB,GACrBD,KAAK,CAACb,UAAU,CAAEP,IAAI,CAAE;YACzBmC,iCAAiC,CAChC7C,WAAW,CAAE8B,KAAK,CAACpB,IAAK,CAAC,EACzBqB,gBACD,CAAC;YACD;UACD;;UAEA;UACAQ,WAAW,CACVd,oBAAoB,CACnBK,KAAK,CAACpB,IAAI,CACV,EACD,KACD,CAAC;QACF;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAEA,eAAe;EACdiD,IAAI,EAAElD,qBAAqB;EAC3BmD,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
1
+ {"version":3,"names":["__","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControlPure","name","clientId","metadata","ignoredHookedBlocks","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockName","blockHooks","includes","blockIndex","rootClientId","innerBlocksLength","getBlocks","getBlockIndex","getBlockRootClientId","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","relativePosition","candidates","undefined","hookedBlock","find","candidate","Object","values","insertBlock","removeBlock","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","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":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AACtD,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,SAAS,EACTC,aAAa,QACP,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,KAAK,IAAIC,WAAW,QAAQ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EAC7BC,UAAUA,CAAA,EAAG;IACZ,OAAO,IAAI;EACZ;AACD,CAAC"}
@@ -1,16 +1,17 @@
1
- import { createElement } from "react";
1
+ import { createElement, Fragment } from "react";
2
2
  /**
3
3
  * WordPress dependencies
4
4
  */
5
5
  import { getBlockType, store as blocksStore } from '@wordpress/blocks';
6
6
  import { createHigherOrderComponent } from '@wordpress/compose';
7
7
  import { useSelect } from '@wordpress/data';
8
+ import { useLayoutEffect, useCallback, useState } from '@wordpress/element';
8
9
  import { addFilter } from '@wordpress/hooks';
10
+ import { RichTextData } from '@wordpress/rich-text';
11
+
9
12
  /**
10
13
  * Internal dependencies
11
14
  */
12
- import { store as blockEditorStore } from '../store';
13
- import { useBlockEditContext } from '../components/block-edit/context';
14
15
  import { unlock } from '../lock-unlock';
15
16
 
16
17
  /** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */
@@ -23,68 +24,192 @@ import { unlock } from '../lock-unlock';
23
24
  * @return {WPHigherOrderComponent} Higher-order component.
24
25
  */
25
26
 
26
- export const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
27
+ const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
27
28
  'core/paragraph': ['content'],
28
29
  'core/heading': ['content'],
29
30
  'core/image': ['url', 'title', 'alt'],
30
31
  'core/button': ['url', 'text', 'linkTarget']
31
32
  };
32
- const createEditFunctionWithBindingsAttribute = () => createHigherOrderComponent(BlockEdit => props => {
33
+
34
+ /**
35
+ * Based on the given block name,
36
+ * check if it is possible to bind the block.
37
+ *
38
+ * @param {string} blockName - The block name.
39
+ * @return {boolean} Whether it is possible to bind the block to sources.
40
+ */
41
+ export function canBindBlock(blockName) {
42
+ return blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;
43
+ }
44
+
45
+ /**
46
+ * Based on the given block name and attribute name,
47
+ * check if it is possible to bind the block attribute.
48
+ *
49
+ * @param {string} blockName - The block name.
50
+ * @param {string} attributeName - The attribute name.
51
+ * @return {boolean} Whether it is possible to bind the block attribute.
52
+ */
53
+ export function canBindAttribute(blockName, attributeName) {
54
+ return canBindBlock(blockName) && BLOCK_BINDINGS_ALLOWED_BLOCKS[blockName].includes(attributeName);
55
+ }
56
+
57
+ /**
58
+ * This component is responsible for detecting and
59
+ * propagating data changes from the source to the block.
60
+ *
61
+ * @param {Object} props - The component props.
62
+ * @param {string} props.attrName - The attribute name.
63
+ * @param {Object} props.blockProps - The block props with bound attribute.
64
+ * @param {Object} props.source - Source handler.
65
+ * @param {Object} props.args - The arguments to pass to the source.
66
+ * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
67
+ * @return {null} Data-handling component. Render nothing.
68
+ */
69
+ const BindingConnector = ({
70
+ args,
71
+ attrName,
72
+ blockProps,
73
+ source,
74
+ onPropValueChange
75
+ }) => {
33
76
  const {
34
- clientId,
35
- name: blockName
36
- } = useBlockEditContext();
37
- const blockBindingsSources = unlock(useSelect(blocksStore)).getAllBlockBindingsSources();
77
+ placeholder,
78
+ value: propValue
79
+ } = source.useSource(blockProps, args);
38
80
  const {
39
- getBlockAttributes
40
- } = useSelect(blockEditorStore);
41
- const updatedAttributes = getBlockAttributes(clientId);
42
- if (updatedAttributes?.metadata?.bindings) {
43
- Object.entries(updatedAttributes.metadata.bindings).forEach(([attributeName, settings]) => {
44
- const source = blockBindingsSources[settings.source];
45
- if (source && source.useSource) {
46
- // Second argument (`updateMetaValue`) will be used to update the value in the future.
47
- const {
48
- placeholder,
49
- useValue: [metaValue = null] = []
50
- } = source.useSource(props, settings.args);
51
- if (placeholder && !metaValue) {
52
- // If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.
53
- // Adding this workaround until attributes and metadata fields types are improved and include `url`.
54
- const htmlAttribute = getBlockType(blockName).attributes[attributeName].attribute;
55
- if (htmlAttribute === 'src' || htmlAttribute === 'href') {
56
- updatedAttributes[attributeName] = null;
57
- } else {
58
- updatedAttributes[attributeName] = placeholder;
59
- }
60
- }
61
- if (metaValue) {
62
- updatedAttributes[attributeName] = metaValue;
63
- }
81
+ name: blockName
82
+ } = blockProps;
83
+ const attrValue = blockProps.attributes[attrName];
84
+ const updateBoundAttibute = useCallback((newAttrValue, prevAttrValue) => {
85
+ /*
86
+ * If the attribute is a RichTextData instance,
87
+ * (core/paragraph, core/heading, core/button, etc.)
88
+ * compare its HTML representation with the new value.
89
+ *
90
+ * To do: it looks like a workaround.
91
+ * Consider improving the attribute and metadata fields types.
92
+ */
93
+ if (prevAttrValue instanceof RichTextData) {
94
+ // Bail early if the Rich Text value is the same.
95
+ if (prevAttrValue.toHTMLString() === newAttrValue) {
96
+ return;
64
97
  }
98
+
99
+ /*
100
+ * To preserve the value type,
101
+ * convert the new value to a RichTextData instance.
102
+ */
103
+ newAttrValue = RichTextData.fromHTMLString(newAttrValue);
104
+ }
105
+ if (prevAttrValue === newAttrValue) {
106
+ return;
107
+ }
108
+ onPropValueChange({
109
+ [attrName]: newAttrValue
65
110
  });
66
- }
67
- return createElement(BlockEdit, {
68
- key: "edit",
111
+ }, [attrName, onPropValueChange]);
112
+ useLayoutEffect(() => {
113
+ if (typeof propValue !== 'undefined') {
114
+ updateBoundAttibute(propValue, attrValue);
115
+ } else if (placeholder) {
116
+ /*
117
+ * Placeholder fallback.
118
+ * If the attribute is `src` or `href`,
119
+ * a placeholder can't be used because it is not a valid url.
120
+ * Adding this workaround until
121
+ * attributes and metadata fields types are improved and include `url`.
122
+ */
123
+ const htmlAttribute = getBlockType(blockName).attributes[attrName].attribute;
124
+ if (htmlAttribute === 'src' || htmlAttribute === 'href') {
125
+ updateBoundAttibute(null);
126
+ return;
127
+ }
128
+ updateBoundAttibute(placeholder);
129
+ }
130
+ }, [updateBoundAttibute, propValue, attrValue, placeholder, blockName, attrName]);
131
+ return null;
132
+ };
133
+
134
+ /**
135
+ * BlockBindingBridge acts like a component wrapper
136
+ * that connects the bound attributes of a block
137
+ * to the source handlers.
138
+ * For this, it creates a BindingConnector for each bound attribute.
139
+ *
140
+ * @param {Object} props - The component props.
141
+ * @param {Object} props.blockProps - The BlockEdit props object.
142
+ * @param {Object} props.bindings - The block bindings settings.
143
+ * @param {Function} props.onPropValueChange - The function to call when the attribute value changes.
144
+ * @return {null} Data-handling component. Render nothing.
145
+ */
146
+ function BlockBindingBridge({
147
+ blockProps,
148
+ bindings,
149
+ onPropValueChange
150
+ }) {
151
+ const blockBindingsSources = unlock(useSelect(blocksStore)).getAllBlockBindingsSources();
152
+ return createElement(Fragment, null, Object.entries(bindings).map(([attrName, boundAttribute]) => {
153
+ // Bail early if the block doesn't have a valid source handler.
154
+ const source = blockBindingsSources[boundAttribute.source];
155
+ if (!source?.useSource) {
156
+ return null;
157
+ }
158
+ return createElement(BindingConnector, {
159
+ key: attrName,
160
+ attrName: attrName,
161
+ source: source,
162
+ blockProps: blockProps,
163
+ args: boundAttribute.args,
164
+ onPropValueChange: onPropValueChange
165
+ });
166
+ }));
167
+ }
168
+ const withBlockBindingSupport = createHigherOrderComponent(BlockEdit => props => {
169
+ /*
170
+ * Collect and update the bound attributes
171
+ * in a separate state.
172
+ */
173
+ const [boundAttributes, setBoundAttributes] = useState({});
174
+ const updateBoundAttributes = useCallback(newAttributes => setBoundAttributes(prev => ({
175
+ ...prev,
176
+ ...newAttributes
177
+ })), []);
178
+
179
+ /*
180
+ * Create binding object filtering
181
+ * only the attributes that can be bound.
182
+ */
183
+ const bindings = Object.fromEntries(Object.entries(props.attributes.metadata?.bindings || {}).filter(([attrName]) => canBindAttribute(props.name, attrName)));
184
+ return createElement(Fragment, null, Object.keys(bindings).length > 0 && createElement(BlockBindingBridge, {
185
+ blockProps: props,
186
+ bindings: bindings,
187
+ onPropValueChange: updateBoundAttributes
188
+ }), createElement(BlockEdit, {
69
189
  ...props,
70
- attributes: updatedAttributes
71
- });
72
- }, 'useBoundAttributes');
190
+ attributes: {
191
+ ...props.attributes,
192
+ ...boundAttributes
193
+ }
194
+ }));
195
+ }, 'withBlockBindingSupport');
73
196
 
74
197
  /**
75
198
  * Filters a registered block's settings to enhance a block's `edit` component
76
199
  * to upgrade bound attributes.
77
200
  *
78
- * @param {WPBlockSettings} settings Registered block settings.
79
- *
201
+ * @param {WPBlockSettings} settings - Registered block settings.
202
+ * @param {string} name - Block name.
80
203
  * @return {WPBlockSettings} Filtered block settings.
81
204
  */
82
- function shimAttributeSource(settings) {
83
- if (!(settings.name in BLOCK_BINDINGS_ALLOWED_BLOCKS)) {
205
+ function shimAttributeSource(settings, name) {
206
+ if (!canBindBlock(name)) {
84
207
  return settings;
85
208
  }
86
- settings.edit = createEditFunctionWithBindingsAttribute()(settings.edit);
87
- return settings;
209
+ return {
210
+ ...settings,
211
+ edit: withBlockBindingSupport(settings.edit)
212
+ };
88
213
  }
89
214
  addFilter('blocks.registerBlockType', 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source', shimAttributeSource);
90
215
  //# sourceMappingURL=use-bindings-attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getBlockType","store","blocksStore","createHigherOrderComponent","useSelect","addFilter","blockEditorStore","useBlockEditContext","unlock","BLOCK_BINDINGS_ALLOWED_BLOCKS","createEditFunctionWithBindingsAttribute","BlockEdit","props","clientId","name","blockName","blockBindingsSources","getAllBlockBindingsSources","getBlockAttributes","updatedAttributes","metadata","bindings","Object","entries","forEach","attributeName","settings","source","useSource","placeholder","useValue","metaValue","args","htmlAttribute","attributes","attribute","createElement","key","shimAttributeSource","edit"],"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":";AAAA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACtE,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,SAAS,QAAQ,kBAAkB;AA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AGJ,MAAM,CAACC,SAAS,CAAEhB,KAAK,EAAEc,QAAQ,CAACM,IAAK,CAAC;QAE5C,IAAKH,WAAW,IAAI,CAAEE,SAAS,EAAG;UACjC;UACA;UACA,MAAME,aAAa,GAClBjC,YAAY,CAAEe,SAAU,CAAC,CAACmB,UAAU,CACnCT,aAAa,CACb,CAACU,SAAS;UACZ,IACCF,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,OACCK,aAAA,CAACzB,SAAS;IACT0B,GAAG,EAAC,MAAM;IAAA,GACLzB,KAAK;IACVsB,UAAU,EAAGf;EAAmB,CAChC,CAAC;AAEJ,CAAC,EACD,oBACD,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASmB,mBAAmBA,CAAEZ,QAAQ,EAAG;EACxC,IAAK,EAAIA,QAAQ,CAACZ,IAAI,IAAIL,6BAA6B,CAAE,EAAG;IAC3D,OAAOiB,QAAQ;EAChB;EACAA,QAAQ,CAACa,IAAI,GAAG7B,uCAAuC,CAAC,CAAC,CAAEgB,QAAQ,CAACa,IAAK,CAAC;EAE1E,OAAOb,QAAQ;AAChB;AAEArB,SAAS,CACR,0BAA0B,EAC1B,0EAA0E,EAC1EiC,mBACD,CAAC"}
1
+ {"version":3,"names":["getBlockType","store","blocksStore","createHigherOrderComponent","useSelect","useLayoutEffect","useCallback","useState","addFilter","RichTextData","unlock","BLOCK_BINDINGS_ALLOWED_BLOCKS","canBindBlock","blockName","canBindAttribute","attributeName","includes","BindingConnector","args","attrName","blockProps","source","onPropValueChange","placeholder","value","propValue","useSource","name","attrValue","attributes","updateBoundAttibute","newAttrValue","prevAttrValue","toHTMLString","fromHTMLString","htmlAttribute","attribute","BlockBindingBridge","bindings","blockBindingsSources","getAllBlockBindingsSources","createElement","Fragment","Object","entries","map","boundAttribute","key","withBlockBindingSupport","BlockEdit","props","boundAttributes","setBoundAttributes","updateBoundAttributes","newAttributes","prev","fromEntries","metadata","filter","keys","length","shimAttributeSource","settings","edit"],"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":";AAAA;AACA;AACA;AACA,SAASA,YAAY,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACtE,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,oBAAoB;AAC3E,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,YAAY,QAAQ,sBAAsB;;AAEnD;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;;AAEvC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,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;AACA,OAAO,SAASC,YAAYA,CAAEC,SAAS,EAAG;EACzC,OAAOA,SAAS,IAAIF,6BAA6B;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,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;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
24
24
  import { getDuotoneFilter } from './components/duotone/utils';
25
25
  import { useFlashEditableBlocks } from './components/use-flash-editable-blocks';
26
26
  import { selectBlockPatternsKey } from './store/private-keys';
27
+ import { requiresWrapperOnCopy } from './components/writing-flow/utils';
27
28
  import { PrivateRichText } from './components/rich-text/';
28
29
 
29
30
  /**
@@ -56,6 +57,7 @@ lock(privateApis, {
56
57
  usesContextKey,
57
58
  useFlashEditableBlocks,
58
59
  selectBlockPatternsKey,
60
+ requiresWrapperOnCopy,
59
61
  PrivateRichText
60
62
  });
61
63
  //# sourceMappingURL=private-apis.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["globalStyles","ExperimentalBlockEditorProvider","lock","getRichTextValues","ResizableBoxPopover","ComposedPrivateInserter","PrivateInserter","default","PrivateQuickInserter","PrivateListView","BlockInfo","useCanBlockToolbarBeFocused","cleanEmptyObject","useStyleOverride","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","useLayoutClasses","useLayoutStyles","DimensionsTool","ResolutionTool","ReusableBlocksRenameHint","useReusableBlocksRenameHint","usesContextKey","ExperimentalBlockCanvas","getDuotoneFilter","useFlashEditableBlocks","selectBlockPatternsKey","PrivateRichText","privateApis"],"sources":["@wordpress/block-editor/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport { lock } from './lock-unlock';\nimport { getRichTextValues } from './components/rich-text/get-rich-text-values';\nimport ResizableBoxPopover from './components/resizable-box-popover';\nimport { ComposedPrivateInserter as PrivateInserter } from './components/inserter';\nimport { default as PrivateQuickInserter } from './components/inserter/quick-inserter';\nimport { PrivateListView } from './components/list-view';\nimport BlockInfo from './components/block-info-slot-fill';\nimport { useCanBlockToolbarBeFocused } from './utils/use-can-block-toolbar-be-focused';\nimport { cleanEmptyObject, useStyleOverride } from './hooks/utils';\nimport BlockQuickNavigation from './components/block-quick-navigation';\nimport { LayoutStyle } from './components/block-list/layout';\nimport { BlockRemovalWarningModal } from './components/block-removal-warning-modal';\nimport { useLayoutClasses, useLayoutStyles } from './hooks';\nimport DimensionsTool from './components/dimensions-tool';\nimport ResolutionTool from './components/resolution-tool';\nimport {\n\tdefault as ReusableBlocksRenameHint,\n\tuseReusableBlocksRenameHint,\n} from './components/inserter/reusable-block-rename-hint';\nimport { usesContextKey } from './components/rich-text/format-edit';\nimport { ExperimentalBlockCanvas } from './components/block-canvas';\nimport { getDuotoneFilter } from './components/duotone/utils';\nimport { useFlashEditableBlocks } from './components/use-flash-editable-blocks';\nimport { selectBlockPatternsKey } from './store/private-keys';\nimport { PrivateRichText } from './components/rich-text/';\n\n/**\n * Private @wordpress/block-editor APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\t...globalStyles,\n\tExperimentalBlockCanvas,\n\tExperimentalBlockEditorProvider,\n\tgetDuotoneFilter,\n\tgetRichTextValues,\n\tPrivateInserter,\n\tPrivateQuickInserter,\n\tPrivateListView,\n\tResizableBoxPopover,\n\tBlockInfo,\n\tuseCanBlockToolbarBeFocused,\n\tcleanEmptyObject,\n\tuseStyleOverride,\n\tBlockQuickNavigation,\n\tLayoutStyle,\n\tBlockRemovalWarningModal,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\tDimensionsTool,\n\tResolutionTool,\n\tReusableBlocksRenameHint,\n\tuseReusableBlocksRenameHint,\n\tusesContextKey,\n\tuseFlashEditableBlocks,\n\tselectBlockPatternsKey,\n\tPrivateRichText,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,KAAKA,YAAY,MAAM,4BAA4B;AAC1D,SAASC,+BAA+B,QAAQ,uBAAuB;AACvE,SAASC,IAAI,QAAQ,eAAe;AACpC,SAASC,iBAAiB,QAAQ,6CAA6C;AAC/E,OAAOC,mBAAmB,MAAM,oCAAoC;AACpE,SAASC,uBAAuB,IAAIC,eAAe,QAAQ,uBAAuB;AAClF,SAASC,OAAO,IAAIC,oBAAoB,QAAQ,sCAAsC;AACtF,SAASC,eAAe,QAAQ,wBAAwB;AACxD,OAAOC,SAAS,MAAM,mCAAmC;AACzD,SAASC,2BAA2B,QAAQ,0CAA0C;AACtF,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,eAAe;AAClE,OAAOC,oBAAoB,MAAM,qCAAqC;AACtE,SAASC,WAAW,QAAQ,gCAAgC;AAC5D,SAASC,wBAAwB,QAAQ,0CAA0C;AACnF,SAASC,gBAAgB,EAAEC,eAAe,QAAQ,SAAS;AAC3D,OAAOC,cAAc,MAAM,8BAA8B;AACzD,OAAOC,cAAc,MAAM,8BAA8B;AACzD,SACCb,OAAO,IAAIc,wBAAwB,EACnCC,2BAA2B,QACrB,kDAAkD;AACzD,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,sBAAsB,QAAQ,wCAAwC;AAC/E,SAASC,sBAAsB,QAAQ,sBAAsB;AAC7D,SAASC,eAAe,QAAQ,yBAAyB;;AAEzD;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7B3B,IAAI,CAAE2B,WAAW,EAAE;EAClB,GAAG7B,YAAY;EACfwB,uBAAuB;EACvBvB,+BAA+B;EAC/BwB,gBAAgB;EAChBtB,iBAAiB;EACjBG,eAAe;EACfE,oBAAoB;EACpBC,eAAe;EACfL,mBAAmB;EACnBM,SAAS;EACTC,2BAA2B;EAC3BC,gBAAgB;EAChBC,gBAAgB;EAChBC,oBAAoB;EACpBC,WAAW;EACXC,wBAAwB;EACxBC,gBAAgB;EAChBC,eAAe;EACfC,cAAc;EACdC,cAAc;EACdC,wBAAwB;EACxBC,2BAA2B;EAC3BC,cAAc;EACdG,sBAAsB;EACtBC,sBAAsB;EACtBC;AACD,CAAE,CAAC"}
1
+ {"version":3,"names":["globalStyles","ExperimentalBlockEditorProvider","lock","getRichTextValues","ResizableBoxPopover","ComposedPrivateInserter","PrivateInserter","default","PrivateQuickInserter","PrivateListView","BlockInfo","useCanBlockToolbarBeFocused","cleanEmptyObject","useStyleOverride","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","useLayoutClasses","useLayoutStyles","DimensionsTool","ResolutionTool","ReusableBlocksRenameHint","useReusableBlocksRenameHint","usesContextKey","ExperimentalBlockCanvas","getDuotoneFilter","useFlashEditableBlocks","selectBlockPatternsKey","requiresWrapperOnCopy","PrivateRichText","privateApis"],"sources":["@wordpress/block-editor/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport { lock } from './lock-unlock';\nimport { getRichTextValues } from './components/rich-text/get-rich-text-values';\nimport ResizableBoxPopover from './components/resizable-box-popover';\nimport { ComposedPrivateInserter as PrivateInserter } from './components/inserter';\nimport { default as PrivateQuickInserter } from './components/inserter/quick-inserter';\nimport { PrivateListView } from './components/list-view';\nimport BlockInfo from './components/block-info-slot-fill';\nimport { useCanBlockToolbarBeFocused } from './utils/use-can-block-toolbar-be-focused';\nimport { cleanEmptyObject, useStyleOverride } from './hooks/utils';\nimport BlockQuickNavigation from './components/block-quick-navigation';\nimport { LayoutStyle } from './components/block-list/layout';\nimport { BlockRemovalWarningModal } from './components/block-removal-warning-modal';\nimport { useLayoutClasses, useLayoutStyles } from './hooks';\nimport DimensionsTool from './components/dimensions-tool';\nimport ResolutionTool from './components/resolution-tool';\nimport {\n\tdefault as ReusableBlocksRenameHint,\n\tuseReusableBlocksRenameHint,\n} from './components/inserter/reusable-block-rename-hint';\nimport { usesContextKey } from './components/rich-text/format-edit';\nimport { ExperimentalBlockCanvas } from './components/block-canvas';\nimport { getDuotoneFilter } from './components/duotone/utils';\nimport { useFlashEditableBlocks } from './components/use-flash-editable-blocks';\nimport { selectBlockPatternsKey } from './store/private-keys';\nimport { requiresWrapperOnCopy } from './components/writing-flow/utils';\nimport { PrivateRichText } from './components/rich-text/';\n\n/**\n * Private @wordpress/block-editor APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\t...globalStyles,\n\tExperimentalBlockCanvas,\n\tExperimentalBlockEditorProvider,\n\tgetDuotoneFilter,\n\tgetRichTextValues,\n\tPrivateInserter,\n\tPrivateQuickInserter,\n\tPrivateListView,\n\tResizableBoxPopover,\n\tBlockInfo,\n\tuseCanBlockToolbarBeFocused,\n\tcleanEmptyObject,\n\tuseStyleOverride,\n\tBlockQuickNavigation,\n\tLayoutStyle,\n\tBlockRemovalWarningModal,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\tDimensionsTool,\n\tResolutionTool,\n\tReusableBlocksRenameHint,\n\tuseReusableBlocksRenameHint,\n\tusesContextKey,\n\tuseFlashEditableBlocks,\n\tselectBlockPatternsKey,\n\trequiresWrapperOnCopy,\n\tPrivateRichText,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,KAAKA,YAAY,MAAM,4BAA4B;AAC1D,SAASC,+BAA+B,QAAQ,uBAAuB;AACvE,SAASC,IAAI,QAAQ,eAAe;AACpC,SAASC,iBAAiB,QAAQ,6CAA6C;AAC/E,OAAOC,mBAAmB,MAAM,oCAAoC;AACpE,SAASC,uBAAuB,IAAIC,eAAe,QAAQ,uBAAuB;AAClF,SAASC,OAAO,IAAIC,oBAAoB,QAAQ,sCAAsC;AACtF,SAASC,eAAe,QAAQ,wBAAwB;AACxD,OAAOC,SAAS,MAAM,mCAAmC;AACzD,SAASC,2BAA2B,QAAQ,0CAA0C;AACtF,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,eAAe;AAClE,OAAOC,oBAAoB,MAAM,qCAAqC;AACtE,SAASC,WAAW,QAAQ,gCAAgC;AAC5D,SAASC,wBAAwB,QAAQ,0CAA0C;AACnF,SAASC,gBAAgB,EAAEC,eAAe,QAAQ,SAAS;AAC3D,OAAOC,cAAc,MAAM,8BAA8B;AACzD,OAAOC,cAAc,MAAM,8BAA8B;AACzD,SACCb,OAAO,IAAIc,wBAAwB,EACnCC,2BAA2B,QACrB,kDAAkD;AACzD,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,sBAAsB,QAAQ,wCAAwC;AAC/E,SAASC,sBAAsB,QAAQ,sBAAsB;AAC7D,SAASC,qBAAqB,QAAQ,iCAAiC;AACvE,SAASC,eAAe,QAAQ,yBAAyB;;AAEzD;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7B5B,IAAI,CAAE4B,WAAW,EAAE;EAClB,GAAG9B,YAAY;EACfwB,uBAAuB;EACvBvB,+BAA+B;EAC/BwB,gBAAgB;EAChBtB,iBAAiB;EACjBG,eAAe;EACfE,oBAAoB;EACpBC,eAAe;EACfL,mBAAmB;EACnBM,SAAS;EACTC,2BAA2B;EAC3BC,gBAAgB;EAChBC,gBAAgB;EAChBC,oBAAoB;EACpBC,WAAW;EACXC,wBAAwB;EACxBC,gBAAgB;EAChBC,eAAe;EACfC,cAAc;EACdC,cAAc;EACdC,wBAAwB;EACxBC,2BAA2B;EAC3BC,cAAc;EACdG,sBAAsB;EACtBC,sBAAsB;EACtBC,qBAAqB;EACrBC;AACD,CAAE,CAAC"}
@@ -1331,7 +1331,7 @@ export const duplicateBlocks = (clientIds, updateSelection = true) => ({
1331
1331
  };
1332
1332
 
1333
1333
  /**
1334
- * Action that inserts an empty block before a given block.
1334
+ * Action that inserts a default block before a given block.
1335
1335
  *
1336
1336
  * @param {string} clientId
1337
1337
  */
@@ -1347,12 +1347,29 @@ export const insertBeforeBlock = clientId => ({
1347
1347
  if (isLocked) {
1348
1348
  return;
1349
1349
  }
1350
- const firstSelectedIndex = select.getBlockIndex(clientId);
1351
- return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex);
1350
+ const blockIndex = select.getBlockIndex(clientId);
1351
+ const directInsertBlock = rootClientId ? select.getDirectInsertBlock(rootClientId) : null;
1352
+ if (!directInsertBlock) {
1353
+ return dispatch.insertDefaultBlock({}, rootClientId, blockIndex);
1354
+ }
1355
+ const copiedAttributes = {};
1356
+ if (directInsertBlock.attributesToCopy) {
1357
+ const attributes = select.getBlockAttributes(clientId);
1358
+ directInsertBlock.attributesToCopy.forEach(key => {
1359
+ if (attributes[key]) {
1360
+ copiedAttributes[key] = attributes[key];
1361
+ }
1362
+ });
1363
+ }
1364
+ const block = createBlock(directInsertBlock.name, {
1365
+ ...directInsertBlock.attributes,
1366
+ ...copiedAttributes
1367
+ });
1368
+ return dispatch.insertBlock(block, blockIndex, rootClientId);
1352
1369
  };
1353
1370
 
1354
1371
  /**
1355
- * Action that inserts an empty block after a given block.
1372
+ * Action that inserts a default block after a given block.
1356
1373
  *
1357
1374
  * @param {string} clientId
1358
1375
  */
@@ -1368,8 +1385,25 @@ export const insertAfterBlock = clientId => ({
1368
1385
  if (isLocked) {
1369
1386
  return;
1370
1387
  }
1371
- const firstSelectedIndex = select.getBlockIndex(clientId);
1372
- return dispatch.insertDefaultBlock({}, rootClientId, firstSelectedIndex + 1);
1388
+ const blockIndex = select.getBlockIndex(clientId);
1389
+ const directInsertBlock = rootClientId ? select.getDirectInsertBlock(rootClientId) : null;
1390
+ if (!directInsertBlock) {
1391
+ return dispatch.insertDefaultBlock({}, rootClientId, blockIndex + 1);
1392
+ }
1393
+ const copiedAttributes = {};
1394
+ if (directInsertBlock.attributesToCopy) {
1395
+ const attributes = select.getBlockAttributes(clientId);
1396
+ directInsertBlock.attributesToCopy.forEach(key => {
1397
+ if (attributes[key]) {
1398
+ copiedAttributes[key] = attributes[key];
1399
+ }
1400
+ });
1401
+ }
1402
+ const block = createBlock(directInsertBlock.name, {
1403
+ ...directInsertBlock.attributes,
1404
+ ...copiedAttributes
1405
+ });
1406
+ return dispatch.insertBlock(block, blockIndex + 1, rootClientId);
1373
1407
  };
1374
1408
 
1375
1409
  /**