Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/amis-core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down
5 changes: 3 additions & 2 deletions packages/amis-core/src/renderers/wrapControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
70 changes: 51 additions & 19 deletions packages/amis-editor-core/src/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const MainStore = types
id: 'root',
label: 'Root'
}),
map: types.optional(types.frozen(), {}),
theme: 'cxd', // 主题,默认cxd主题
hoverId: '',
hoverRegion: '',
Expand Down Expand Up @@ -388,26 +389,29 @@ export const MainStore = types
id: string,
regionOrType?: string
): EditorNodeType | undefined {
let pool = self.root.children.concat();

while (pool.length) {
const item = pool.shift();
if (
item.id === id &&
(!regionOrType ||
item.region === regionOrType ||
item.type === regionOrType)
) {
return item;
}

// 将当前节点的子节点全部放置到 pool中
if (item.children.length) {
pool.push.apply(pool, item.children);
}
}
const key = id + (regionOrType ? '-' + regionOrType : '');
return self.map[key];

// let pool = self.root.children.concat();

// while (pool.length) {
// const item = pool.shift();
// if (
// item.id === id &&
// (!regionOrType ||
// item.region === regionOrType ||
// item.type === regionOrType)
// ) {
// return item;
// }

// // 将当前节点的子节点全部放置到 pool中
// if (item.children.length) {
// pool.push.apply(pool, item.children);
// }
// }

return undefined;
// return undefined;
},

get activeNodeInfo(): RendererInfo | null | undefined {
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -1953,6 +1984,7 @@ export const MainStore = types
},

beforeDestroy() {
self.map = {};
lazyUpdateTargetName.cancel();
}
};
Expand Down
6 changes: 6 additions & 0 deletions packages/amis-editor-core/src/store/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

Expand Down
2 changes: 1 addition & 1 deletion packages/amis-editor/src/plugin/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ export class TablePlugin extends BasePlugin {
}));
} else {
// 只取10条预览,否则太多卡顿
props.value = arr.slice(0, 10);
props.value = arr.slice(0, 3);
}

// 编辑模式,不允许表格调整宽度
Expand Down
89 changes: 89 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -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
Loading