|
| 1 | +import React from 'react' |
1 | 2 | import { DefaultThirdPartyControlDefinitions } from '../../core/third-party/third-party-controls' |
2 | 3 | import type { PropertyControlsInfo } from '../custom-code/code-file' |
3 | 4 | import { Substores, useEditorState } from '../editor/store/store-hook' |
| 5 | +import { useDispatch } from '../editor/store/dispatch-context' |
| 6 | +import { updatePropertyControlsInfo } from '../editor/actions/action-creators' |
4 | 7 |
|
5 | 8 | export const PropertyControlsExportedForTestInspection: { current: PropertyControlsInfo } = { |
6 | 9 | current: {}, |
@@ -31,14 +34,18 @@ function emitChange() { |
31 | 34 | } |
32 | 35 |
|
33 | 36 | export function usePropertyControlsInfo(): PropertyControlsInfo { |
34 | | - const override = useEditorState( |
35 | | - Substores.restOfEditor, |
36 | | - (store) => store.editor.propertyControlsInfoOverride, |
37 | | - 'usePropertyControlsInfo override', |
38 | | - ) |
39 | | - |
40 | 37 | // TODO don't forget about DefaultThirdPartyControlDefinitions |
41 | | - const defaultControls = DefaultThirdPartyControlDefinitions |
| 38 | + return React.useSyncExternalStore(propControlsStore.subscribe, propControlsStore.getSnapshot) |
| 39 | +} |
| 40 | + |
| 41 | +export function useDispatchWhenPropertyControlsInfoChanges() { |
| 42 | + const dispatch = useDispatch() |
| 43 | + |
| 44 | + const previousPropControls = React.useRef<PropertyControlsInfo | null>(null) |
| 45 | + const propControls = usePropertyControlsInfo() |
| 46 | + if (previousPropControls.current !== propControls) { |
| 47 | + dispatch([updatePropertyControlsInfo(propControls)]) |
| 48 | + } |
42 | 49 |
|
43 | | - return override ?? (null as any) |
| 50 | + previousPropControls.current = propControls |
44 | 51 | } |
0 commit comments