fix: 修复id不为string类型时,自定义样式报错 (#10396)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
This commit is contained in:
qkiroc 2024-06-11 15:36:09 +08:00 committed by GitHub
parent fb0f64a78f
commit 9da4b43f33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -325,7 +325,7 @@ export function insertCustomStyle(prams: {
let {value} = formatStyle(themeCss, classNames, id, defaultData, data);
value = customStyleClassPrefix ? `${customStyleClassPrefix} ${value}` : value;
let classId = id.replace('u:', '');
let classId = id?.replace?.('u:', '') || id + '';
if (typeof data?.index === 'number') {
classId += `-${data.index}`;
}
@ -385,7 +385,8 @@ export function insertEditCustomStyle(params: {
doc?: Document;
[propName: string]: any;
}) {
const {customStyle, id, doc, data} = params;
const {customStyle, doc, data} = params;
const id = params.id?.replace?.('u:', '') || params.id + '';
let styles: any = {};
traverseStyle(customStyle, '', styles);
@ -395,7 +396,7 @@ export function insertEditCustomStyle(params: {
index = `-${data.index}`;
}
if (!isEmpty(styles)) {
const className = `wrapperCustomStyle-${id?.replace('u:', '')}${index}`;
const className = `wrapperCustomStyle-${id}${index}`;
Object.keys(styles).forEach((key: string) => {
if (!isObject(styles[key])) {
content += `\n.${className} {\n ${key}: ${
@ -451,12 +452,9 @@ export function insertEditCustomStyle(params: {
insertStyle({
style: content,
classId:
'wrapperCustomStyle-' +
((typeof id === 'string' ? id.replace('u:', '') : '') || uuid()) +
index,
classId: 'wrapperCustomStyle-' + (id || uuid()) + index,
doc,
id: typeof id === 'string' ? id.replace('u:', '').replace(/(-.*)/, '') : ''
id: id.replace(/(-.*)/, '')
});
}
@ -478,7 +476,8 @@ export function removeCustomStyle(
doc?: Document,
data?: any
) {
let styleId = 'amis-' + (type ? type + '-' : '') + id.replace('u:', '');
let styleId =
'amis-' + (type ? type + '-' : '') + (id.replace?.('u:', '') || id + '');
if (typeof data?.index === 'number') {
styleId += `-${data.index}`;
}
@ -523,5 +522,9 @@ export function setThemeClassName(params: {
index = `-${data.index}`;
}
return `${name}-${id.replace('u:', '')}` + (extra ? `-${extra}` : '') + index;
return (
`${name}-${id.replace?.('u:', '') || id}` +
(extra ? `-${extra}` : '') +
index
);
}