@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,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Disposable, Emitter } from '@flowgram-vue/utils';
|
|
7
|
+
import { ConfigEntity, EntityOpts } from '../../../common';
|
|
8
|
+
import type { PlaygroundConfigEntity } from './playground-config-entity';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 编辑态
|
|
12
|
+
*/
|
|
13
|
+
export interface EditorState {
|
|
14
|
+
id: string;
|
|
15
|
+
disabled?: boolean | ((config: PlaygroundConfigEntity) => boolean);
|
|
16
|
+
cursor?: string; // 光标类型
|
|
17
|
+
shortcut?: string; // 快捷键
|
|
18
|
+
shortcutAutoEsc?: boolean; // 点击快捷键后自动退出到默认
|
|
19
|
+
// 仅在状态发生变化时,当前快捷键才会生效
|
|
20
|
+
shortcutWorksOnlyOnStateChanged?: boolean;
|
|
21
|
+
handle?: (config: PlaygroundConfigEntity, e?: EditorStateChangeEvent) => void; // 触发逻辑
|
|
22
|
+
disableSelector?: boolean; // 切换后会把选择器隐藏了
|
|
23
|
+
cancelMode:
|
|
24
|
+
| 'esc' // 按住 esc 则退
|
|
25
|
+
| 'once' // 触发一次后则退出
|
|
26
|
+
| 'hold' // 点击会保持该状态
|
|
27
|
+
onEsc?: (config: PlaygroundConfigEntity, e?: KeyboardEvent) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export namespace EditorState {
|
|
31
|
+
export const STATE_SELECT: EditorState = {
|
|
32
|
+
id: 'STATE_SELECT',
|
|
33
|
+
cursor: '',
|
|
34
|
+
shortcut: '',
|
|
35
|
+
cancelMode: 'hold',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** 鼠标友好模式状态 */
|
|
39
|
+
export const STATE_MOUSE_FRIENDLY_SELECT: EditorState = {
|
|
40
|
+
id: 'STATE_MOUSE_FRIENDLY_SELECT',
|
|
41
|
+
cursor: 'grab', // 初始为小手状态
|
|
42
|
+
shortcut: '',
|
|
43
|
+
cancelMode: 'hold',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const STATE_GRAB: EditorState = {
|
|
47
|
+
id: 'STATE_GRAB',
|
|
48
|
+
cursor: 'grab',
|
|
49
|
+
shortcut: 'SPACE', // 如果是鼠标模式,这里不用按住 SPACE 就可以拖动
|
|
50
|
+
shortcutAutoEsc: true,
|
|
51
|
+
shortcutWorksOnlyOnStateChanged: true,
|
|
52
|
+
cancelMode: 'hold',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export const EDITOR_STATE_DEFAULTS: EditorState[] = [
|
|
56
|
+
EditorState.STATE_SELECT,
|
|
57
|
+
EditorState.STATE_MOUSE_FRIENDLY_SELECT,
|
|
58
|
+
EditorState.STATE_GRAB,
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
export interface EditorStateChangeEvent {
|
|
62
|
+
state: EditorState;
|
|
63
|
+
event?: MouseEvent;
|
|
64
|
+
lastState?: EditorState;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 编辑状态管理
|
|
69
|
+
*/
|
|
70
|
+
export class EditorStateConfigEntity extends ConfigEntity {
|
|
71
|
+
static type = 'EditorStateConfigEntity';
|
|
72
|
+
|
|
73
|
+
private _isPressingSpaceBar: boolean = false;
|
|
74
|
+
private _isPressingShift: boolean = false;
|
|
75
|
+
|
|
76
|
+
protected states = EDITOR_STATE_DEFAULTS.slice();
|
|
77
|
+
|
|
78
|
+
protected selected: string = EditorState.STATE_SELECT.id;
|
|
79
|
+
|
|
80
|
+
protected onStateChangeEmitter = new Emitter<EditorStateChangeEvent>();
|
|
81
|
+
|
|
82
|
+
readonly onStateChange = this.onStateChangeEmitter.event;
|
|
83
|
+
|
|
84
|
+
constructor(opts: EntityOpts) {
|
|
85
|
+
super(opts);
|
|
86
|
+
this.toDispose.push(this.onStateChangeEmitter);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get isPressingSpaceBar(): boolean {
|
|
90
|
+
return this._isPressingSpaceBar;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
set isPressingSpaceBar(isPressing: boolean) {
|
|
94
|
+
this._isPressingSpaceBar = isPressing;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get isPressingShift(): boolean {
|
|
98
|
+
return this._isPressingShift;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
set isPressingShift(isPressing: boolean) {
|
|
102
|
+
this._isPressingShift = isPressing;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 取消指定状态后触发
|
|
107
|
+
* @param stateId
|
|
108
|
+
* @param fn
|
|
109
|
+
*/
|
|
110
|
+
onCancel(stateId: string, fn: () => void): Disposable {
|
|
111
|
+
return this.onStateChange(e => {
|
|
112
|
+
if (e.lastState && e.lastState.id === stateId) {
|
|
113
|
+
fn();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
getCurrentState(): EditorState | undefined {
|
|
119
|
+
return this.states.find(s => s.id === this.selected);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
is(stateId: string): boolean {
|
|
123
|
+
return this.selected === stateId;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
changeState(stateId: string, event?: MouseEvent): void {
|
|
127
|
+
const state = this.states.find(s => s.id === stateId);
|
|
128
|
+
if (!state) throw new Error(`Unknown editor state ${stateId}`);
|
|
129
|
+
if (this.selected !== stateId) {
|
|
130
|
+
const lastState = this.getCurrentState();
|
|
131
|
+
this.selected = stateId;
|
|
132
|
+
this.onStateChangeEmitter.fire({ state, event, lastState });
|
|
133
|
+
this.fireChange();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
toDefaultState(): void {
|
|
138
|
+
this.changeState(EditorState.STATE_SELECT.id);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
registerState(state: EditorState): void {
|
|
142
|
+
this.states.push(state);
|
|
143
|
+
// this.sortStates();
|
|
144
|
+
this.fireChange();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getStates(): EditorState[] {
|
|
148
|
+
return this.states;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 是否为鼠标友好模式
|
|
153
|
+
*/
|
|
154
|
+
isMouseFriendlyMode(): boolean {
|
|
155
|
+
return this.getCurrentState() === EditorState.STATE_MOUSE_FRIENDLY_SELECT;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
getStateFromShortcut(e: KeyboardEvent): EditorState | undefined {
|
|
160
|
+
return this.states.find(s => {
|
|
161
|
+
const shortcut =
|
|
162
|
+
s.shortcut === 'SPACE' ? ' ' : (s.shortcut || '').toLowerCase();
|
|
163
|
+
if (shortcut === e.key.toLowerCase()) {
|
|
164
|
+
return s;
|
|
165
|
+
// switch (e.key.toLowerCase()) {
|
|
166
|
+
// case '=':
|
|
167
|
+
// case '-':
|
|
168
|
+
// case '0':
|
|
169
|
+
// if (e.ctrlKey) {
|
|
170
|
+
// return s;
|
|
171
|
+
// }
|
|
172
|
+
// break;
|
|
173
|
+
// default:
|
|
174
|
+
// return s;
|
|
175
|
+
// }
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|