@@ -16,13 +16,14 @@ import {
16
16
$registeredComponentMetas ,
17
17
} from "~/shared/nano-states" ;
18
18
import { isRichText } from "~/shared/content-model" ;
19
- import { $selectedInstancePath } from "~/shared/awareness" ;
19
+ import { $selectedInstance , $ selectedInstancePath } from "~/shared/awareness" ;
20
20
import {
21
21
$selectedInstanceInitialPropNames ,
22
22
$selectedInstancePropsMetas ,
23
23
showAttributeMeta ,
24
24
type PropValue ,
25
25
} from "../shared" ;
26
+ import { $instanceTags } from "../../style-panel/shared/model" ;
26
27
27
28
type PropOrName = { prop ?: Prop ; propName : string } ;
28
29
@@ -157,32 +158,41 @@ const $canHaveTextContent = computed(
157
158
}
158
159
) ;
159
160
161
+ const contentModePropertiesByTag : Partial < Record < string , string [ ] > > = {
162
+ img : [ "src" , "width" , "height" , "alt" ] ,
163
+ a : [ "href" ] ,
164
+ } ;
165
+
166
+ const $selectedInstanceTag = computed (
167
+ [ $selectedInstance , $instanceTags ] ,
168
+ ( selectedInstance , instanceTags ) => {
169
+ if ( selectedInstance === undefined ) {
170
+ return ;
171
+ }
172
+ return instanceTags . get ( selectedInstance . id ) ;
173
+ }
174
+ ) ;
175
+
160
176
/** usePropsLogic expects that key={instanceId} is used on the ancestor component */
161
177
export const usePropsLogic = ( {
162
178
instance,
163
179
props,
164
180
updateProp,
165
181
} : UsePropsLogicInput ) => {
166
182
const isContentMode = useStore ( $isContentMode ) ;
183
+ const selectedInstanceTag = useStore ( $selectedInstanceTag ) ;
167
184
168
185
/**
169
186
* In content edit mode we show only Image and Link props
170
187
* In the future I hope the only thing we will show will be Components
171
188
*/
172
189
const isPropVisible = ( propName : string ) => {
173
- const contentModeWhiteList : Partial < Record < string , string [ ] > > = {
174
- Image : [ "src" , "width" , "height" , "alt" ] ,
175
- Link : [ "href" ] ,
176
- RichTextLink : [ "href" ] ,
177
- } ;
178
-
179
190
if ( ! isContentMode ) {
180
191
return true ;
181
192
}
182
-
183
- const propsWhiteList = contentModeWhiteList [ instance . component ] ?? [ ] ;
184
-
185
- return propsWhiteList . includes ( propName ) ;
193
+ const allowedProperties =
194
+ contentModePropertiesByTag [ selectedInstanceTag ?? "" ] ?? [ ] ;
195
+ return allowedProperties . includes ( propName ) ;
186
196
} ;
187
197
188
198
const savedProps = props ;
@@ -231,11 +241,7 @@ export const usePropsLogic = ({
231
241
const initialProps : PropAndMeta [ ] = [ ] ;
232
242
for ( const name of initialPropNames ) {
233
243
const propMeta = propsMetas . get ( name ) ;
234
-
235
244
if ( propMeta === undefined ) {
236
- console . error (
237
- `The prop "${ name } " is defined in meta.initialProps but not in meta.props`
238
- ) ;
239
245
continue ;
240
246
}
241
247
0 commit comments