Skip to content

Commit fa10596

Browse files
committed
fix: invalid icon
1 parent 2420b10 commit fa10596

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/plugins/robot/src/composables/useAgent.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as jsonpatch from 'fast-json-patch'
44
import { utils } from '@opentiny/tiny-engine-utils'
55
import { useCanvas, useHistory } from '@opentiny/tiny-engine-meta-register'
66
import useRobot from '../js/useRobot'
7-
// import SvgICons from '@opentiny/vue-icon'
7+
import SvgICons from '@opentiny/vue-icon'
88

99
const { string2Obj, reactiveObj2String: obj2String } = utils
1010
import { 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+
2333
const 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

Comments
 (0)