| 1 |
import { withSelect, withDispatch, select } from '@wordpress/data'; |
| 2 |
|
| 3 |
// from answer here: https://github.com/WordPress/gutenberg/issues/44477#issuecomment-1263026599 |
| 4 |
export const isFullSiteEditor = () => { |
| 5 |
return select && !!select('core/edit-site'); |
| 6 |
}; |
| 7 |
|
| 8 |
const applyWithSelect = withSelect((select: Function, props: any): any => { |
| 9 |
return { |
| 10 |
metaValue: select('core/editor').getEditedPostAttribute('meta')[ |
| 11 |
props.metaKey |
| 12 |
], |
| 13 |
}; |
| 14 |
}); |
| 15 |
|
| 16 |
const applyWithDispatch = withDispatch( |
| 17 |
(dispatch: Function, props: any): any => { |
| 18 |
return { |
| 19 |
setMetaValue(value: string) { |
| 20 |
dispatch('core/editor').editPost({ meta: { [props.metaKey]: value } }); |
| 21 |
}, |
| 22 |
}; |
| 23 |
} |
| 24 |
); |
| 25 |
|
| 26 |
function apply<T>(el: T): T { |
| 27 |
return applyWithSelect(applyWithDispatch(el)); |
| 28 |
} |
| 29 |
|
| 30 |
export default apply; |
| 31 |
|