Skip to content

Commit c40ef64

Browse files
authored
Fix multiple empty icon blocks as one (#265)
* make the icon chooser open event distinct for each icon being edited * refactor the handleSelect callback for IconModifier to separate concerns * rebuild block-editor bundle
1 parent 13fe980 commit c40ef64

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

block-editor/build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '17f5c0bec291cb2ddb3f');
1+
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '053349df96bda0ebca60');

block-editor/build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

block-editor/src/edit.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { computeIconLayerCount, prepareParamsForUseBlock, renderIcon } from './r
1212
import IconModifier from './iconModifier'
1313
import createCustomEvent from './createCustomEvent'
1414

15-
const openIconChooserForAddLayerEvent = createCustomEvent()
1615
const { IconChooserModal } = get(window, [GLOBAL_KEY, 'iconChooser'], {})
1716
const modifyToolbarIcon = wpIconFromFaIconDefinition(faBrush)
1817
const defaultStylingParams = {
@@ -23,6 +22,8 @@ const defaultStylingParams = {
2322
export function Edit(props) {
2423
const { attributes, setAttributes } = props
2524

25+
const iconChooserOpenEvent = createCustomEvent()
26+
2627
const [justificationDropdownMenuIcon, setJustificationDropdownMenuIcon] = useState(justifyCenter)
2728

2829
const setJustification = (justification) => {
@@ -121,8 +122,8 @@ export function Edit(props) {
121122
attributes={attributes}
122123
setAttributes={setAttributes}
123124
IconChooserModal={IconChooserModal}
124-
prepareHandleSelect={prepareHandleSelect}
125-
iconChooserOpenEvent={openIconChooserForAddLayerEvent}
125+
handleSelect={prepareHandleSelect({ replace: 0 })}
126+
iconChooserOpenEvent={iconChooserOpenEvent}
126127
/>
127128
</Modal>
128129
)}
@@ -145,11 +146,11 @@ export function Edit(props) {
145146
>
146147
<IconChooserModal
147148
onSubmit={prepareHandleSelect({ append: true })}
148-
openEvent={openIconChooserForAddLayerEvent}
149+
openEvent={iconChooserOpenEvent}
149150
/>
150151
<Button
151152
variant="secondary"
152-
onClick={() => document.dispatchEvent(openIconChooserForAddLayerEvent)}
153+
onClick={() => document.dispatchEvent(iconChooserOpenEvent)}
153154
>
154155
{__('Choose Icon', 'font-awesome')}
155156
</Button>

block-editor/src/iconModifier.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export default function (params) {
379379
context,
380380
iconChooserOpenEvent,
381381
IconChooserModal,
382-
prepareHandleSelect
382+
handleSelect
383383
} = params
384384

385385
const iconLayers = attributes.iconLayers || []
@@ -483,7 +483,7 @@ export default function (params) {
483483
</div>
484484
<IconChooserModal
485485
title={__('Change Font Awesome Icon', 'font-awesome')}
486-
onSubmit={prepareHandleSelect({ replace: 0 })}
486+
onSubmit={handleSelect}
487487
openEvent={iconChooserOpenEvent}
488488
/>
489489
</div>

0 commit comments

Comments
 (0)