@@ -4,7 +4,7 @@ import * as jsonpatch from 'fast-json-patch'
44import { utils } from '@opentiny/tiny-engine-utils'
55import { useCanvas , useHistory } from '@opentiny/tiny-engine-meta-register'
66import useRobot from '../js/useRobot'
7- // import SvgICons from '@opentiny/vue-icon'
7+ import SvgICons from '@opentiny/vue-icon'
88
99const { string2Obj, reactiveObj2String : obj2String } = utils
1010import { useThrottleFn } from '@vueuse/core'
@@ -20,11 +20,22 @@ const setSchema = async (schema: object) => {
2020 setSaved ( false )
2121}
2222
23+ const fixInvalidIconComponent = ( data : any ) => {
24+ if ( data . componentName === 'Icon' && data . props ?. name && ! SvgICons [ data . props . name as keyof typeof SvgICons ] ) {
25+ data . props . name = 'IconWarning'
26+ }
27+
28+ if ( data . children && Array . isArray ( data . children ) ) {
29+ data . children . forEach ( ( child : any ) => fixInvalidIconComponent ( child ) )
30+ }
31+ }
32+
2333const updateStreamCanvasPageSchema = ( streamContent : string , currentPageSchema : object ) => {
2434 try {
2535 const repaired = jsonrepair ( streamContent )
2636 const parsedJson = JSON . parse ( repaired )
2737 const result = parsedJson . reduce ( ( acc : object , patch : any ) => {
38+ fixInvalidIconComponent ( patch . value )
2839 return jsonpatch . applyPatch ( acc , [ patch ] , false , false ) . newDocument
2940 } , currentPageSchema )
3041 const editorValue = string2Obj ( obj2String ( result ) )
@@ -60,8 +71,8 @@ export const updateCanvasPageSchema = (streamContent: string, currentJson: objec
6071 try {
6172 const schemaPatch = JSON . parse ( content )
6273 if ( isValidFastJsonPatch ( schemaPatch ) ) {
63- // const result = schemaPatch.reduce(jsonpatch.applyReducer, currentJson)
6474 const result = schemaPatch . reduce ( ( acc : object , patch : any ) => {
75+ fixInvalidIconComponent ( patch . value )
6576 return jsonpatch . applyPatch ( acc , [ patch ] , false , false ) . newDocument
6677 } , currentJson )
6778 setSchema ( result )
0 commit comments