@@ -109,7 +109,7 @@ import { useProperties, useCanvas, useHistory, useHelp } from '@opentiny/tiny-en
109109import { LinkButton } from ' @opentiny/tiny-engine-common'
110110import { CodeConfigurator } from ' @opentiny/tiny-engine-configurator'
111111import useStyle , { updateGlobalStyleStr } from ' ../../js/useStyle'
112- import { stringify , getSelectorArr , parser } from ' ../../js/parser'
112+ import { stringify , getSelectorArr , buildCssObjectFromContent } from ' ../../js/parser'
113113
114114const { getSchema , propsUpdateKey , setProp } = useProperties ()
115115
@@ -448,29 +448,7 @@ watchEffect(() => {
448448})
449449
450450const save = ({ content }) => {
451- const { parseList, styleObject } = parser(content)
452- const cssObject = {}
453-
454- // 保证存入 cssObject 的键值顺序与编辑器中的源码字符顺序一致
455- parseList.forEach((item) => {
456- // parser 中的 handleRules 没有给普通 rule 赋 type 属性,只具备 selectors 和 style
457- if (!item.type && item.selectors) {
458- if (styleObject[item.selectors]) {
459- cssObject[item.selectors] = styleObject[item.selectors].rules
460- }
461- } else if (item.type === 'atrule') {
462- const rawValue = item.style?.value || ''
463- const braceIdx = rawValue.indexOf('{')
464- const key = braceIdx !== -1 ? rawValue.slice(0, braceIdx).trim() : rawValue.trim()
465- const value = braceIdx !== -1 ? rawValue.slice(braceIdx).trim() : ''
466-
467- if (cssObject[key] !== undefined) {
468- cssObject[key] = Array.isArray(cssObject[key]) ? [...cssObject[key], value] : [cssObject[key], value]
469- } else {
470- cssObject[key] = value
471- }
472- }
473- })
451+ const cssObject = buildCssObjectFromContent(content)
474452
475453 const { addHistory } = useHistory()
476454 const { updateRect } = useCanvas().canvasApi.value
0 commit comments