fix: 修复工作流节点交互与旧浏览器兼容
- 修复 Tinyflow Vue wrapper 可选 boolean 默认关闭节点拖拽和连线的问题 - 为 Tinyflow 增加 structuredClone 兼容与 Chrome 90 构建目标 - 增加节点交互归一化与 Tab 空值防御
This commit is contained in:
22
easyflow-ui-admin/packages/tinyflow-ui/src/utils/compat.ts
Normal file
22
easyflow-ui-admin/packages/tinyflow-ui/src/utils/compat.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
type StructuredCloneFallback = <T>(value: T) => T;
|
||||
|
||||
/**
|
||||
* Installs browser compatibility shims required by Tinyflow.
|
||||
*/
|
||||
export function installTinyflowBrowserCompat() {
|
||||
if (
|
||||
typeof globalThis.structuredClone === 'function' ||
|
||||
typeof JSON === 'undefined'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fallback: StructuredCloneFallback = (value) =>
|
||||
value == null ? value : JSON.parse(JSON.stringify(value));
|
||||
|
||||
Object.defineProperty(globalThis, 'structuredClone', {
|
||||
configurable: true,
|
||||
value: fallback,
|
||||
writable: true,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import type { Node } from '@xyflow/svelte';
|
||||
import type { CustomNode, TinyflowOptions } from '../types';
|
||||
|
||||
export const DEFAULT_NODE_DRAG_HANDLE = '.tf-node-drag-handle';
|
||||
|
||||
export type TinyflowNodeNormalizer = (node: Node) => Node;
|
||||
|
||||
function shouldUseDefaultDragHandle(
|
||||
node: Node,
|
||||
customNodes?: Record<string, CustomNode>,
|
||||
) {
|
||||
if (Object.prototype.hasOwnProperty.call(node, 'dragHandle')) {
|
||||
return false;
|
||||
}
|
||||
const customNode = node.type ? customNodes?.[node.type] : undefined;
|
||||
return customNode?.presentation !== 'plain';
|
||||
}
|
||||
|
||||
export function createTinyflowNodeNormalizer(
|
||||
options?: TinyflowOptions,
|
||||
): TinyflowNodeNormalizer {
|
||||
const readonly = options?.readonly === true;
|
||||
const nodesDraggable = options?.nodesDraggable ?? !readonly;
|
||||
const nodesConnectable = options?.nodesConnectable ?? !readonly;
|
||||
const elementsSelectable = options?.elementsSelectable ?? !readonly;
|
||||
|
||||
return (node) => {
|
||||
const nextNode = { ...node };
|
||||
|
||||
if (nodesDraggable) {
|
||||
if (nextNode.draggable === false) {
|
||||
delete nextNode.draggable;
|
||||
}
|
||||
if (shouldUseDefaultDragHandle(nextNode, options?.customNodes)) {
|
||||
nextNode.dragHandle = DEFAULT_NODE_DRAG_HANDLE;
|
||||
}
|
||||
} else {
|
||||
nextNode.draggable = false;
|
||||
}
|
||||
|
||||
if (nodesConnectable) {
|
||||
if (nextNode.connectable === false) {
|
||||
delete nextNode.connectable;
|
||||
}
|
||||
} else {
|
||||
nextNode.connectable = false;
|
||||
}
|
||||
|
||||
if (elementsSelectable) {
|
||||
if (nextNode.selectable === false) {
|
||||
delete nextNode.selectable;
|
||||
}
|
||||
} else {
|
||||
nextNode.selectable = false;
|
||||
}
|
||||
|
||||
return nextNode;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user