|
105 | 105 | /* metaService: engine.setting.styles.ClassNamesContainer-index */ |
106 | 106 | import { computed, reactive, ref, nextTick, watch, watchEffect } from 'vue' |
107 | 107 | import { Select as TinySelect } from '@opentiny/vue' |
108 | | -import { useProperties, useCanvas, useHistory, useHelp } from '@opentiny/tiny-engine-meta-register' |
| 108 | +import { useProperties, useCanvas, useHistory, useHelp, getMergeMeta } from '@opentiny/tiny-engine-meta-register' |
109 | 109 | import { LinkButton } from '@opentiny/tiny-engine-common' |
| 110 | +import { formatString } from '@opentiny/tiny-engine-common/js/ast' |
110 | 111 | import { CodeConfigurator } from '@opentiny/tiny-engine-configurator' |
111 | 112 | import useStyle, { updateGlobalStyleStr } from '../../js/useStyle' |
112 | 113 | import { stringify, getSelectorArr, parser } from '../../js/parser' |
@@ -448,16 +449,25 @@ watchEffect(() => { |
448 | 449 | }) |
449 | 450 |
|
450 | 451 | const save = ({ content }) => { |
451 | | - const { styleObject } = parser(content) |
452 | | - const cssObject = {} |
453 | | - Object.keys(styleObject).forEach((styleKey) => { |
454 | | - cssObject[styleKey] = styleObject[styleKey].rules |
455 | | - }) |
| 452 | + const enableStructuredCss = getMergeMeta('engine.config')?.enableStructuredCss |
| 453 | + let cssData = null |
| 454 | +
|
| 455 | + if (enableStructuredCss) { |
| 456 | + const { styleObject } = parser(content) |
| 457 | + const cssObject = {} |
| 458 | + Object.keys(styleObject).forEach((styleKey) => { |
| 459 | + cssObject[styleKey] = styleObject[styleKey].rules |
| 460 | + }) |
| 461 | + cssData = cssObject |
| 462 | + } else { |
| 463 | + cssData = formatString(content.replace(/"/g, "'"), 'css') |
| 464 | + } |
| 465 | +
|
456 | 466 | const { addHistory } = useHistory() |
457 | 467 | const { updateRect } = useCanvas().canvasApi.value |
458 | 468 | const { updateSchema } = useCanvas() |
459 | 469 |
|
460 | | - updateSchema({ css: cssObject }) |
| 470 | + updateSchema({ css: cssData }) |
461 | 471 | state.schemaUpdateKey++ |
462 | 472 | addHistory() |
463 | 473 | updateRect() |
|
0 commit comments