@@ -79,6 +79,8 @@ const canvasStore = useCanvasStore();
7979const component = ref <HTMLElement | InstanceType <typeof TextBlock > | null >(null );
8080const attrs = useAttrs ();
8181const editor = ref <InstanceType <typeof BlockEditor > | null >(null );
82+ const isMounted = ref (false );
83+
8284const pageStore = usePageStore ();
8385const blockDataStore = useBlockDataStore ();
8486const blockUidStore = useBlockUidStore ();
@@ -179,7 +181,7 @@ const attributes = computed(() => {
179181 }
180182
181183 Object .keys (additionalAttributes ).forEach ((key ) => {
182- if (! RESTRICTED_ATTRIBS .includes (key )) {
184+ if (RESTRICTED_ATTRIBS .includes (key )) {
183185 delete additionalAttributes [key ];
184186 }
185187 });
@@ -219,13 +221,7 @@ const attributes = computed(() => {
219221 if (props .block .getDataKey (" type" ) === " attribute" ) {
220222 let value;
221223 if (props .block .getDataKey (" comesFrom" ) === " props" ) {
222- value = getPropValue (
223- props .block .getDataKey (" key" ) as string ,
224- props .block ,
225- getDataScriptValue ,
226- getBlockDataScriptValue ,
227- props .defaultProps ,
228- );
224+ value = getPropValue (props .block .getDataKey (" key" ) as string , props .block , uidToUse );
229225 } else if (props .block .getDataKey (" comesFrom" ) === " blockDataScript" ) {
230226 value = getBlockDataScriptValue (props .block .getDataKey (" key" ) as string );
231227 } else {
@@ -243,13 +239,7 @@ const attributes = computed(() => {
243239 const property = dataKeyObj .property as string ;
244240 let value;
245241 if (dataKeyObj .comesFrom === " props" ) {
246- value = getPropValue (
247- dataKeyObj .key as string ,
248- props .block ,
249- getDataScriptValue ,
250- getBlockDataScriptValue ,
251- props .defaultProps ,
252- );
242+ value = getPropValue (dataKeyObj .key as string , props .block , uidToUse );
253243 } else if (dataKeyObj .comesFrom === " blockDataScript" ) {
254244 value = getBlockDataScriptValue (dataKeyObj .key as string );
255245 } else {
@@ -283,13 +273,7 @@ const styles = computed(() => {
283273 if (props .block .getDataKey (" type" ) === " style" ) {
284274 let value;
285275 if (props .block .getDataKey (" comesFrom" ) === " props" ) {
286- value = getPropValue (
287- props .block .getDataKey (" key" ) as string ,
288- props .block ,
289- getDataScriptValue ,
290- getBlockDataScriptValue ,
291- props .defaultProps ,
292- );
276+ value = getPropValue (props .block .getDataKey (" key" ) as string , props .block , uidToUse );
293277 } else if (props .block .getDataKey (" comesFrom" ) === " blockDataScript" ) {
294278 value = getBlockDataScriptValue (props .block .getDataKey (" key" ) as string );
295279 } else {
@@ -308,13 +292,7 @@ const styles = computed(() => {
308292 const property = dataKeyObj .property as string ;
309293 let value;
310294 if (dataKeyObj .comesFrom === " props" ) {
311- value = getPropValue (
312- dataKeyObj .key as string ,
313- props .block ,
314- getDataScriptValue ,
315- getBlockDataScriptValue ,
316- props .defaultProps ,
317- );
295+ value = getPropValue (dataKeyObj .key as string , props .block , uidToUse );
318296 } else if (dataKeyObj .comesFrom === " blockDataScript" ) {
319297 value = getBlockDataScriptValue (dataKeyObj .key as string );
320298 } else {
@@ -396,31 +374,34 @@ onMounted(async () => {
396374 }
397375 blockUidStore .registerBlockUid (uidToUse , props .block );
398376 blockUidStore .setParentUid (uidToUse , props .parentBlockUid || " root" );
377+ isMounted .value = true ;
399378});
400379
401380const allResolvedProps = computed (() => {
381+ if (! isMounted .value ) {
382+ return {};
383+ }
384+ const defaultProps = Object .entries (props .defaultProps || {}).reduce ((acc , [key , value ]) => {
385+ acc [key ] = value .value ;
386+ return acc ;
387+ }, {} as Record <string , any >);
388+
389+ const blockProps = Object .entries ({
390+ ... props .block .getBlockProps (),
391+ }).reduce ((acc , [key ]) => {
392+ acc [key ] = getPropValue (key , props .block , uidToUse );
393+ return acc ;
394+ }, {} as Record <string , any >);
395+
396+ const parentProps = Object .entries (getParentProps (props .block , uidToUse )).reduce ((acc , [key , value ]) => {
397+ acc [key ] = getPropValue (key , value .block ! , value .blockUid );
398+ return acc ;
399+ }, {} as Record <string , any >);
400+
402401 return {
403- ... Object .fromEntries (
404- Object .entries (props .defaultProps || {}).map (([key , value ]) => {
405- return [key , value .value ];
406- }),
407- ),
408- ... Object .fromEntries (
409- Object .entries ({ ... props .block .getBlockProps (), ... getParentProps (props .block ) }).map (
410- ([key , prop ]) => {
411- return [
412- key ,
413- getPropValue (
414- key ,
415- props .block ,
416- getDataScriptValue ,
417- (path : string ) => getDataForKey ({ ... props .blockData }, path ), // block props can not refer to own block data items
418- props .defaultProps ,
419- ),
420- ];
421- },
422- ),
423- ),
402+ ... parentProps ,
403+ ... blockProps ,
404+ ... defaultProps ,
424405 };
425406});
426407
@@ -497,12 +478,18 @@ watch(
497478 });
498479 });
499480 },
500- { immediate: true },
481+ { immediate: true , deep: true },
501482);
502483
503484watchEffect (() => {
504- blockDataStore .setPageData (uidToUse , props .data || {});
505485 blockDataStore .setBlockData (uidToUse , props .blockData || {}, " passedDown" );
486+ });
487+
488+ watchEffect (() => {
489+ blockDataStore .setPageData (uidToUse , props .data || {});
490+ });
491+
492+ watchEffect (() => {
506493 blockDataStore .setBlockDefaultProps (uidToUse , props .defaultProps || {});
507494});
508495
@@ -526,13 +513,7 @@ const hiddenDueToVisibilityCondition = computed(() => {
526513 const value = getDataScriptValue (key as string );
527514 return ! Boolean (value );
528515 } else {
529- const value = getPropValue (
530- key as string ,
531- props .block ,
532- getDataScriptValue ,
533- getBlockDataScriptValue ,
534- props .defaultProps ,
535- );
516+ const value = getPropValue (key as string , props .block , uidToUse );
536517 return ! Boolean (value );
537518 }
538519});
0 commit comments