mirror of
https://github.com/Powerful-517/yys-editor.git
synced 2026-03-05 15:05:27 +00:00
fix: 修复节点无法缩放的问题
- 修改 normalizeNodeModel 优先使用 model 的实际尺寸而不是 props - 移除 width/height 变化检查,避免覆盖用户的手动缩放操作 - 在 setProperties 时强制保持 model 的当前尺寸 - 修改 useNodeAppearance 优先使用 node 的实际尺寸 - 移除 applyStyleToModel 调用,尺寸由 LogicFlow 控制
This commit is contained in:
@@ -159,12 +159,13 @@ function applyMetaToModel(model: BaseNodeModel, metaInput?: Record<string, any>)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function applyStyleToModel(model: BaseNodeModel, styleInput?: Record<string, any>) {
|
function applyStyleToModel(model: BaseNodeModel, styleInput?: Record<string, any>) {
|
||||||
const style = normalizeNodeStyle(styleInput, { width: model.width, height: model.height });
|
// 只有当 style 中明确指定了 width/height 时才更新 model
|
||||||
if (style.width && model.width !== style.width) {
|
// 避免用默认值覆盖用户的手动缩放操作
|
||||||
model.width = style.width;
|
if (styleInput?.width != null && model.width !== styleInput.width) {
|
||||||
|
model.width = styleInput.width;
|
||||||
}
|
}
|
||||||
if (style.height && model.height !== style.height) {
|
if (styleInput?.height != null && model.height !== styleInput.height) {
|
||||||
model.height = style.height;
|
model.height = styleInput.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,25 +175,33 @@ function normalizeNodeModel(model: BaseNodeModel) {
|
|||||||
|
|
||||||
const props = (model.getProperties?.() as any) ?? (model as any)?.properties ?? {};
|
const props = (model.getProperties?.() as any) ?? (model as any)?.properties ?? {};
|
||||||
const incomingMeta = ensureMeta(props.meta);
|
const incomingMeta = ensureMeta(props.meta);
|
||||||
|
|
||||||
|
// 优先使用 model 的实际尺寸(用户可能刚刚手动缩放了节点)
|
||||||
const normalized = normalizePropertiesWithStyle(
|
const normalized = normalizePropertiesWithStyle(
|
||||||
{ ...props, meta: incomingMeta },
|
{ ...props, meta: incomingMeta },
|
||||||
{ width: props.width ?? model.width, height: props.height ?? model.height }
|
{ width: model.width, height: model.height }
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentMeta = ensureMeta((model as any)?.properties?.meta);
|
const currentMeta = ensureMeta((model as any)?.properties?.meta);
|
||||||
const metaChanged =
|
const metaChanged =
|
||||||
currentMeta.visible !== incomingMeta.visible ||
|
currentMeta.visible !== incomingMeta.visible ||
|
||||||
currentMeta.locked !== incomingMeta.locked ||
|
currentMeta.locked !== incomingMeta.locked ||
|
||||||
currentMeta.groupId !== incomingMeta.groupId;
|
currentMeta.groupId !== incomingMeta.groupId;
|
||||||
const styleChanged =
|
|
||||||
!styleEquals(props.style, normalized.style) ||
|
// 只检查 style 的其他属性变化,不检查 width/height
|
||||||
props.width !== normalized.width ||
|
// 因为 width/height 应该由 LogicFlow 的缩放控制,而不是由 properties 控制
|
||||||
props.height !== normalized.height;
|
const styleChanged = !styleEquals(props.style, normalized.style);
|
||||||
|
|
||||||
if (metaChanged || styleChanged) {
|
if (metaChanged || styleChanged) {
|
||||||
lfInstance.setProperties(model.id, normalized);
|
// 同步 style 到 properties,但保持 width/height 与 model 一致
|
||||||
|
lfInstance.setProperties(model.id, {
|
||||||
|
...normalized,
|
||||||
|
width: model.width,
|
||||||
|
height: model.height
|
||||||
|
});
|
||||||
}
|
}
|
||||||
applyMetaToModel(model, normalized.meta);
|
applyMetaToModel(model, normalized.meta);
|
||||||
applyStyleToModel(model, normalized.style);
|
// 不再调用 applyStyleToModel,因为 width/height 应该由 LogicFlow 控制
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeAllNodes() {
|
function normalizeAllNodes() {
|
||||||
|
|||||||
@@ -12,9 +12,13 @@ export function useNodeAppearance(options?: { onPropsChange?: PropsChangeHandler
|
|||||||
|
|
||||||
const syncFromProps = (props?: any, node?: any) => {
|
const syncFromProps = (props?: any, node?: any) => {
|
||||||
const target = props ?? node?.properties ?? {};
|
const target = props ?? node?.properties ?? {};
|
||||||
|
// 优先使用 node 的实际尺寸,因为用户缩放时 node.width/height 会先更新
|
||||||
|
const currentWidth = node?.width ?? target.width;
|
||||||
|
const currentHeight = node?.height ?? target.height;
|
||||||
|
|
||||||
style.value = normalizeNodeStyle(target.style, {
|
style.value = normalizeNodeStyle(target.style, {
|
||||||
width: target.width ?? node?.width,
|
width: currentWidth,
|
||||||
height: target.height ?? node?.height
|
height: currentHeight
|
||||||
});
|
});
|
||||||
options?.onPropsChange?.(target, node);
|
options?.onPropsChange?.(target, node);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user