| 1 |
import { useEffect } from "@wordpress/element"; |
| 2 |
|
| 3 |
export const useSyncParentAttributes = ({ parentAttributes, attributes, setAttributes }) => { |
| 4 |
useEffect(() => { |
| 5 |
const { iconEnable, iconSource, svgIconName, iconName, listTitleEnable, descriptionEnable } = attributes; |
| 6 |
|
| 7 |
const updates = {}; |
| 8 |
|
| 9 |
if (iconEnable === undefined) { |
| 10 |
updates.iconEnableParent = parentAttributes.iconEnable; |
| 11 |
} |
| 12 |
if (iconSource === undefined) { |
| 13 |
updates.iconSourceParent = parentAttributes.iconSource; |
| 14 |
} |
| 15 |
if (svgIconName === undefined) { |
| 16 |
updates.parentSvgIconName = parentAttributes.svgIconName; |
| 17 |
} |
| 18 |
if (iconName === undefined) { |
| 19 |
updates.parentIconName = parentAttributes.iconName; |
| 20 |
} |
| 21 |
if (listTitleEnable === undefined) { |
| 22 |
updates.parentListTitleEnable = parentAttributes.listTitleEnable; |
| 23 |
} |
| 24 |
if (descriptionEnable === undefined) { |
| 25 |
updates.parentDescriptionEnable = parentAttributes.descriptionEnable; |
| 26 |
} |
| 27 |
|
| 28 |
if (attributes.parentIconSourceCustom !== parentAttributes.iconSourceCustom) { |
| 29 |
updates.parentIconSourceCustom = parentAttributes.iconSourceCustom; |
| 30 |
} |
| 31 |
if (attributes.parentListsLayout !== parentAttributes.smartListsLayout) { |
| 32 |
updates.parentListsLayout = parentAttributes.smartListsLayout; |
| 33 |
} |
| 34 |
|
| 35 |
if (Object.keys(updates).length > 0) { |
| 36 |
setAttributes(updates); |
| 37 |
} |
| 38 |
}, [ |
| 39 |
attributes.iconEnable, |
| 40 |
attributes.iconSource, |
| 41 |
attributes.svgIconName, |
| 42 |
attributes.iconName, |
| 43 |
attributes.listTitleEnable, |
| 44 |
attributes.descriptionEnable, |
| 45 |
attributes.parentIconSourceCustom, |
| 46 |
attributes.parentListsLayout, |
| 47 |
parentAttributes.iconEnable, |
| 48 |
parentAttributes.iconSource, |
| 49 |
parentAttributes.svgIconName, |
| 50 |
parentAttributes.iconName, |
| 51 |
parentAttributes.listTitleEnable, |
| 52 |
parentAttributes.descriptionEnable, |
| 53 |
parentAttributes.iconSourceCustom, |
| 54 |
parentAttributes.smartListsLayout, |
| 55 |
setAttributes, |
| 56 |
]); |
| 57 |
}; |
| 58 |
|