@flowgram.ai/playground-react 0.1.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/dist/esm/index.js +224 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +120 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +252 -0
- package/dist/index.js.map +1 -0
- package/index.css +163 -0
- package/package.json +64 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/index.ts
|
|
13
|
+
import "reflect-metadata";
|
|
14
|
+
import { useRefresh, Emitter, Event, Disposable } from "@flowgram.ai/utils";
|
|
15
|
+
export * from "@flowgram.ai/core";
|
|
16
|
+
|
|
17
|
+
// src/hooks/use-playground-tools.ts
|
|
18
|
+
import { useCallback, useEffect, useState } from "react";
|
|
19
|
+
import {
|
|
20
|
+
EditorState,
|
|
21
|
+
EditorStateConfigEntity,
|
|
22
|
+
useConfigEntity,
|
|
23
|
+
usePlayground
|
|
24
|
+
} from "@flowgram.ai/core";
|
|
25
|
+
import { DisposableCollection } from "@flowgram.ai/utils";
|
|
26
|
+
function usePlaygroundTools(props) {
|
|
27
|
+
const { maxZoom = 2, minZoom = 0.25 } = props || {};
|
|
28
|
+
const playground = usePlayground();
|
|
29
|
+
const editorState = useConfigEntity(EditorStateConfigEntity, true);
|
|
30
|
+
const [zoom, setZoom] = useState(1);
|
|
31
|
+
const handleZoomOut = useCallback(
|
|
32
|
+
(easing) => {
|
|
33
|
+
if (zoom < minZoom) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
playground.config.zoomout(easing);
|
|
37
|
+
},
|
|
38
|
+
[zoom, playground, minZoom]
|
|
39
|
+
);
|
|
40
|
+
const handleZoomIn = useCallback(
|
|
41
|
+
(easing) => {
|
|
42
|
+
if (zoom > maxZoom) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
playground.config.zoomin(easing);
|
|
46
|
+
},
|
|
47
|
+
[zoom, playground, maxZoom]
|
|
48
|
+
);
|
|
49
|
+
const handleUpdateZoom = useCallback(
|
|
50
|
+
(value, easing, easingDuration) => {
|
|
51
|
+
playground.config.updateZoom(value, easing, easingDuration);
|
|
52
|
+
},
|
|
53
|
+
[playground]
|
|
54
|
+
);
|
|
55
|
+
const handleToggleIneractiveType = useCallback(() => {
|
|
56
|
+
if (editorState.isMouseFriendlyMode()) {
|
|
57
|
+
editorState.changeState(EditorState.STATE_SELECT.id);
|
|
58
|
+
} else {
|
|
59
|
+
editorState.changeState(EditorState.STATE_MOUSE_FRIENDLY_SELECT.id);
|
|
60
|
+
}
|
|
61
|
+
}, [editorState]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const dispose = new DisposableCollection();
|
|
64
|
+
dispose.push(playground.onZoom((z) => setZoom(z)));
|
|
65
|
+
return () => dispose.dispose();
|
|
66
|
+
}, [playground]);
|
|
67
|
+
return {
|
|
68
|
+
zoomin: handleZoomIn,
|
|
69
|
+
zoomout: handleZoomOut,
|
|
70
|
+
updateZoom: handleUpdateZoom,
|
|
71
|
+
zoom,
|
|
72
|
+
interactiveType: editorState.isMouseFriendlyMode() ? "MOUSE" : "PAD",
|
|
73
|
+
toggleIneractiveType: handleToggleIneractiveType
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/components/playground-react.tsx
|
|
78
|
+
import React2, { useMemo, forwardRef } from "react";
|
|
79
|
+
import {
|
|
80
|
+
createPlaygroundPlugin as createPlaygroundPlugin2,
|
|
81
|
+
PlaygroundReactProvider,
|
|
82
|
+
PlaygroundReactRenderer
|
|
83
|
+
} from "@flowgram.ai/core";
|
|
84
|
+
|
|
85
|
+
// src/preset/playground-react-preset.ts
|
|
86
|
+
import { createShortcutsPlugin } from "@flowgram.ai/shortcuts-plugin";
|
|
87
|
+
import {
|
|
88
|
+
createPlaygroundPlugin,
|
|
89
|
+
PlaygroundConfig,
|
|
90
|
+
PlaygroundLayer
|
|
91
|
+
} from "@flowgram.ai/core";
|
|
92
|
+
import { createBackgroundPlugin } from "@flowgram.ai/background-plugin";
|
|
93
|
+
function createPlaygroundReactPreset(opts, plugins = []) {
|
|
94
|
+
return (ctx) => {
|
|
95
|
+
plugins = plugins.slice();
|
|
96
|
+
if (opts.shortcuts) {
|
|
97
|
+
plugins.push(
|
|
98
|
+
createShortcutsPlugin({
|
|
99
|
+
registerShortcuts: (registry) => opts.shortcuts(registry, ctx)
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (opts.plugins) {
|
|
104
|
+
plugins.push(...opts.plugins(ctx));
|
|
105
|
+
}
|
|
106
|
+
plugins.push(
|
|
107
|
+
createPlaygroundPlugin({
|
|
108
|
+
onBind: (bindConfig) => {
|
|
109
|
+
opts.onBind?.(bindConfig);
|
|
110
|
+
},
|
|
111
|
+
onInit: (ctx2) => {
|
|
112
|
+
const playgroundConfig = ctx2.get(PlaygroundConfig);
|
|
113
|
+
if (opts.playground) {
|
|
114
|
+
if (opts.playground.autoFocus !== void 0) {
|
|
115
|
+
playgroundConfig.autoFocus = opts.playground.autoFocus;
|
|
116
|
+
}
|
|
117
|
+
if (opts.playground.autoResize !== void 0) {
|
|
118
|
+
playgroundConfig.autoResize = opts.playground.autoResize;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
playgroundConfig.autoFocus = false;
|
|
122
|
+
ctx2.playground.registerLayer(PlaygroundLayer, opts.playground);
|
|
123
|
+
if (opts.layers) {
|
|
124
|
+
ctx2.playground.registerLayers(...opts.layers);
|
|
125
|
+
}
|
|
126
|
+
if (opts.onInit) opts.onInit(ctx2);
|
|
127
|
+
},
|
|
128
|
+
onReady(ctx2) {
|
|
129
|
+
if (opts.onReady) opts.onReady(ctx2);
|
|
130
|
+
},
|
|
131
|
+
onAllLayersRendered() {
|
|
132
|
+
if (opts.onAllLayersRendered) opts.onAllLayersRendered(ctx);
|
|
133
|
+
},
|
|
134
|
+
onDispose() {
|
|
135
|
+
if (opts.onDispose) opts.onDispose(ctx);
|
|
136
|
+
},
|
|
137
|
+
containerModules: opts.containerModules || []
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
if (opts.background || opts.background === void 0) {
|
|
141
|
+
plugins.push(createBackgroundPlugin(opts.background || {}));
|
|
142
|
+
}
|
|
143
|
+
return plugins;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/layers/playground-content-layer.tsx
|
|
148
|
+
import React from "react";
|
|
149
|
+
import { injectable } from "inversify";
|
|
150
|
+
import { Layer } from "@flowgram.ai/core";
|
|
151
|
+
import { domUtils } from "@flowgram.ai/utils";
|
|
152
|
+
var PlaygroundContentLayer = class extends Layer {
|
|
153
|
+
constructor() {
|
|
154
|
+
super(...arguments);
|
|
155
|
+
this.node = domUtils.createDivWithClass(
|
|
156
|
+
"gedit-playground-layer gedit-playground-content-layer"
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
onZoom(scale) {
|
|
160
|
+
this.node.style.transform = `scale(${scale})`;
|
|
161
|
+
}
|
|
162
|
+
onReady() {
|
|
163
|
+
this.node.style.left = "0px";
|
|
164
|
+
this.node.style.top = "0px";
|
|
165
|
+
}
|
|
166
|
+
updateOptions(opts) {
|
|
167
|
+
this.options = opts;
|
|
168
|
+
this.render();
|
|
169
|
+
}
|
|
170
|
+
render() {
|
|
171
|
+
return /* @__PURE__ */ React.createElement(
|
|
172
|
+
"div",
|
|
173
|
+
{
|
|
174
|
+
className: this.options.className,
|
|
175
|
+
style: { position: "absolute", ...this.options.style }
|
|
176
|
+
},
|
|
177
|
+
this.options.children
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
PlaygroundContentLayer.type = "PlaygroundContentLayer";
|
|
182
|
+
PlaygroundContentLayer = __decorateClass([
|
|
183
|
+
injectable()
|
|
184
|
+
], PlaygroundContentLayer);
|
|
185
|
+
|
|
186
|
+
// src/components/playground-react.tsx
|
|
187
|
+
var PlaygroundReact = forwardRef(
|
|
188
|
+
function PlaygroundReact2(props, ref) {
|
|
189
|
+
const { parentContainer, children, ...others } = props;
|
|
190
|
+
const contentLoadPlugin = useMemo(
|
|
191
|
+
() => createPlaygroundPlugin2({
|
|
192
|
+
onInit(ctx) {
|
|
193
|
+
ctx.playground.registerLayer(PlaygroundContentLayer);
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
[]
|
|
197
|
+
);
|
|
198
|
+
const preset = useMemo(() => createPlaygroundReactPreset(others, [contentLoadPlugin]), []);
|
|
199
|
+
return /* @__PURE__ */ React2.createElement(PlaygroundReactProvider, { ref, plugins: preset, parentContainer }, /* @__PURE__ */ React2.createElement(PlaygroundReactRenderer, null, children));
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// src/components/playground-react-content.tsx
|
|
204
|
+
import React3, { useMemo as useMemo2 } from "react";
|
|
205
|
+
import { usePlayground as usePlayground2 } from "@flowgram.ai/core";
|
|
206
|
+
var PlaygroundReactContent = (props) => {
|
|
207
|
+
const playground = usePlayground2();
|
|
208
|
+
useMemo2(() => {
|
|
209
|
+
const layer = playground.getLayer(PlaygroundContentLayer);
|
|
210
|
+
layer.updateOptions(props);
|
|
211
|
+
}, [props]);
|
|
212
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null);
|
|
213
|
+
};
|
|
214
|
+
export {
|
|
215
|
+
Disposable,
|
|
216
|
+
Emitter,
|
|
217
|
+
Event,
|
|
218
|
+
PlaygroundReact,
|
|
219
|
+
PlaygroundReactContent,
|
|
220
|
+
createPlaygroundReactPreset,
|
|
221
|
+
usePlaygroundTools,
|
|
222
|
+
useRefresh
|
|
223
|
+
};
|
|
224
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/hooks/use-playground-tools.ts","../../src/components/playground-react.tsx","../../src/preset/playground-react-preset.ts","../../src/layers/playground-content-layer.tsx","../../src/components/playground-react-content.tsx"],"sourcesContent":["import 'reflect-metadata';\n\n/* 核心 模块导出 */\nexport { useRefresh, Emitter, Event, Disposable } from '@flowgram.ai/utils';\nexport * from '@flowgram.ai/core';\n\nexport { usePlaygroundTools } from './hooks';\nexport {\n PlaygroundReact,\n PlaygroundReactContent,\n PlaygroundReactContentProps,\n PlaygroundRef,\n} from './components';\nexport { PlaygroundReactProps, createPlaygroundReactPreset } from './preset';\n","import { useCallback, useEffect, useState } from 'react';\n\nimport {\n EditorState,\n EditorStateConfigEntity,\n PlaygroundInteractiveType,\n useConfigEntity,\n usePlayground,\n} from '@flowgram.ai/core';\nimport { DisposableCollection } from '@flowgram.ai/utils';\n\nexport interface PlaygroundToolsPropsType {\n /**\n * 最大缩放比,默认 2\n */\n maxZoom?: number;\n /**\n * 最小缩放比,默认 0.25\n */\n minZoom?: number;\n}\n\nexport interface PlaygroundTools {\n /**\n * 缩放 zoom 大小比例\n */\n zoom: number;\n /**\n * 放大\n */\n zoomin: (easing?: boolean) => void;\n /**\n * 缩小\n */\n zoomout: (easing?: boolean) => void;\n /**\n * 设置缩放比例\n * @param zoom\n */\n updateZoom: (newZoom: number, easing?: boolean, easingDuration?: number) => void;\n /**\n * 当前的交互模式, 鼠标友好模式 和 触摸板模式\n */\n interactiveType: PlaygroundInteractiveType;\n /**\n * 切换交互模式\n */\n toggleIneractiveType: () => void;\n}\n\nexport function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools {\n const { maxZoom = 2, minZoom = 0.25 } = props || {};\n const playground = usePlayground();\n const editorState = useConfigEntity(EditorStateConfigEntity, true);\n\n const [zoom, setZoom] = useState(1);\n\n const handleZoomOut = useCallback(\n (easing?: boolean) => {\n if (zoom < minZoom) {\n return;\n }\n playground.config.zoomout(easing);\n },\n [zoom, playground, minZoom],\n );\n\n const handleZoomIn = useCallback(\n (easing?: boolean) => {\n if (zoom > maxZoom) {\n return;\n }\n playground.config.zoomin(easing);\n },\n [zoom, playground, maxZoom],\n );\n\n const handleUpdateZoom = useCallback(\n (value: number, easing?: boolean, easingDuration?: number) => {\n playground.config.updateZoom(value, easing, easingDuration);\n },\n [playground],\n );\n\n const handleToggleIneractiveType = useCallback(() => {\n if (editorState.isMouseFriendlyMode()) {\n editorState.changeState(EditorState.STATE_SELECT.id);\n } else {\n editorState.changeState(EditorState.STATE_MOUSE_FRIENDLY_SELECT.id);\n }\n }, [editorState]);\n\n useEffect(() => {\n const dispose = new DisposableCollection();\n dispose.push(playground.onZoom(z => setZoom(z)));\n return () => dispose.dispose();\n }, [playground]);\n\n return {\n zoomin: handleZoomIn,\n zoomout: handleZoomOut,\n updateZoom: handleUpdateZoom,\n zoom,\n interactiveType: editorState.isMouseFriendlyMode() ? 'MOUSE' : 'PAD',\n toggleIneractiveType: handleToggleIneractiveType,\n };\n}\n","import React, { useMemo, forwardRef } from 'react';\n\nimport {\n createPlaygroundPlugin,\n PlaygroundReactProvider,\n PlaygroundReactRenderer,\n PluginContext,\n} from '@flowgram.ai/core';\n\nimport { PlaygroundReactProps, createPlaygroundReactPreset } from '../preset';\nimport { PlaygroundContentLayer } from '../layers/playground-content-layer';\n\nexport type PlaygroundRef = PluginContext;\n\nexport const PlaygroundReact = forwardRef<PlaygroundRef, PlaygroundReactProps>(\n function PlaygroundReact(props, ref) {\n const { parentContainer, children, ...others } = props;\n const contentLoadPlugin = useMemo(\n () =>\n createPlaygroundPlugin({\n onInit(ctx) {\n ctx.playground.registerLayer(PlaygroundContentLayer);\n },\n }),\n [],\n );\n const preset = useMemo(() => createPlaygroundReactPreset(others, [contentLoadPlugin]), []);\n return (\n <PlaygroundReactProvider ref={ref} plugins={preset} parentContainer={parentContainer}>\n <PlaygroundReactRenderer>{children}</PlaygroundReactRenderer>\n </PlaygroundReactProvider>\n );\n },\n);\n","import { createShortcutsPlugin } from '@flowgram.ai/shortcuts-plugin';\nimport {\n PluginContext,\n PluginsProvider,\n Plugin,\n createPlaygroundPlugin,\n PlaygroundConfig,\n PlaygroundLayer,\n} from '@flowgram.ai/core';\nimport { createBackgroundPlugin } from '@flowgram.ai/background-plugin';\n\nimport { PlaygroundReactProps } from './playground-react-props';\n\nexport function createPlaygroundReactPreset<CTX extends PluginContext = PluginContext>(\n opts: PlaygroundReactProps<CTX>,\n plugins: Plugin[] = []\n): PluginsProvider<CTX> {\n return (ctx: CTX) => {\n plugins = plugins.slice();\n /**\n * 注册快捷键\n */\n if (opts.shortcuts) {\n plugins.push(\n createShortcutsPlugin({\n registerShortcuts: (registry) => opts.shortcuts!(registry, ctx),\n })\n );\n }\n /**\n * 注册三方插件\n */\n if (opts.plugins) {\n plugins.push(...opts.plugins(ctx));\n }\n /**\n * 画布生命周期注册\n */\n plugins.push(\n createPlaygroundPlugin<CTX>({\n onBind: (bindConfig) => {\n opts.onBind?.(bindConfig);\n },\n onInit: (ctx) => {\n const playgroundConfig = ctx.get<PlaygroundConfig>(PlaygroundConfig);\n if (opts.playground) {\n if (opts.playground.autoFocus !== undefined) {\n playgroundConfig.autoFocus = opts.playground.autoFocus;\n }\n if (opts.playground.autoResize !== undefined) {\n playgroundConfig.autoResize = opts.playground.autoResize;\n }\n }\n playgroundConfig.autoFocus = false;\n ctx.playground.registerLayer(PlaygroundLayer, opts.playground);\n if (opts.layers) {\n ctx.playground.registerLayers(...opts.layers);\n }\n if (opts.onInit) opts.onInit(ctx);\n },\n onReady(ctx) {\n if (opts.onReady) opts.onReady(ctx);\n },\n onAllLayersRendered() {\n if (opts.onAllLayersRendered) opts.onAllLayersRendered(ctx);\n },\n onDispose() {\n if (opts.onDispose) opts.onDispose(ctx);\n },\n containerModules: opts.containerModules || [],\n })\n );\n\n /**\n * 注册背景 (放最后插入), 默认打开\n */\n if (opts.background || opts.background === undefined) {\n plugins.push(createBackgroundPlugin(opts.background || {}));\n }\n return plugins;\n };\n}\n","import React from 'react';\n\nimport { injectable } from 'inversify';\nimport { Layer } from '@flowgram.ai/core';\nimport { domUtils } from '@flowgram.ai/utils';\n\nexport interface PlaygroundReactContentProps {\n className?: string;\n style?: React.CSSProperties;\n children?: React.ReactNode;\n}\n\n@injectable()\nexport class PlaygroundContentLayer extends Layer<PlaygroundReactContentProps> {\n static type = 'PlaygroundContentLayer';\n\n readonly node = domUtils.createDivWithClass(\n 'gedit-playground-layer gedit-playground-content-layer',\n );\n\n onZoom(scale: number): void {\n this.node.style.transform = `scale(${scale})`;\n }\n\n onReady() {\n this.node.style.left = '0px';\n this.node.style.top = '0px';\n }\n\n updateOptions(opts: PlaygroundReactContentProps) {\n this.options = opts;\n this.render();\n }\n\n render(): JSX.Element {\n return (\n <div\n className={this.options.className}\n style={{ position: 'absolute', ...this.options.style }}\n >\n {this.options.children}\n </div>\n );\n }\n}\n","import React, { useMemo } from 'react';\n\nimport { usePlayground } from '@flowgram.ai/core';\n\nimport {\n PlaygroundContentLayer,\n PlaygroundReactContentProps,\n} from '../layers/playground-content-layer';\n\nexport { PlaygroundReactContentProps };\n\nexport const PlaygroundReactContent: React.FC<PlaygroundReactContentProps> = props => {\n const playground = usePlayground();\n useMemo(() => {\n const layer = playground.getLayer(PlaygroundContentLayer)!;\n layer.updateOptions(props);\n }, [props]);\n return <></>;\n};\n"],"mappings":";;;;;;;;;;;;AAAA,OAAO;AAGP,SAAS,YAAY,SAAS,OAAO,kBAAkB;AACvD,cAAc;;;ACJd,SAAS,aAAa,WAAW,gBAAgB;AAEjD;AAA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UAAM,oBAAoB;AAAA,MACxB,MACEC,wBAAuB;AAAA,QACrB,OAAO,KAAK;AACV,cAAI,WAAW,cAAc,sBAAsB;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AACA,UAAM,SAAS,QAAQ,MAAM,4BAA4B,QAAQ,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;AACzF,WACE,gBAAAC,OAAA,cAAC,2BAAwB,KAAU,SAAS,QAAQ,mBAClD,gBAAAA,OAAA,cAAC,+BAAyB,QAAS,CACrC;AAAA,EAEJ;AACF;;;AGjCA,OAAOC,UAAS,WAAAC,gBAAe;AAE/B,SAAS,iBAAAC,sBAAqB;AASvB,IAAM,yBAAgE,WAAS;AACpF,QAAM,aAAaC,eAAc;AACjC,EAAAC,SAAQ,MAAM;AACZ,UAAM,QAAQ,WAAW,SAAS,sBAAsB;AACxD,UAAM,cAAc,KAAK;AAAA,EAC3B,GAAG,CAAC,KAAK,CAAC;AACV,SAAO,gBAAAC,OAAA,cAAAA,OAAA,cAAE;AACX;","names":["React","createPlaygroundPlugin","ctx","PlaygroundReact","createPlaygroundPlugin","React","React","useMemo","usePlayground","usePlayground","useMemo","React"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export { Disposable, Emitter, Event, useRefresh } from '@flowgram.ai/utils';
|
|
2
|
+
import { PlaygroundInteractiveType, PluginContext, PlaygroundLayerOptions, PluginBindConfig, Plugin, LayerRegistry, PluginsProvider } from '@flowgram.ai/core';
|
|
3
|
+
export * from '@flowgram.ai/core';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { interfaces } from 'inversify';
|
|
6
|
+
import { ShortcutsRegistry } from '@flowgram.ai/shortcuts-plugin';
|
|
7
|
+
import { BackgroundLayerOptions } from '@flowgram.ai/background-plugin';
|
|
8
|
+
|
|
9
|
+
interface PlaygroundToolsPropsType {
|
|
10
|
+
/**
|
|
11
|
+
* 最大缩放比,默认 2
|
|
12
|
+
*/
|
|
13
|
+
maxZoom?: number;
|
|
14
|
+
/**
|
|
15
|
+
* 最小缩放比,默认 0.25
|
|
16
|
+
*/
|
|
17
|
+
minZoom?: number;
|
|
18
|
+
}
|
|
19
|
+
interface PlaygroundTools {
|
|
20
|
+
/**
|
|
21
|
+
* 缩放 zoom 大小比例
|
|
22
|
+
*/
|
|
23
|
+
zoom: number;
|
|
24
|
+
/**
|
|
25
|
+
* 放大
|
|
26
|
+
*/
|
|
27
|
+
zoomin: (easing?: boolean) => void;
|
|
28
|
+
/**
|
|
29
|
+
* 缩小
|
|
30
|
+
*/
|
|
31
|
+
zoomout: (easing?: boolean) => void;
|
|
32
|
+
/**
|
|
33
|
+
* 设置缩放比例
|
|
34
|
+
* @param zoom
|
|
35
|
+
*/
|
|
36
|
+
updateZoom: (newZoom: number, easing?: boolean, easingDuration?: number) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 当前的交互模式, 鼠标友好模式 和 触摸板模式
|
|
39
|
+
*/
|
|
40
|
+
interactiveType: PlaygroundInteractiveType;
|
|
41
|
+
/**
|
|
42
|
+
* 切换交互模式
|
|
43
|
+
*/
|
|
44
|
+
toggleIneractiveType: () => void;
|
|
45
|
+
}
|
|
46
|
+
declare function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 画布配置配置
|
|
50
|
+
*/
|
|
51
|
+
interface PlaygroundReactProps<CTX extends PluginContext = PluginContext> {
|
|
52
|
+
/**
|
|
53
|
+
* 背景开关,默认打开
|
|
54
|
+
*/
|
|
55
|
+
background?: BackgroundLayerOptions | boolean;
|
|
56
|
+
/**
|
|
57
|
+
* 画布相关配置
|
|
58
|
+
*/
|
|
59
|
+
playground?: PlaygroundLayerOptions & {
|
|
60
|
+
autoFocus?: boolean;
|
|
61
|
+
autoResize?: boolean;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* 注册快捷键
|
|
65
|
+
*/
|
|
66
|
+
shortcuts?: (shortcutsRegistry: ShortcutsRegistry, ctx: CTX) => void;
|
|
67
|
+
/**
|
|
68
|
+
* 插件 IOC 注册,等价于 containerModule
|
|
69
|
+
*/
|
|
70
|
+
onBind?: (bindConfig: PluginBindConfig) => void;
|
|
71
|
+
/**
|
|
72
|
+
* 画布模块注册阶段
|
|
73
|
+
*/
|
|
74
|
+
onInit?: (ctx: CTX) => void;
|
|
75
|
+
/**
|
|
76
|
+
* 画布事件注册阶段 (一般用于注册 dom 事件)
|
|
77
|
+
*/
|
|
78
|
+
onReady?: (ctx: CTX) => void;
|
|
79
|
+
/**
|
|
80
|
+
* 画布所有 layer 第一次渲染完成后触发
|
|
81
|
+
*/
|
|
82
|
+
onAllLayersRendered?: (ctx: CTX) => void;
|
|
83
|
+
/**
|
|
84
|
+
* 画布销毁阶段
|
|
85
|
+
*/
|
|
86
|
+
onDispose?: (ctx: CTX) => void;
|
|
87
|
+
/**
|
|
88
|
+
* 插件扩展
|
|
89
|
+
* @param ctx
|
|
90
|
+
*/
|
|
91
|
+
plugins?: (ctx: CTX) => Plugin[];
|
|
92
|
+
/**
|
|
93
|
+
* 注册 layer
|
|
94
|
+
*/
|
|
95
|
+
layers?: LayerRegistry[];
|
|
96
|
+
/**
|
|
97
|
+
* IOC 模块,用于更底层的插件扩展
|
|
98
|
+
*/
|
|
99
|
+
containerModules?: interfaces.ContainerModule[];
|
|
100
|
+
children?: React.ReactNode;
|
|
101
|
+
/**
|
|
102
|
+
* 父 IOC 容器
|
|
103
|
+
*/
|
|
104
|
+
parentContainer?: interfaces.Container;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare function createPlaygroundReactPreset<CTX extends PluginContext = PluginContext>(opts: PlaygroundReactProps<CTX>, plugins?: Plugin[]): PluginsProvider<CTX>;
|
|
108
|
+
|
|
109
|
+
type PlaygroundRef = PluginContext;
|
|
110
|
+
declare const PlaygroundReact: React.ForwardRefExoticComponent<PlaygroundReactProps<PluginContext> & React.RefAttributes<PluginContext>>;
|
|
111
|
+
|
|
112
|
+
interface PlaygroundReactContentProps {
|
|
113
|
+
className?: string;
|
|
114
|
+
style?: React.CSSProperties;
|
|
115
|
+
children?: React.ReactNode;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
declare const PlaygroundReactContent: React.FC<PlaygroundReactContentProps>;
|
|
119
|
+
|
|
120
|
+
export { PlaygroundReact, PlaygroundReactContent, type PlaygroundReactContentProps, type PlaygroundReactProps, type PlaygroundRef, createPlaygroundReactPreset, usePlaygroundTools };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export { Disposable, Emitter, Event, useRefresh } from '@flowgram.ai/utils';
|
|
2
|
+
import { PlaygroundInteractiveType, PluginContext, PlaygroundLayerOptions, PluginBindConfig, Plugin, LayerRegistry, PluginsProvider } from '@flowgram.ai/core';
|
|
3
|
+
export * from '@flowgram.ai/core';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { interfaces } from 'inversify';
|
|
6
|
+
import { ShortcutsRegistry } from '@flowgram.ai/shortcuts-plugin';
|
|
7
|
+
import { BackgroundLayerOptions } from '@flowgram.ai/background-plugin';
|
|
8
|
+
|
|
9
|
+
interface PlaygroundToolsPropsType {
|
|
10
|
+
/**
|
|
11
|
+
* 最大缩放比,默认 2
|
|
12
|
+
*/
|
|
13
|
+
maxZoom?: number;
|
|
14
|
+
/**
|
|
15
|
+
* 最小缩放比,默认 0.25
|
|
16
|
+
*/
|
|
17
|
+
minZoom?: number;
|
|
18
|
+
}
|
|
19
|
+
interface PlaygroundTools {
|
|
20
|
+
/**
|
|
21
|
+
* 缩放 zoom 大小比例
|
|
22
|
+
*/
|
|
23
|
+
zoom: number;
|
|
24
|
+
/**
|
|
25
|
+
* 放大
|
|
26
|
+
*/
|
|
27
|
+
zoomin: (easing?: boolean) => void;
|
|
28
|
+
/**
|
|
29
|
+
* 缩小
|
|
30
|
+
*/
|
|
31
|
+
zoomout: (easing?: boolean) => void;
|
|
32
|
+
/**
|
|
33
|
+
* 设置缩放比例
|
|
34
|
+
* @param zoom
|
|
35
|
+
*/
|
|
36
|
+
updateZoom: (newZoom: number, easing?: boolean, easingDuration?: number) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 当前的交互模式, 鼠标友好模式 和 触摸板模式
|
|
39
|
+
*/
|
|
40
|
+
interactiveType: PlaygroundInteractiveType;
|
|
41
|
+
/**
|
|
42
|
+
* 切换交互模式
|
|
43
|
+
*/
|
|
44
|
+
toggleIneractiveType: () => void;
|
|
45
|
+
}
|
|
46
|
+
declare function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 画布配置配置
|
|
50
|
+
*/
|
|
51
|
+
interface PlaygroundReactProps<CTX extends PluginContext = PluginContext> {
|
|
52
|
+
/**
|
|
53
|
+
* 背景开关,默认打开
|
|
54
|
+
*/
|
|
55
|
+
background?: BackgroundLayerOptions | boolean;
|
|
56
|
+
/**
|
|
57
|
+
* 画布相关配置
|
|
58
|
+
*/
|
|
59
|
+
playground?: PlaygroundLayerOptions & {
|
|
60
|
+
autoFocus?: boolean;
|
|
61
|
+
autoResize?: boolean;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* 注册快捷键
|
|
65
|
+
*/
|
|
66
|
+
shortcuts?: (shortcutsRegistry: ShortcutsRegistry, ctx: CTX) => void;
|
|
67
|
+
/**
|
|
68
|
+
* 插件 IOC 注册,等价于 containerModule
|
|
69
|
+
*/
|
|
70
|
+
onBind?: (bindConfig: PluginBindConfig) => void;
|
|
71
|
+
/**
|
|
72
|
+
* 画布模块注册阶段
|
|
73
|
+
*/
|
|
74
|
+
onInit?: (ctx: CTX) => void;
|
|
75
|
+
/**
|
|
76
|
+
* 画布事件注册阶段 (一般用于注册 dom 事件)
|
|
77
|
+
*/
|
|
78
|
+
onReady?: (ctx: CTX) => void;
|
|
79
|
+
/**
|
|
80
|
+
* 画布所有 layer 第一次渲染完成后触发
|
|
81
|
+
*/
|
|
82
|
+
onAllLayersRendered?: (ctx: CTX) => void;
|
|
83
|
+
/**
|
|
84
|
+
* 画布销毁阶段
|
|
85
|
+
*/
|
|
86
|
+
onDispose?: (ctx: CTX) => void;
|
|
87
|
+
/**
|
|
88
|
+
* 插件扩展
|
|
89
|
+
* @param ctx
|
|
90
|
+
*/
|
|
91
|
+
plugins?: (ctx: CTX) => Plugin[];
|
|
92
|
+
/**
|
|
93
|
+
* 注册 layer
|
|
94
|
+
*/
|
|
95
|
+
layers?: LayerRegistry[];
|
|
96
|
+
/**
|
|
97
|
+
* IOC 模块,用于更底层的插件扩展
|
|
98
|
+
*/
|
|
99
|
+
containerModules?: interfaces.ContainerModule[];
|
|
100
|
+
children?: React.ReactNode;
|
|
101
|
+
/**
|
|
102
|
+
* 父 IOC 容器
|
|
103
|
+
*/
|
|
104
|
+
parentContainer?: interfaces.Container;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare function createPlaygroundReactPreset<CTX extends PluginContext = PluginContext>(opts: PlaygroundReactProps<CTX>, plugins?: Plugin[]): PluginsProvider<CTX>;
|
|
108
|
+
|
|
109
|
+
type PlaygroundRef = PluginContext;
|
|
110
|
+
declare const PlaygroundReact: React.ForwardRefExoticComponent<PlaygroundReactProps<PluginContext> & React.RefAttributes<PluginContext>>;
|
|
111
|
+
|
|
112
|
+
interface PlaygroundReactContentProps {
|
|
113
|
+
className?: string;
|
|
114
|
+
style?: React.CSSProperties;
|
|
115
|
+
children?: React.ReactNode;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
declare const PlaygroundReactContent: React.FC<PlaygroundReactContentProps>;
|
|
119
|
+
|
|
120
|
+
export { PlaygroundReact, PlaygroundReactContent, type PlaygroundReactContentProps, type PlaygroundReactProps, type PlaygroundRef, createPlaygroundReactPreset, usePlaygroundTools };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
31
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
32
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
33
|
+
if (decorator = decorators[i])
|
|
34
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
35
|
+
if (kind && result) __defProp(target, key, result);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
var src_exports = {};
|
|
41
|
+
__export(src_exports, {
|
|
42
|
+
Disposable: () => import_utils3.Disposable,
|
|
43
|
+
Emitter: () => import_utils3.Emitter,
|
|
44
|
+
Event: () => import_utils3.Event,
|
|
45
|
+
PlaygroundReact: () => PlaygroundReact,
|
|
46
|
+
PlaygroundReactContent: () => PlaygroundReactContent,
|
|
47
|
+
createPlaygroundReactPreset: () => createPlaygroundReactPreset,
|
|
48
|
+
usePlaygroundTools: () => usePlaygroundTools,
|
|
49
|
+
useRefresh: () => import_utils3.useRefresh
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(src_exports);
|
|
52
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
53
|
+
var import_utils3 = require("@flowgram.ai/utils");
|
|
54
|
+
__reExport(src_exports, require("@flowgram.ai/core"), module.exports);
|
|
55
|
+
|
|
56
|
+
// src/hooks/use-playground-tools.ts
|
|
57
|
+
var import_react = require("react");
|
|
58
|
+
var import_core = require("@flowgram.ai/core");
|
|
59
|
+
var import_utils = require("@flowgram.ai/utils");
|
|
60
|
+
function usePlaygroundTools(props) {
|
|
61
|
+
const { maxZoom = 2, minZoom = 0.25 } = props || {};
|
|
62
|
+
const playground = (0, import_core.usePlayground)();
|
|
63
|
+
const editorState = (0, import_core.useConfigEntity)(import_core.EditorStateConfigEntity, true);
|
|
64
|
+
const [zoom, setZoom] = (0, import_react.useState)(1);
|
|
65
|
+
const handleZoomOut = (0, import_react.useCallback)(
|
|
66
|
+
(easing) => {
|
|
67
|
+
if (zoom < minZoom) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
playground.config.zoomout(easing);
|
|
71
|
+
},
|
|
72
|
+
[zoom, playground, minZoom]
|
|
73
|
+
);
|
|
74
|
+
const handleZoomIn = (0, import_react.useCallback)(
|
|
75
|
+
(easing) => {
|
|
76
|
+
if (zoom > maxZoom) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
playground.config.zoomin(easing);
|
|
80
|
+
},
|
|
81
|
+
[zoom, playground, maxZoom]
|
|
82
|
+
);
|
|
83
|
+
const handleUpdateZoom = (0, import_react.useCallback)(
|
|
84
|
+
(value, easing, easingDuration) => {
|
|
85
|
+
playground.config.updateZoom(value, easing, easingDuration);
|
|
86
|
+
},
|
|
87
|
+
[playground]
|
|
88
|
+
);
|
|
89
|
+
const handleToggleIneractiveType = (0, import_react.useCallback)(() => {
|
|
90
|
+
if (editorState.isMouseFriendlyMode()) {
|
|
91
|
+
editorState.changeState(import_core.EditorState.STATE_SELECT.id);
|
|
92
|
+
} else {
|
|
93
|
+
editorState.changeState(import_core.EditorState.STATE_MOUSE_FRIENDLY_SELECT.id);
|
|
94
|
+
}
|
|
95
|
+
}, [editorState]);
|
|
96
|
+
(0, import_react.useEffect)(() => {
|
|
97
|
+
const dispose = new import_utils.DisposableCollection();
|
|
98
|
+
dispose.push(playground.onZoom((z) => setZoom(z)));
|
|
99
|
+
return () => dispose.dispose();
|
|
100
|
+
}, [playground]);
|
|
101
|
+
return {
|
|
102
|
+
zoomin: handleZoomIn,
|
|
103
|
+
zoomout: handleZoomOut,
|
|
104
|
+
updateZoom: handleUpdateZoom,
|
|
105
|
+
zoom,
|
|
106
|
+
interactiveType: editorState.isMouseFriendlyMode() ? "MOUSE" : "PAD",
|
|
107
|
+
toggleIneractiveType: handleToggleIneractiveType
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/components/playground-react.tsx
|
|
112
|
+
var import_react3 = __toESM(require("react"));
|
|
113
|
+
var import_core4 = require("@flowgram.ai/core");
|
|
114
|
+
|
|
115
|
+
// src/preset/playground-react-preset.ts
|
|
116
|
+
var import_shortcuts_plugin = require("@flowgram.ai/shortcuts-plugin");
|
|
117
|
+
var import_core2 = require("@flowgram.ai/core");
|
|
118
|
+
var import_background_plugin = require("@flowgram.ai/background-plugin");
|
|
119
|
+
function createPlaygroundReactPreset(opts, plugins = []) {
|
|
120
|
+
return (ctx) => {
|
|
121
|
+
plugins = plugins.slice();
|
|
122
|
+
if (opts.shortcuts) {
|
|
123
|
+
plugins.push(
|
|
124
|
+
(0, import_shortcuts_plugin.createShortcutsPlugin)({
|
|
125
|
+
registerShortcuts: (registry) => opts.shortcuts(registry, ctx)
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
if (opts.plugins) {
|
|
130
|
+
plugins.push(...opts.plugins(ctx));
|
|
131
|
+
}
|
|
132
|
+
plugins.push(
|
|
133
|
+
(0, import_core2.createPlaygroundPlugin)({
|
|
134
|
+
onBind: (bindConfig) => {
|
|
135
|
+
opts.onBind?.(bindConfig);
|
|
136
|
+
},
|
|
137
|
+
onInit: (ctx2) => {
|
|
138
|
+
const playgroundConfig = ctx2.get(import_core2.PlaygroundConfig);
|
|
139
|
+
if (opts.playground) {
|
|
140
|
+
if (opts.playground.autoFocus !== void 0) {
|
|
141
|
+
playgroundConfig.autoFocus = opts.playground.autoFocus;
|
|
142
|
+
}
|
|
143
|
+
if (opts.playground.autoResize !== void 0) {
|
|
144
|
+
playgroundConfig.autoResize = opts.playground.autoResize;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
playgroundConfig.autoFocus = false;
|
|
148
|
+
ctx2.playground.registerLayer(import_core2.PlaygroundLayer, opts.playground);
|
|
149
|
+
if (opts.layers) {
|
|
150
|
+
ctx2.playground.registerLayers(...opts.layers);
|
|
151
|
+
}
|
|
152
|
+
if (opts.onInit) opts.onInit(ctx2);
|
|
153
|
+
},
|
|
154
|
+
onReady(ctx2) {
|
|
155
|
+
if (opts.onReady) opts.onReady(ctx2);
|
|
156
|
+
},
|
|
157
|
+
onAllLayersRendered() {
|
|
158
|
+
if (opts.onAllLayersRendered) opts.onAllLayersRendered(ctx);
|
|
159
|
+
},
|
|
160
|
+
onDispose() {
|
|
161
|
+
if (opts.onDispose) opts.onDispose(ctx);
|
|
162
|
+
},
|
|
163
|
+
containerModules: opts.containerModules || []
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
if (opts.background || opts.background === void 0) {
|
|
167
|
+
plugins.push((0, import_background_plugin.createBackgroundPlugin)(opts.background || {}));
|
|
168
|
+
}
|
|
169
|
+
return plugins;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/layers/playground-content-layer.tsx
|
|
174
|
+
var import_react2 = __toESM(require("react"));
|
|
175
|
+
var import_inversify = require("inversify");
|
|
176
|
+
var import_core3 = require("@flowgram.ai/core");
|
|
177
|
+
var import_utils2 = require("@flowgram.ai/utils");
|
|
178
|
+
var PlaygroundContentLayer = class extends import_core3.Layer {
|
|
179
|
+
constructor() {
|
|
180
|
+
super(...arguments);
|
|
181
|
+
this.node = import_utils2.domUtils.createDivWithClass(
|
|
182
|
+
"gedit-playground-layer gedit-playground-content-layer"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
onZoom(scale) {
|
|
186
|
+
this.node.style.transform = `scale(${scale})`;
|
|
187
|
+
}
|
|
188
|
+
onReady() {
|
|
189
|
+
this.node.style.left = "0px";
|
|
190
|
+
this.node.style.top = "0px";
|
|
191
|
+
}
|
|
192
|
+
updateOptions(opts) {
|
|
193
|
+
this.options = opts;
|
|
194
|
+
this.render();
|
|
195
|
+
}
|
|
196
|
+
render() {
|
|
197
|
+
return /* @__PURE__ */ import_react2.default.createElement(
|
|
198
|
+
"div",
|
|
199
|
+
{
|
|
200
|
+
className: this.options.className,
|
|
201
|
+
style: { position: "absolute", ...this.options.style }
|
|
202
|
+
},
|
|
203
|
+
this.options.children
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
PlaygroundContentLayer.type = "PlaygroundContentLayer";
|
|
208
|
+
PlaygroundContentLayer = __decorateClass([
|
|
209
|
+
(0, import_inversify.injectable)()
|
|
210
|
+
], PlaygroundContentLayer);
|
|
211
|
+
|
|
212
|
+
// src/components/playground-react.tsx
|
|
213
|
+
var PlaygroundReact = (0, import_react3.forwardRef)(
|
|
214
|
+
function PlaygroundReact2(props, ref) {
|
|
215
|
+
const { parentContainer, children, ...others } = props;
|
|
216
|
+
const contentLoadPlugin = (0, import_react3.useMemo)(
|
|
217
|
+
() => (0, import_core4.createPlaygroundPlugin)({
|
|
218
|
+
onInit(ctx) {
|
|
219
|
+
ctx.playground.registerLayer(PlaygroundContentLayer);
|
|
220
|
+
}
|
|
221
|
+
}),
|
|
222
|
+
[]
|
|
223
|
+
);
|
|
224
|
+
const preset = (0, import_react3.useMemo)(() => createPlaygroundReactPreset(others, [contentLoadPlugin]), []);
|
|
225
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_core4.PlaygroundReactProvider, { ref, plugins: preset, parentContainer }, /* @__PURE__ */ import_react3.default.createElement(import_core4.PlaygroundReactRenderer, null, children));
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// src/components/playground-react-content.tsx
|
|
230
|
+
var import_react4 = __toESM(require("react"));
|
|
231
|
+
var import_core5 = require("@flowgram.ai/core");
|
|
232
|
+
var PlaygroundReactContent = (props) => {
|
|
233
|
+
const playground = (0, import_core5.usePlayground)();
|
|
234
|
+
(0, import_react4.useMemo)(() => {
|
|
235
|
+
const layer = playground.getLayer(PlaygroundContentLayer);
|
|
236
|
+
layer.updateOptions(props);
|
|
237
|
+
}, [props]);
|
|
238
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null);
|
|
239
|
+
};
|
|
240
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
241
|
+
0 && (module.exports = {
|
|
242
|
+
Disposable,
|
|
243
|
+
Emitter,
|
|
244
|
+
Event,
|
|
245
|
+
PlaygroundReact,
|
|
246
|
+
PlaygroundReactContent,
|
|
247
|
+
createPlaygroundReactPreset,
|
|
248
|
+
usePlaygroundTools,
|
|
249
|
+
useRefresh,
|
|
250
|
+
...require("@flowgram.ai/core")
|
|
251
|
+
});
|
|
252
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/use-playground-tools.ts","../src/components/playground-react.tsx","../src/preset/playground-react-preset.ts","../src/layers/playground-content-layer.tsx","../src/components/playground-react-content.tsx"],"sourcesContent":["import 'reflect-metadata';\n\n/* 核心 模块导出 */\nexport { useRefresh, Emitter, Event, Disposable } from '@flowgram.ai/utils';\nexport * from '@flowgram.ai/core';\n\nexport { usePlaygroundTools } from './hooks';\nexport {\n PlaygroundReact,\n PlaygroundReactContent,\n PlaygroundReactContentProps,\n PlaygroundRef,\n} from './components';\nexport { PlaygroundReactProps, createPlaygroundReactPreset } from './preset';\n","import { useCallback, useEffect, useState } from 'react';\n\nimport {\n EditorState,\n EditorStateConfigEntity,\n PlaygroundInteractiveType,\n useConfigEntity,\n usePlayground,\n} from '@flowgram.ai/core';\nimport { DisposableCollection } from '@flowgram.ai/utils';\n\nexport interface PlaygroundToolsPropsType {\n /**\n * 最大缩放比,默认 2\n */\n maxZoom?: number;\n /**\n * 最小缩放比,默认 0.25\n */\n minZoom?: number;\n}\n\nexport interface PlaygroundTools {\n /**\n * 缩放 zoom 大小比例\n */\n zoom: number;\n /**\n * 放大\n */\n zoomin: (easing?: boolean) => void;\n /**\n * 缩小\n */\n zoomout: (easing?: boolean) => void;\n /**\n * 设置缩放比例\n * @param zoom\n */\n updateZoom: (newZoom: number, easing?: boolean, easingDuration?: number) => void;\n /**\n * 当前的交互模式, 鼠标友好模式 和 触摸板模式\n */\n interactiveType: PlaygroundInteractiveType;\n /**\n * 切换交互模式\n */\n toggleIneractiveType: () => void;\n}\n\nexport function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools {\n const { maxZoom = 2, minZoom = 0.25 } = props || {};\n const playground = usePlayground();\n const editorState = useConfigEntity(EditorStateConfigEntity, true);\n\n const [zoom, setZoom] = useState(1);\n\n const handleZoomOut = useCallback(\n (easing?: boolean) => {\n if (zoom < minZoom) {\n return;\n }\n playground.config.zoomout(easing);\n },\n [zoom, playground, minZoom],\n );\n\n const handleZoomIn = useCallback(\n (easing?: boolean) => {\n if (zoom > maxZoom) {\n return;\n }\n playground.config.zoomin(easing);\n },\n [zoom, playground, maxZoom],\n );\n\n const handleUpdateZoom = useCallback(\n (value: number, easing?: boolean, easingDuration?: number) => {\n playground.config.updateZoom(value, easing, easingDuration);\n },\n [playground],\n );\n\n const handleToggleIneractiveType = useCallback(() => {\n if (editorState.isMouseFriendlyMode()) {\n editorState.changeState(EditorState.STATE_SELECT.id);\n } else {\n editorState.changeState(EditorState.STATE_MOUSE_FRIENDLY_SELECT.id);\n }\n }, [editorState]);\n\n useEffect(() => {\n const dispose = new DisposableCollection();\n dispose.push(playground.onZoom(z => setZoom(z)));\n return () => dispose.dispose();\n }, [playground]);\n\n return {\n zoomin: handleZoomIn,\n zoomout: handleZoomOut,\n updateZoom: handleUpdateZoom,\n zoom,\n interactiveType: editorState.isMouseFriendlyMode() ? 'MOUSE' : 'PAD',\n toggleIneractiveType: handleToggleIneractiveType,\n };\n}\n","import React, { useMemo, forwardRef } from 'react';\n\nimport {\n createPlaygroundPlugin,\n PlaygroundReactProvider,\n PlaygroundReactRenderer,\n PluginContext,\n} from '@flowgram.ai/core';\n\nimport { PlaygroundReactProps, createPlaygroundReactPreset } from '../preset';\nimport { PlaygroundContentLayer } from '../layers/playground-content-layer';\n\nexport type PlaygroundRef = PluginContext;\n\nexport const PlaygroundReact = forwardRef<PlaygroundRef, PlaygroundReactProps>(\n function PlaygroundReact(props, ref) {\n const { parentContainer, children, ...others } = props;\n const contentLoadPlugin = useMemo(\n () =>\n createPlaygroundPlugin({\n onInit(ctx) {\n ctx.playground.registerLayer(PlaygroundContentLayer);\n },\n }),\n [],\n );\n const preset = useMemo(() => createPlaygroundReactPreset(others, [contentLoadPlugin]), []);\n return (\n <PlaygroundReactProvider ref={ref} plugins={preset} parentContainer={parentContainer}>\n <PlaygroundReactRenderer>{children}</PlaygroundReactRenderer>\n </PlaygroundReactProvider>\n );\n },\n);\n","import { createShortcutsPlugin } from '@flowgram.ai/shortcuts-plugin';\nimport {\n PluginContext,\n PluginsProvider,\n Plugin,\n createPlaygroundPlugin,\n PlaygroundConfig,\n PlaygroundLayer,\n} from '@flowgram.ai/core';\nimport { createBackgroundPlugin } from '@flowgram.ai/background-plugin';\n\nimport { PlaygroundReactProps } from './playground-react-props';\n\nexport function createPlaygroundReactPreset<CTX extends PluginContext = PluginContext>(\n opts: PlaygroundReactProps<CTX>,\n plugins: Plugin[] = []\n): PluginsProvider<CTX> {\n return (ctx: CTX) => {\n plugins = plugins.slice();\n /**\n * 注册快捷键\n */\n if (opts.shortcuts) {\n plugins.push(\n createShortcutsPlugin({\n registerShortcuts: (registry) => opts.shortcuts!(registry, ctx),\n })\n );\n }\n /**\n * 注册三方插件\n */\n if (opts.plugins) {\n plugins.push(...opts.plugins(ctx));\n }\n /**\n * 画布生命周期注册\n */\n plugins.push(\n createPlaygroundPlugin<CTX>({\n onBind: (bindConfig) => {\n opts.onBind?.(bindConfig);\n },\n onInit: (ctx) => {\n const playgroundConfig = ctx.get<PlaygroundConfig>(PlaygroundConfig);\n if (opts.playground) {\n if (opts.playground.autoFocus !== undefined) {\n playgroundConfig.autoFocus = opts.playground.autoFocus;\n }\n if (opts.playground.autoResize !== undefined) {\n playgroundConfig.autoResize = opts.playground.autoResize;\n }\n }\n playgroundConfig.autoFocus = false;\n ctx.playground.registerLayer(PlaygroundLayer, opts.playground);\n if (opts.layers) {\n ctx.playground.registerLayers(...opts.layers);\n }\n if (opts.onInit) opts.onInit(ctx);\n },\n onReady(ctx) {\n if (opts.onReady) opts.onReady(ctx);\n },\n onAllLayersRendered() {\n if (opts.onAllLayersRendered) opts.onAllLayersRendered(ctx);\n },\n onDispose() {\n if (opts.onDispose) opts.onDispose(ctx);\n },\n containerModules: opts.containerModules || [],\n })\n );\n\n /**\n * 注册背景 (放最后插入), 默认打开\n */\n if (opts.background || opts.background === undefined) {\n plugins.push(createBackgroundPlugin(opts.background || {}));\n }\n return plugins;\n };\n}\n","import React from 'react';\n\nimport { injectable } from 'inversify';\nimport { Layer } from '@flowgram.ai/core';\nimport { domUtils } from '@flowgram.ai/utils';\n\nexport interface PlaygroundReactContentProps {\n className?: string;\n style?: React.CSSProperties;\n children?: React.ReactNode;\n}\n\n@injectable()\nexport class PlaygroundContentLayer extends Layer<PlaygroundReactContentProps> {\n static type = 'PlaygroundContentLayer';\n\n readonly node = domUtils.createDivWithClass(\n 'gedit-playground-layer gedit-playground-content-layer',\n );\n\n onZoom(scale: number): void {\n this.node.style.transform = `scale(${scale})`;\n }\n\n onReady() {\n this.node.style.left = '0px';\n this.node.style.top = '0px';\n }\n\n updateOptions(opts: PlaygroundReactContentProps) {\n this.options = opts;\n this.render();\n }\n\n render(): JSX.Element {\n return (\n <div\n className={this.options.className}\n style={{ position: 'absolute', ...this.options.style }}\n >\n {this.options.children}\n </div>\n );\n }\n}\n","import React, { useMemo } from 'react';\n\nimport { usePlayground } from '@flowgram.ai/core';\n\nimport {\n PlaygroundContentLayer,\n PlaygroundReactContentProps,\n} from '../layers/playground-content-layer';\n\nexport { PlaygroundReactContentProps };\n\nexport const PlaygroundReactContent: React.FC<PlaygroundReactContentProps> = props => {\n const playground = usePlayground();\n useMemo(() => {\n const layer = playground.getLayer(PlaygroundContentLayer)!;\n layer.updateOptions(props);\n }, [props]);\n return <></>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAO;AAGP,IAAAA,gBAAuD;AACvD,wBAAc,8BAJ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AAsB;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AACA,UAAM,aAAS,uBAAQ,MAAM,4BAA4B,QAAQ,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;AACzF,WACE,8BAAAC,QAAA,cAAC,wCAAwB,KAAU,SAAS,QAAQ,mBAClD,8BAAAA,QAAA,cAAC,4CAAyB,QAAS,CACrC;AAAA,EAEJ;AACF;;;AGjCA,IAAAC,gBAA+B;AAE/B,IAAAC,eAA8B;AASvB,IAAM,yBAAgE,WAAS;AACpF,QAAM,iBAAa,4BAAc;AACjC,6BAAQ,MAAM;AACZ,UAAM,QAAQ,WAAW,SAAS,sBAAsB;AACxD,UAAM,cAAc,KAAK;AAAA,EAC3B,GAAG,CAAC,KAAK,CAAC;AACV,SAAO,8BAAAC,QAAA,4BAAAA,QAAA,cAAE;AACX;","names":["import_utils","import_react","import_core","import_core","ctx","import_react","import_core","import_utils","React","PlaygroundReact","React","import_react","import_core","React"]}
|
package/index.css
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--g-selection-background: #4d53e8;
|
|
3
|
+
--g-editor-background: #f2f3f5;
|
|
4
|
+
--g-playground-select: var(--g-selection-background);
|
|
5
|
+
--g-playground-hover: var(--g-selection-background);
|
|
6
|
+
--g-playground-line: var(--g-selection-background);
|
|
7
|
+
--g-playground-blur: #999;
|
|
8
|
+
--g-playground-selectBox-outline: var(--g-selection-background);
|
|
9
|
+
--g-playground-selectBox-background: rgba(141, 144, 231, 0.1);
|
|
10
|
+
--g-playground-select-hover-background: rgba(77, 83, 232, 0.1);
|
|
11
|
+
--g-playground-select-control-size: 12px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.gedit-playground {
|
|
15
|
+
position: absolute;
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
left: 0;
|
|
19
|
+
top: 0;
|
|
20
|
+
z-index: 10;
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
user-select: none;
|
|
23
|
+
outline: none;
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
background-color: var(--g-editor-background);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.gedit-playground-scroll-right {
|
|
29
|
+
position: absolute;
|
|
30
|
+
right: 2px;
|
|
31
|
+
height: 100vh;
|
|
32
|
+
width: 7px;
|
|
33
|
+
z-index: 10;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.gedit-playground-scroll-bottom {
|
|
37
|
+
position: absolute;
|
|
38
|
+
bottom: 2px;
|
|
39
|
+
width: 100vw;
|
|
40
|
+
height: 7px;
|
|
41
|
+
z-index: 10;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.gedit-playground-scroll-right-block {
|
|
45
|
+
position: absolute;
|
|
46
|
+
opacity: 0.3;
|
|
47
|
+
border-radius: 3.5px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.gedit-playground-scroll-right-block:hover {
|
|
51
|
+
opacity: 0.6;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.gedit-playground-scroll-bottom-block {
|
|
55
|
+
position: absolute;
|
|
56
|
+
opacity: 0.3;
|
|
57
|
+
border-radius: 3.5px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.gedit-playground-scroll-bottom-block:hover {
|
|
61
|
+
opacity: 0.6;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.gedit-playground-scroll-hidden {
|
|
65
|
+
opacity: 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.gedit-playground * {
|
|
69
|
+
box-sizing: border-box;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.gedit-playground-loading {
|
|
73
|
+
position: absolute;
|
|
74
|
+
color: white;
|
|
75
|
+
left: 50%;
|
|
76
|
+
top: 50%;
|
|
77
|
+
z-index: 100;
|
|
78
|
+
display: flex;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
align-items: center;
|
|
81
|
+
transition: opacity 0.8s;
|
|
82
|
+
flex-direction: column;
|
|
83
|
+
text-align: center;
|
|
84
|
+
opacity: 0.8;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.gedit-hidden {
|
|
88
|
+
display: none;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.gedit-playground-pipeline {
|
|
92
|
+
position: absolute;
|
|
93
|
+
overflow: visible;
|
|
94
|
+
width: 100%;
|
|
95
|
+
height: 100%;
|
|
96
|
+
left: 0;
|
|
97
|
+
top: 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.gedit-playground-pipeline::before {
|
|
101
|
+
content: '';
|
|
102
|
+
position: absolute;
|
|
103
|
+
width: 1px;
|
|
104
|
+
height: 100%;
|
|
105
|
+
left: 0;
|
|
106
|
+
top: 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.gedit-playground-layer {
|
|
110
|
+
position: absolute;
|
|
111
|
+
overflow: visible;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.gedit-selector-box {
|
|
115
|
+
position: absolute;
|
|
116
|
+
left: 0;
|
|
117
|
+
top: 0;
|
|
118
|
+
width: 0;
|
|
119
|
+
height: 0;
|
|
120
|
+
z-index: 33;
|
|
121
|
+
outline: 1px solid var(--g-playground-selectBox-outline);
|
|
122
|
+
background-color: var(--g-playground-selectBox-background);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.gedit-selector-box-block {
|
|
126
|
+
position: absolute;
|
|
127
|
+
left: 0;
|
|
128
|
+
top: 0;
|
|
129
|
+
width: 0;
|
|
130
|
+
height: 0;
|
|
131
|
+
z-index: 9999;
|
|
132
|
+
display: none;
|
|
133
|
+
background-color: rgba(0, 0, 0, 0);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.gedit-selector-bounds-background {
|
|
137
|
+
position: absolute;
|
|
138
|
+
left: 0;
|
|
139
|
+
top: 0;
|
|
140
|
+
width: 0;
|
|
141
|
+
height: 0;
|
|
142
|
+
outline: 1px solid var(--g-playground-selectBox-outline);
|
|
143
|
+
background-color: #f0f4ff;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.gedit-selector-bounds-foreground {
|
|
147
|
+
position: absolute;
|
|
148
|
+
left: 0;
|
|
149
|
+
top: 0;
|
|
150
|
+
width: 0;
|
|
151
|
+
height: 0;
|
|
152
|
+
z-index: 33;
|
|
153
|
+
background: rgba(255, 255, 255, 0);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.gedit-grid-svg {
|
|
157
|
+
display: block;
|
|
158
|
+
position: absolute;
|
|
159
|
+
left: 20px;
|
|
160
|
+
top: 20px;
|
|
161
|
+
width: 0;
|
|
162
|
+
height: 0;
|
|
163
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowgram.ai/playground-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"require": "./dist/index.js",
|
|
9
|
+
"import": "./dist/esm/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./index.css": {
|
|
12
|
+
"import": "./index.css",
|
|
13
|
+
"require": "./index.css"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/esm/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"index.css"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"inversify": "^6.0.1",
|
|
25
|
+
"reflect-metadata": "~0.2.2",
|
|
26
|
+
"@flowgram.ai/background-plugin": "0.1.0",
|
|
27
|
+
"@flowgram.ai/core": "0.1.0",
|
|
28
|
+
"@flowgram.ai/utils": "0.1.0",
|
|
29
|
+
"@flowgram.ai/shortcuts-plugin": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/bezier-js": "4.1.3",
|
|
33
|
+
"@types/lodash": "^4.14.137",
|
|
34
|
+
"@types/react": "^18",
|
|
35
|
+
"@types/react-dom": "^18",
|
|
36
|
+
"@vitest/coverage-v8": "^0.32.0",
|
|
37
|
+
"eslint": "^8.54.0",
|
|
38
|
+
"react": "^18",
|
|
39
|
+
"react-dom": "^18",
|
|
40
|
+
"tsup": "^8.0.1",
|
|
41
|
+
"typescript": "^5.0.4",
|
|
42
|
+
"vitest": "^0.34.6",
|
|
43
|
+
"@flowgram.ai/eslint-config": "0.1.0",
|
|
44
|
+
"@flowgram.ai/ts-config": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": ">=17",
|
|
48
|
+
"react-dom": ">=17"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"registry": "https://registry.npmjs.org/"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "npm run build:fast -- --dts-resolve",
|
|
56
|
+
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
|
|
57
|
+
"build:watch": "npm run build:fast -- --dts-resolve",
|
|
58
|
+
"clean": "rimraf dist",
|
|
59
|
+
"test": "exit 0",
|
|
60
|
+
"test:cov": "exit 0",
|
|
61
|
+
"ts-check": "tsc --noEmit",
|
|
62
|
+
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
|
|
63
|
+
}
|
|
64
|
+
}
|