perf: 提高编辑器性能 (#9413) (#9418)

This commit is contained in:
liaoxuezhi 2024-01-12 15:33:02 +08:00 committed by GitHub
parent 37a0f5e09f
commit b313e11263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 158 additions and 22 deletions

View File

@ -310,8 +310,16 @@ function AMISRenderer({
}
// 根据环境覆盖 schema这个要在最前面做不然就无法覆盖 validations
schema = envOverwrite(schema, locale);
schema = replaceText(schema, options.replaceText, env.replaceTextIgnoreKeys);
schema = React.useMemo(() => {
schema = envOverwrite(schema, locale);
// todo 和 envOverwrite 一起处理,减少循环次数
schema = replaceText(
schema,
options.replaceText,
env.replaceTextIgnoreKeys
);
return schema;
}, [schema, locale]);
return (
<EnvContext.Provider value={env}>

View File

@ -794,15 +794,16 @@ export function wrapControl<
}
getValue() {
const {formStore: data, $schema: control} = this.props;
const {formStore, data, $schema: control} = this.props;
let value: any = this.model ? this.model.tmpValue : control.value;
if (control.pipeIn) {
value = callStrFunction.call(
this,
control.pipeIn,
['value', 'data'],
['value', 'store', 'data'],
value,
formStore,
data
);
}

View File

@ -133,6 +133,7 @@ export const MainStore = types
id: 'root',
label: 'Root'
}),
map: types.optional(types.frozen(), {}),
theme: 'cxd', // 主题默认cxd主题
hoverId: '',
hoverRegion: '',
@ -388,26 +389,29 @@ export const MainStore = types
id: string,
regionOrType?: string
): EditorNodeType | undefined {
let pool = self.root.children.concat();
const key = id + (regionOrType ? '-' + regionOrType : '');
return self.map[key];
while (pool.length) {
const item = pool.shift();
if (
item.id === id &&
(!regionOrType ||
item.region === regionOrType ||
item.type === regionOrType)
) {
return item;
}
// let pool = self.root.children.concat();
// 将当前节点的子节点全部放置到 pool中
if (item.children.length) {
pool.push.apply(pool, item.children);
}
}
// while (pool.length) {
// const item = pool.shift();
// if (
// item.id === id &&
// (!regionOrType ||
// item.region === regionOrType ||
// item.type === regionOrType)
// ) {
// return item;
// }
return undefined;
// // 将当前节点的子节点全部放置到 pool中
// if (item.children.length) {
// pool.push.apply(pool, item.children);
// }
// }
// return undefined;
},
get activeNodeInfo(): RendererInfo | null | undefined {
@ -1054,6 +1058,33 @@ export const MainStore = types
);
return {
setNode(node: EditorNodeType) {
const map = {...self.map};
if (node.region) {
map[node.id + '-' + node.region] = node;
} else {
map[node.id] = node;
map[node.id + '-' + node.type] = node;
}
self.map = map;
},
unsetNode(node: EditorNodeType) {
const map = {...self.map};
if (node.region) {
map[node.id + '-' + node.region] === node &&
delete map[node.id + '-' + node.region];
} else {
map[node.id] === node && delete map[node.id];
map[node.id + '-' + node.type] === node &&
delete map[node.id + '-' + node.type];
}
self.map = map;
},
setLayer(value: any) {
layer = value;
},
@ -1953,6 +1984,7 @@ export const MainStore = types
},
beforeDestroy() {
self.map = {};
lazyUpdateTargetName.cancel();
}
};

View File

@ -614,11 +614,17 @@ export const EditorNode = types
});
const node = self.children[self.children.length - 1];
node.setInfo(props.info);
(getRoot(self) as any).setNode(node);
return node;
},
removeChild(child: any) {
const idx = self.children.findIndex(item => item === child);
const node = self.children[idx];
if (!node) {
return;
}
(getRoot(self) as any).unsetNode(node);
self.children.splice(idx, 1);
},

View File

@ -742,7 +742,7 @@ export class TablePlugin extends BasePlugin {
}));
} else {
// 只取10条预览否则太多卡顿
props.value = arr.slice(0, 10);
props.value = arr.slice(0, 3);
}
// 编辑模式,不允许表格调整宽度

89
publish.sh Normal file
View File

@ -0,0 +1,89 @@
#!/bin/bash
publish_type=$1
version=$2
tag=$3
npm run version -- $version --no-git-tag-version --force-publish --yes
rm -rf npm
npm run build --workspace=amis-editor --workspace=amis-editor-core --workspace=amis-formula --workspace=amis-core --workspace=amis-ui --workspace=amis
mkdir -p npm/packages
cp -r packages/{amis-formula,amis-core,amis-ui,amis,amis-editor,amis-editor-core} npm/packages
cp package.json npm
# # 记录last commit便于区分内网版本包之间的差异
REVISION=revision.json
npm run revision -- $REVISION
if [ -f "$REVISION" ]; then
for dir in $(find ./npm/packages -mindepth 1 -maxdepth 1 -type d); do
[ -d "$dir" ] && cp $REVISION "$dir/$REVISION";
done;
else
echo "$REVISION not exists."
fi
cd npm
if [ "$publish_type" == "internal" ]; then
echo "处理文件内容中……"
# package.json 里面把包名称换了
for f in $(find ./packages -name "package.json"); do
sed -i '' -e 's/\"name\": \"amis/\"name\": \"@fex\/amis/g' $f
sed -i '' -e 's/\"amis-/\"@fex\/amis-/g' $f
sed -i '' -e 's/\"amis\":/\"@fex\/amis\":/g' $f
sed -i '' -e 's/\"i18n-runtime\":/\"@fex\/i18n-runtime\":/g' $f
done
for f in $(find ./packages/*/esm ./packages/*/lib -type f -name "*.[tj]s"); do
echo $f
sed -i '' -e "s#'\(amis\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-formula\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-formula\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-core\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-core\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-ui\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-ui\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-editor\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-editor\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-editor-core\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-editor-core\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-editor-comp\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-editor-comp\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-theme-editor\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-theme-editor\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-postcss\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-postcss\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(amis-theme-editor-helper\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(amis-theme-editor-helper\)\(['\"/]\)#\"@fex\/\1\2#g" $f
sed -i '' -e "s#'\(i18n-runtime\)\(['\"/]\)#'@fex\/\1\2#g" $f
sed -i '' -e "s#\"\(i18n-runtime\)\(['\"/]\)#\"@fex\/\1\2#g" $f
done
echo "正在发版……"
npm publish --tag=$tag --workspaces --registry=http://registry.npm.baidu-int.com --ignore-scripts
else
echo "正在发版……"
npm publish --tag=$tag --workspaces --ignore-scripts
fi
cd ..
rm -rf npm