File tree Expand file tree Collapse file tree 3 files changed +33
-33
lines changed
show/components/fields/text Expand file tree Collapse file tree 3 files changed +33
-33
lines changed Original file line number Diff line number Diff line change 1010 </script >
1111<script lang="ts" setup>
1212 import { computed } from ' vue' ;
13+ import type { Component } from ' vue' ;
1314
1415 const props = defineProps <{
15- templateData? : Record <string , any >,
16- templateProps? : string [],
1716 template: string ,
17+ components? : Record <string , Component >,
1818 }>();
1919
2020 const component = computed (() => ({
21- components ,
22- template: ` <div class="SharpTemplate">${props .template ?? ' ' }</div> ` ,
23- props: [
24- ... (props .templateProps || []),
25- ... Object .keys (props .templateData ?? {}),
26- ],
21+ components: {
22+ ... components ,
23+ ... props .components ,
24+ },
25+ template: ` <div data-sharp-template>${sanitizeForVue (props .template ?? ' ' )}</div> ` ,
2726 }));
27+
28+ function sanitizeForVue(template : string ) {
29+ return template .replaceAll (' {{' , ' {{' ).replaceAll (' }}' , ' }}' );
30+ }
2831 </script >
2932
3033<template >
31- <component :is =" component" v-bind = " templateData ?? {} " >
34+ <component :is =" component" >
3235 <slot />
3336 </component >
3437</template >
Original file line number Diff line number Diff line change 44 import Html from " @/show/components/fields/text/nodes/Html.vue" ;
55 import { ShowTextFieldData } from " @/types" ;
66 import Embed from " @/show/components/fields/text/nodes/Embed.vue" ;
7- import { components } from ' @/components/TemplateRenderer.vue' ;
7+ import TemplateRenderer from ' @/components/TemplateRenderer.vue' ;
88
99 const props = defineProps <{
1010 field: ShowTextFieldData ,
2121 dom .content .removeChild (htmlNode );
2222 });
2323 return dom .innerHTML ;
24- })
24+ });
2525
26- const component = computed <Component >(() => ({
27- template: ` <div>${formattedContent .value }</div> ` ,
28- components: {
29- ... components ,
30- ' x-sharp-file' : File ,
31- ' x-sharp-image' : File ,
32- ' html-content' : Html ,
33- ... Object .fromEntries (
34- Object .entries (props .field .embeds ?? {})
35- .map (([embedKey , embed ]) => [
36- embed .tag ,
37- {
38- template: ' <Embed :embed="embed" v-bind="$attrs"></Embed>' ,
39- components: { Embed },
40- data : () => ({ embed }),
41- }
42- ])
43- ),
44- },
26+ const components = computed (() => ({
27+ ' x-sharp-file' : File ,
28+ ' x-sharp-image' : File ,
29+ ' html-content' : Html ,
30+ ... Object .fromEntries (
31+ Object .entries (props .field .embeds ?? {})
32+ .map (([embedKey , embed ]) => [
33+ embed .tag ,
34+ {
35+ template: ' <Embed :embed="embed" v-bind="$attrs"></Embed>' ,
36+ components: { Embed },
37+ data : () => ({ embed }),
38+ }
39+ ])
40+ ),
4541 }));
4642 </script >
4743
4844<template >
49- <component :is = " component " />
45+ <TemplateRenderer :template = " formattedContent " :components = " components " />
5046</template >
51-
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ export function sanitize(html: string | null) {
66 ADD_TAGS : [ 'iframe' ] ,
77 CUSTOM_ELEMENT_HANDLING : {
88 tagNameCheck : ( ) => true ,
9- attributeNameCheck : ( ) => true ,
9+ attributeNameCheck : ( name ) => {
10+ return ! name . match ( / ^ ( v - ) | : | @ | # / ) ; // remove vue related attributes
11+ } ,
1012 } ,
1113 } )
1214 : html ;
You can’t perform that action at this time.
0 commit comments