@flowgram-vue/core 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/dist/index.cjs +0 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +0 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
- package/src/common/config-entity.ts +80 -0
- package/src/common/entity-data.ts +171 -0
- package/src/common/entity-manager-contribution.ts +12 -0
- package/src/common/entity-manager.ts +475 -0
- package/src/common/entity.ts +482 -0
- package/src/common/index.ts +22 -0
- package/src/common/playground-context.ts +35 -0
- package/src/common/playground-decorator-helper.ts +113 -0
- package/src/common/playground-decorators.ts +85 -0
- package/src/common/playground-schedule.ts +30 -0
- package/src/common/protect-wheel-area.ts +11 -0
- package/src/common/schema/index.ts +14 -0
- package/src/common/schema/node.ts +15 -0
- package/src/common/schema/opacity-schema.ts +19 -0
- package/src/common/schema/origin-schema.ts +35 -0
- package/src/common/schema/position-schema.ts +35 -0
- package/src/common/schema/rotation-schema.ts +19 -0
- package/src/common/schema/scale-schema.ts +35 -0
- package/src/common/schema/size-schema.ts +42 -0
- package/src/common/schema/skew-schema.ts +35 -0
- package/src/common/schema/transform-schema.ts +613 -0
- package/src/common/utils/bounds.spec.ts +229 -0
- package/src/common/utils/bounds.ts +176 -0
- package/src/common/utils/index.ts +6 -0
- package/src/composables/index.ts +16 -0
- package/src/composables/use-config-entity.ts +31 -0
- package/src/composables/use-entities.ts +26 -0
- package/src/composables/use-entity-data-from-context.ts +34 -0
- package/src/composables/use-entity-from-context.ts +31 -0
- package/src/composables/use-listen-events.ts +22 -0
- package/src/composables/use-playground-container.ts +16 -0
- package/src/composables/use-playground-context.ts +15 -0
- package/src/composables/use-playground-drag.ts +31 -0
- package/src/composables/use-playground.ts +16 -0
- package/src/composables/use-refresh.ts +6 -0
- package/src/composables/use-service.ts +17 -0
- package/src/core/index.ts +8 -0
- package/src/core/layer/config/editor-state-config-entity.ts +180 -0
- package/src/core/layer/config/index.ts +7 -0
- package/src/core/layer/config/playground-config-entity.ts +604 -0
- package/src/core/layer/index.ts +8 -0
- package/src/core/layer/layer.ts +248 -0
- package/src/core/layer/playground-layer.ts +547 -0
- package/src/core/pipeline/index.ts +10 -0
- package/src/core/pipeline/pipeline-entities-selector.ts +200 -0
- package/src/core/pipeline/pipeline-entities.ts +230 -0
- package/src/core/pipeline/pipeline-registry.ts +344 -0
- package/src/core/pipeline/pipeline-renderer.ts +248 -0
- package/src/core/pipeline/pipeline-vue-utils.ts +96 -0
- package/src/core/pipeline/pipeline.ts +28 -0
- package/src/core/utils/index.ts +12 -0
- package/src/core/utils/inject-provider-decorators.ts +27 -0
- package/src/core/utils/lazy-inject-decorators.ts +38 -0
- package/src/core/utils/mouse-touch-event.ts +120 -0
- package/src/core/utils/playground-drag.ts +511 -0
- package/src/core/utils/playground-gesture.spec.ts +135 -0
- package/src/core/utils/playground-gesture.ts +118 -0
- package/src/core/utils/tween.ts +156 -0
- package/src/core/utils/use-gesture/core/Controller.ts +212 -0
- package/src/core/utils/use-gesture/core/EventStore.ts +46 -0
- package/src/core/utils/use-gesture/core/TimeoutStore.ts +28 -0
- package/src/core/utils/use-gesture/core/actions.ts +63 -0
- package/src/core/utils/use-gesture/core/config/commonConfigResolver.ts +86 -0
- package/src/core/utils/use-gesture/core/config/coordinatesConfigResolver.ts +48 -0
- package/src/core/utils/use-gesture/core/config/dragConfigResolver.ts +140 -0
- package/src/core/utils/use-gesture/core/config/hoverConfigResolver.ts +11 -0
- package/src/core/utils/use-gesture/core/config/moveConfigResolver.ts +11 -0
- package/src/core/utils/use-gesture/core/config/pinchConfigResolver.ts +59 -0
- package/src/core/utils/use-gesture/core/config/resolver.ts +70 -0
- package/src/core/utils/use-gesture/core/config/scrollConfigResolver.ts +8 -0
- package/src/core/utils/use-gesture/core/config/sharedConfigResolver.ts +28 -0
- package/src/core/utils/use-gesture/core/config/support.ts +52 -0
- package/src/core/utils/use-gesture/core/config/wheelConfigResolver.ts +8 -0
- package/src/core/utils/use-gesture/core/engines/CoordinatesEngine.ts +78 -0
- package/src/core/utils/use-gesture/core/engines/DragEngine.ts +403 -0
- package/src/core/utils/use-gesture/core/engines/Engine.ts +406 -0
- package/src/core/utils/use-gesture/core/engines/HoverEngine.ts +43 -0
- package/src/core/utils/use-gesture/core/engines/MoveEngine.ts +52 -0
- package/src/core/utils/use-gesture/core/engines/PinchEngine.ts +345 -0
- package/src/core/utils/use-gesture/core/engines/ScrollEngine.ts +42 -0
- package/src/core/utils/use-gesture/core/engines/WheelEngine.ts +48 -0
- package/src/core/utils/use-gesture/core/index.ts +7 -0
- package/src/core/utils/use-gesture/core/parser.ts +92 -0
- package/src/core/utils/use-gesture/core/types/action.ts +19 -0
- package/src/core/utils/use-gesture/core/types/config.ts +255 -0
- package/src/core/utils/use-gesture/core/types/handlers.ts +73 -0
- package/src/core/utils/use-gesture/core/types/index.ts +11 -0
- package/src/core/utils/use-gesture/core/types/internalConfig.ts +80 -0
- package/src/core/utils/use-gesture/core/types/state.ts +275 -0
- package/src/core/utils/use-gesture/core/types/utils.ts +204 -0
- package/src/core/utils/use-gesture/core/types.ts +8 -0
- package/src/core/utils/use-gesture/core/utils/events.ts +158 -0
- package/src/core/utils/use-gesture/core/utils/fn.ts +32 -0
- package/src/core/utils/use-gesture/core/utils/maths.ts +63 -0
- package/src/core/utils/use-gesture/core/utils/state.ts +24 -0
- package/src/core/utils/use-gesture/core/utils.ts +8 -0
- package/src/core/utils/use-gesture/index.ts +6 -0
- package/src/core/utils/use-gesture/vanilla/DragGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/Gesture.ts +45 -0
- package/src/core/utils/use-gesture/vanilla/HoverGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/MoveGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/PinchGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/Recognizer.ts +43 -0
- package/src/core/utils/use-gesture/vanilla/ScrollGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/WheelGesture.ts +27 -0
- package/src/core/utils/use-gesture/vanilla/createGesture.ts +18 -0
- package/src/core/utils/use-gesture/vanilla/index.ts +18 -0
- package/src/env.d.ts +10 -0
- package/src/index.ts +17 -0
- package/src/playground-config.ts +70 -0
- package/src/playground-container.ts +129 -0
- package/src/playground-contribution.ts +81 -0
- package/src/playground-mock-tools.ts +143 -0
- package/src/playground.ts +401 -0
- package/src/plugin/index.ts +6 -0
- package/src/plugin/plugin.ts +226 -0
- package/src/services/clipboard-service.ts +40 -0
- package/src/services/context-menu-service.ts +25 -0
- package/src/services/index.ts +10 -0
- package/src/services/logger-service.ts +49 -0
- package/src/services/selection-service.ts +54 -0
- package/src/services/storage-service.ts +65 -0
- package/src/vue/index.ts +8 -0
- package/src/vue/playground-vue-context.ts +22 -0
- package/src/vue/playground-vue-provider.ts +115 -0
- package/src/vue/playground-vue-renderer.vue +44 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { inject, injectable } from 'inversify';
|
|
7
|
+
import type { Component, VNode } from 'vue';
|
|
8
|
+
import {
|
|
9
|
+
type CacheManager,
|
|
10
|
+
type Disposable,
|
|
11
|
+
DisposableCollection,
|
|
12
|
+
type DOMCache,
|
|
13
|
+
domUtils,
|
|
14
|
+
} from '@flowgram-vue/utils';
|
|
15
|
+
|
|
16
|
+
// import { Adsorber } from '../utils/adsorber';
|
|
17
|
+
// import { PlaygroundDrag, type PlaygroundDragEntitiesOpts } from '../utils';
|
|
18
|
+
import { type PipelineEntities } from '../pipeline/pipeline-entities';
|
|
19
|
+
import { type PipeEventName, type PipelineDimension, type PipeSupportEvent } from '../pipeline';
|
|
20
|
+
import {
|
|
21
|
+
EntityManager,
|
|
22
|
+
injectPlaygroundContext,
|
|
23
|
+
PlaygroundContext,
|
|
24
|
+
type PositionSchema,
|
|
25
|
+
} from '../../common';
|
|
26
|
+
// import { SelectionService } from '@flowgram-vue/application-common';
|
|
27
|
+
import { type PlaygroundConfigEntity } from './config';
|
|
28
|
+
|
|
29
|
+
export interface LayerOptions {}
|
|
30
|
+
|
|
31
|
+
export const LayerOptions = Symbol('LayerOptions');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 基础 layer
|
|
35
|
+
*/
|
|
36
|
+
@injectable()
|
|
37
|
+
export class Layer<
|
|
38
|
+
OPT extends LayerOptions = any,
|
|
39
|
+
CONTEXT extends PlaygroundContext = PlaygroundContext
|
|
40
|
+
> {
|
|
41
|
+
/**
|
|
42
|
+
* layer 的配置, 由 registerLayer(Layer, LayerOptions) 传入
|
|
43
|
+
*/
|
|
44
|
+
@inject(LayerOptions) options: OPT;
|
|
45
|
+
|
|
46
|
+
protected readonly toDispose = new DisposableCollection();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* layer 可能存在 dom 也可能没有,如果有,则会加入到 pipeline 的 dom 节点上
|
|
50
|
+
*/
|
|
51
|
+
node: HTMLElement;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 父节点
|
|
55
|
+
*/
|
|
56
|
+
pipelineNode: HTMLElement;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 画布根节点
|
|
60
|
+
*/
|
|
61
|
+
playgroundNode: HTMLElement;
|
|
62
|
+
|
|
63
|
+
// /**
|
|
64
|
+
// * 发送 payload
|
|
65
|
+
// * @param payloadKey
|
|
66
|
+
// * @param payloadValue
|
|
67
|
+
// * @param cb - layer 触发 autorun 后的回调
|
|
68
|
+
// */
|
|
69
|
+
// dispatch<P>(payloadKey: string | symbol, payloadValue: P, cb?: () => void): void {}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 当前 layer 的所有监听的实体数据
|
|
73
|
+
*/
|
|
74
|
+
observeManager: PipelineEntities;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 实体管理器
|
|
78
|
+
*/
|
|
79
|
+
@inject(EntityManager) readonly entityManager: EntityManager;
|
|
80
|
+
|
|
81
|
+
@injectPlaygroundContext() readonly context: CONTEXT;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 自动触发更新,在不需要 Vue 渲染的时候用这个方法
|
|
85
|
+
*/
|
|
86
|
+
autorun?(): void;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 绘制 Vue 组件或 VNode
|
|
90
|
+
*/
|
|
91
|
+
render?(): Component | VNode | null;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 默认每个 Layer 独立 createApp 隔离更新,这种情况就需要数据驱动刷新
|
|
95
|
+
*/
|
|
96
|
+
renderWithVueMemo = true;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 全局选择
|
|
100
|
+
*/
|
|
101
|
+
// selectionService?: SelectionService;
|
|
102
|
+
/**
|
|
103
|
+
* 监听 playground 上的事件
|
|
104
|
+
* 规则:
|
|
105
|
+
* 1. 按 priority 排序,越高先执行
|
|
106
|
+
* 2. 没有提供,按 layer 的注册顺序,后注册先执行 (符合冒泡排序)
|
|
107
|
+
* 3. 执行返回 true,则阻止后续的执行
|
|
108
|
+
*/
|
|
109
|
+
listenPlaygroundEvent: (
|
|
110
|
+
name: PipeEventName,
|
|
111
|
+
handle: (event: PipeSupportEvent) => boolean | void,
|
|
112
|
+
priority?: number,
|
|
113
|
+
options?: AddEventListenerOptions
|
|
114
|
+
) => Disposable;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 监听 document 上的事件
|
|
118
|
+
* 规则:
|
|
119
|
+
* 1. 按 priority 排序,越高先执行
|
|
120
|
+
* 2. 没有提供,按 layer 的注册顺序,后注册先执行 (符合冒泡排序)
|
|
121
|
+
* 3. 执行返回 true,则阻止后续的执行
|
|
122
|
+
*/
|
|
123
|
+
listenGlobalEvent: (
|
|
124
|
+
name: PipeEventName,
|
|
125
|
+
handle: (event: PipeSupportEvent) => boolean | void,
|
|
126
|
+
priority?: number,
|
|
127
|
+
options?: AddEventListenerOptions
|
|
128
|
+
) => Disposable;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* 初始化时候触发
|
|
132
|
+
*/
|
|
133
|
+
onReady?(): void;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* playground 大小变化时候会触发
|
|
137
|
+
*/
|
|
138
|
+
onResize?(size: PipelineDimension): void;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* playground focus 时候触发
|
|
142
|
+
*/
|
|
143
|
+
onFocus?(): void;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* playground blur 时候触发
|
|
147
|
+
*/
|
|
148
|
+
onBlur?(): void;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 监听缩放
|
|
152
|
+
*/
|
|
153
|
+
onZoom?(zoom: number): void;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 监听滚动
|
|
157
|
+
*/
|
|
158
|
+
onScroll?(scroll: { scrollX: number; scrollY: number }): void;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* viewport 更新触发
|
|
162
|
+
*/
|
|
163
|
+
onViewportChange?(): void;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* readonly 或 disable 状态变化
|
|
167
|
+
* @param state
|
|
168
|
+
*/
|
|
169
|
+
onReadonlyOrDisabledChange?(state: { disabled: boolean; readonly: boolean }): void;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* playground 是否 focused
|
|
173
|
+
*/
|
|
174
|
+
readonly isFocused: boolean;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 销毁
|
|
178
|
+
*/
|
|
179
|
+
dispose(): void {
|
|
180
|
+
this.toDispose.dispose();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 创建 dom 缓冲池
|
|
185
|
+
* @param className
|
|
186
|
+
*/
|
|
187
|
+
createDOMCache<T extends DOMCache>(
|
|
188
|
+
className: string | (() => HTMLElement),
|
|
189
|
+
children?: string
|
|
190
|
+
): CacheManager<T> {
|
|
191
|
+
if (!this.node) throw new Error('DomCache need a parent dom node.');
|
|
192
|
+
return domUtils.createDOMCache<T>(this.node, className, children);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 加载 layer 注册的实体数据,内部使用,不需要手动触发
|
|
197
|
+
* @return 数据是否变化
|
|
198
|
+
*/
|
|
199
|
+
declare reloadEntities: () => boolean;
|
|
200
|
+
|
|
201
|
+
// /**
|
|
202
|
+
// * 在画布上拖动实体
|
|
203
|
+
// */
|
|
204
|
+
// startDrag<T>(
|
|
205
|
+
// clientX: number,
|
|
206
|
+
// clientY: number,
|
|
207
|
+
// opts: PlaygroundDragEntitiesOpts<T> = {},
|
|
208
|
+
// ): Disposable {
|
|
209
|
+
// const adsorbRefs = Adsorber.getRefsFromEntities(
|
|
210
|
+
// this.entityManager,
|
|
211
|
+
// opts.entities || [],
|
|
212
|
+
// this.config,
|
|
213
|
+
// );
|
|
214
|
+
// return PlaygroundDrag.startDrag(clientX, clientY, {
|
|
215
|
+
// ...opts,
|
|
216
|
+
// adsorbRefs,
|
|
217
|
+
// config: this.config,
|
|
218
|
+
// });
|
|
219
|
+
// }
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 全局画布配置
|
|
223
|
+
*/
|
|
224
|
+
config: PlaygroundConfigEntity;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 获取鼠标在 Playground 的位置
|
|
228
|
+
*/
|
|
229
|
+
getPosFromMouseEvent(
|
|
230
|
+
event: { clientX: number; clientY: number },
|
|
231
|
+
addScale = true
|
|
232
|
+
): PositionSchema {
|
|
233
|
+
const pos = this.config.getPosFromMouseEvent(event, addScale);
|
|
234
|
+
return {
|
|
235
|
+
x: pos.x,
|
|
236
|
+
y: pos.y,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 可以用于获取别的 layer
|
|
242
|
+
*/
|
|
243
|
+
getOtherLayer: <T extends Layer>(layerRegistry: LayerRegistry<T>) => T | undefined;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface LayerRegistry<P extends Layer = Layer> {
|
|
247
|
+
new (): P;
|
|
248
|
+
}
|