@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
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowgram-vue/core",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://flowgram.ai/",
|
|
7
|
+
"repository": "https://github.com/Crayon-hua/flowgram-vue",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@phosphor/messaging": "^1.3.0",
|
|
24
|
+
"@tweenjs/tween.js": "^18",
|
|
25
|
+
"inversify": "^6.0.1",
|
|
26
|
+
"lodash-es": "^4.17.21",
|
|
27
|
+
"nanoid": "^5.0.9",
|
|
28
|
+
"reflect-metadata": "~0.2.2",
|
|
29
|
+
"@flowgram-vue/command": "0.2.0",
|
|
30
|
+
"@flowgram-vue/utils": "0.2.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"vue": "^3.3.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/lodash-es": "^4.17.12",
|
|
37
|
+
"@types/node": "^20",
|
|
38
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
39
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
40
|
+
"@vue/test-utils": "^2.4.6",
|
|
41
|
+
"eslint": "^9.0.0",
|
|
42
|
+
"jsdom": "^26.1.0",
|
|
43
|
+
"typescript": "^5.8.3",
|
|
44
|
+
"vitest": "^3.2.4",
|
|
45
|
+
"vue": "^3.5.18",
|
|
46
|
+
"@flowgram-vue/eslint-config": "0.2.0",
|
|
47
|
+
"@flowgram-vue/build-config": "0.2.0",
|
|
48
|
+
"@flowgram-vue/ts-config": "0.2.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"registry": "https://registry.npmjs.org/"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "flowgram-build",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"lint": "eslint .",
|
|
58
|
+
"ts-check": "tsc --noEmit",
|
|
59
|
+
"type-check": "tsc --noEmit",
|
|
60
|
+
"build:fast": "flowgram-build --fast",
|
|
61
|
+
"build:watch": "flowgram-build --watch"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { type Disposable } from '@flowgram-vue/utils';
|
|
7
|
+
|
|
8
|
+
import type { EntityDataRegistry } from './entity-data';
|
|
9
|
+
import { EntityData } from './entity-data';
|
|
10
|
+
import { Entity, type EntityOpts } from './entity';
|
|
11
|
+
|
|
12
|
+
export interface ConfigEntityProps {}
|
|
13
|
+
|
|
14
|
+
// let version = 0
|
|
15
|
+
|
|
16
|
+
export function createConfigDataRegistry<P>(entity: ConfigEntity<any>): EntityDataRegistry {
|
|
17
|
+
class ConfigData extends EntityData<P> {
|
|
18
|
+
getDefaultData(): P {
|
|
19
|
+
return entity.getDefaultConfig();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
checkChanged(newProps: Partial<P>): boolean {
|
|
23
|
+
return entity.checkChanged(this.data, newProps);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
toJSON(): object {
|
|
27
|
+
return super.toJSON();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Object.defineProperty(ConfigData, 'type', {
|
|
32
|
+
value: `_${entity.type}DataMixin`,
|
|
33
|
+
// value: `_${entity.type}DataMixin_${version++}`,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return ConfigData as any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 用于专门的数据配置,且是单例
|
|
41
|
+
*/
|
|
42
|
+
export class ConfigEntity<
|
|
43
|
+
P extends ConfigEntityProps = ConfigEntityProps,
|
|
44
|
+
O extends EntityOpts = EntityOpts,
|
|
45
|
+
> extends Entity<O> {
|
|
46
|
+
static type = 'ConfigEntity';
|
|
47
|
+
|
|
48
|
+
protected ConfigDataRegistry: EntityDataRegistry;
|
|
49
|
+
|
|
50
|
+
constructor(opts: O) {
|
|
51
|
+
super(opts);
|
|
52
|
+
this.isInitialized = true;
|
|
53
|
+
this.ConfigDataRegistry = createConfigDataRegistry<P>(this);
|
|
54
|
+
this.addData(this.ConfigDataRegistry);
|
|
55
|
+
this.isInitialized = false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getDefaultConfig(): P {
|
|
59
|
+
return {} as P;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 判断 config 数据是否变化
|
|
64
|
+
*/
|
|
65
|
+
checkChanged(oldData: P, newData: Partial<P>): boolean {
|
|
66
|
+
return Entity.checkDataChanged(oldData, newData);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get config(): P {
|
|
70
|
+
return this.getData(this.ConfigDataRegistry)!.data as P;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
updateConfig(props: Partial<P>): void {
|
|
74
|
+
this.updateData(this.ConfigDataRegistry, props);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onConfigChanged(fn: (data: P) => void): Disposable {
|
|
78
|
+
return this.getData<EntityData>(this.ConfigDataRegistry)!.onDataChange(d => fn(d.data as P));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Compare, DisposableImpl, Emitter } from '@flowgram-vue/utils';
|
|
7
|
+
|
|
8
|
+
import { Entity } from './entity';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 实体的数据块
|
|
12
|
+
*/
|
|
13
|
+
export abstract class EntityData<
|
|
14
|
+
DATA = any | number | string,
|
|
15
|
+
OPTS extends {} = {},
|
|
16
|
+
> extends DisposableImpl {
|
|
17
|
+
static type = 'EntityData';
|
|
18
|
+
|
|
19
|
+
protected onDataChangeEmitter = new Emitter<EntityData<DATA, OPTS>>();
|
|
20
|
+
|
|
21
|
+
protected onWillChangeEmitter = new Emitter<EntityData<DATA, OPTS>>();
|
|
22
|
+
|
|
23
|
+
protected _data: DATA;
|
|
24
|
+
|
|
25
|
+
private _changeLocked = false;
|
|
26
|
+
|
|
27
|
+
protected _version = 0;
|
|
28
|
+
|
|
29
|
+
declare entity: Entity;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 修改后触发
|
|
33
|
+
*/
|
|
34
|
+
readonly onDataChange = this.onDataChangeEmitter.event;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 修改前触发
|
|
38
|
+
*/
|
|
39
|
+
readonly onWillChange = this.onWillChangeEmitter.event;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 初始化数据
|
|
43
|
+
*/
|
|
44
|
+
abstract getDefaultData(): DATA;
|
|
45
|
+
|
|
46
|
+
constructor(entity: Entity, readonly opts?: OPTS) {
|
|
47
|
+
super();
|
|
48
|
+
this.entity = entity;
|
|
49
|
+
this._data = this.getDefaultData();
|
|
50
|
+
this.toDispose.push(this.onDataChangeEmitter);
|
|
51
|
+
this.toDispose.push(this.onWillChangeEmitter);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* data 类型
|
|
56
|
+
*/
|
|
57
|
+
get type(): string {
|
|
58
|
+
if (!(this.constructor as any).type) {
|
|
59
|
+
throw new Error(`Entity Data Registry need a type: ${this.constructor.name}`);
|
|
60
|
+
}
|
|
61
|
+
return (this.constructor as any).type;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 当前数据
|
|
66
|
+
*/
|
|
67
|
+
get data(): DATA {
|
|
68
|
+
return this._data;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 更新单个数据
|
|
73
|
+
*/
|
|
74
|
+
update(props: Partial<DATA> | keyof DATA | DATA, value?: any): void {
|
|
75
|
+
if (arguments.length === 2) {
|
|
76
|
+
if (this._data[props as keyof DATA] !== value) {
|
|
77
|
+
this.fireWillChange();
|
|
78
|
+
this._data[props as keyof DATA] = value;
|
|
79
|
+
this.fireChange();
|
|
80
|
+
}
|
|
81
|
+
} else if (this.checkChanged(props as Partial<DATA>)) {
|
|
82
|
+
this.fireWillChange();
|
|
83
|
+
if (typeof props !== 'object') {
|
|
84
|
+
this._data = props as any;
|
|
85
|
+
} else {
|
|
86
|
+
this._data = { ...this._data, ...(props as Partial<DATA>) };
|
|
87
|
+
}
|
|
88
|
+
this.fireChange();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 更新全量数据
|
|
94
|
+
* @param props
|
|
95
|
+
*/
|
|
96
|
+
fullyUpdate(props: DATA): void {
|
|
97
|
+
// 仅做一层的全量比较
|
|
98
|
+
if (Compare.isChanged(this._data, props, 1, false)) {
|
|
99
|
+
this.fireWillChange();
|
|
100
|
+
this._data = props;
|
|
101
|
+
this.fireChange();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated
|
|
107
|
+
* 检测属性是否更改,默认采用浅比较
|
|
108
|
+
*/
|
|
109
|
+
checkChanged(newProps: Partial<DATA> | DATA): boolean {
|
|
110
|
+
return Entity.checkDataChanged(this._data, newProps);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 存储数据,一般在关闭浏览器后需要暂时存到 localStorage
|
|
115
|
+
*/
|
|
116
|
+
toJSON(): any {
|
|
117
|
+
return this.data as any;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 还原数据
|
|
122
|
+
*/
|
|
123
|
+
fromJSON(data: object): void {
|
|
124
|
+
this.update(data);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get changeLocked(): boolean {
|
|
128
|
+
return this._changeLocked;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
set changeLocked(p) {
|
|
132
|
+
this._changeLocked = p;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fireWillChange(): void {
|
|
136
|
+
this.onWillChangeEmitter.fire(this as EntityData<DATA, OPTS>);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
fireChange(): void {
|
|
140
|
+
if (this._changeLocked) return;
|
|
141
|
+
this._version++;
|
|
142
|
+
/* istanbul ignore next */
|
|
143
|
+
if (this._version >= Number.MAX_SAFE_INTEGER) {
|
|
144
|
+
this._version = 0;
|
|
145
|
+
}
|
|
146
|
+
this.onDataChangeEmitter.fire(this as EntityData<DATA, OPTS>);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected bindChange(data: EntityData, fn?: () => void): void {
|
|
150
|
+
this.toDispose.push(
|
|
151
|
+
data.onDataChange(() => {
|
|
152
|
+
if (fn) fn();
|
|
153
|
+
this.fireChange();
|
|
154
|
+
}),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get version() {
|
|
159
|
+
return this._version;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export type EntityDataProps<E extends EntityData> = E['data'];
|
|
164
|
+
|
|
165
|
+
export interface EntityDataRegistry<E extends EntityData = EntityData> {
|
|
166
|
+
new (...args: any[]): E;
|
|
167
|
+
|
|
168
|
+
type: E['type'];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type EntityDataInjector = <OPTS extends {} = {}>() => OPTS;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { type EntityManager } from './entity-manager';
|
|
7
|
+
|
|
8
|
+
export const EntityManagerContribution = Symbol('EntityManagerContribution');
|
|
9
|
+
|
|
10
|
+
export interface EntityManagerContribution {
|
|
11
|
+
registerEntityManager(entityManager: EntityManager): void;
|
|
12
|
+
}
|