@flowgram.ai/playground-react 0.1.0-alpha.10
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 +226 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +254 -0
- package/dist/index.js.map +1 -0
- package/index.css +168 -0
- package/package.json +66 -0
|
@@ -0,0 +1,226 @@
|
|
|
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 { DisposableCollection } from "@flowgram.ai/utils";
|
|
20
|
+
import {
|
|
21
|
+
EditorState,
|
|
22
|
+
EditorStateConfigEntity,
|
|
23
|
+
useConfigEntity,
|
|
24
|
+
usePlayground
|
|
25
|
+
} from "@flowgram.ai/core";
|
|
26
|
+
function usePlaygroundTools(props) {
|
|
27
|
+
const { maxZoom, minZoom } = props || {};
|
|
28
|
+
const playground = usePlayground();
|
|
29
|
+
const editorState = useConfigEntity(EditorStateConfigEntity, true);
|
|
30
|
+
const [zoom, setZoom] = useState(1);
|
|
31
|
+
const handleZoomOut = useCallback(
|
|
32
|
+
(easing) => {
|
|
33
|
+
playground.config.zoomout(easing);
|
|
34
|
+
},
|
|
35
|
+
[playground]
|
|
36
|
+
);
|
|
37
|
+
const handleZoomIn = useCallback(
|
|
38
|
+
(easing) => {
|
|
39
|
+
playground.config.zoomin(easing);
|
|
40
|
+
},
|
|
41
|
+
[playground]
|
|
42
|
+
);
|
|
43
|
+
const handleUpdateZoom = useCallback(
|
|
44
|
+
(value, easing, easingDuration) => {
|
|
45
|
+
playground.config.updateZoom(value, easing, easingDuration);
|
|
46
|
+
},
|
|
47
|
+
[playground]
|
|
48
|
+
);
|
|
49
|
+
const handleToggleIneractiveType = useCallback(() => {
|
|
50
|
+
if (editorState.isMouseFriendlyMode()) {
|
|
51
|
+
editorState.changeState(EditorState.STATE_SELECT.id);
|
|
52
|
+
} else {
|
|
53
|
+
editorState.changeState(EditorState.STATE_MOUSE_FRIENDLY_SELECT.id);
|
|
54
|
+
}
|
|
55
|
+
}, [editorState]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const dispose = new DisposableCollection();
|
|
58
|
+
dispose.push(playground.onZoom((z) => setZoom(z)));
|
|
59
|
+
return () => dispose.dispose();
|
|
60
|
+
}, [playground]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const config = playground.config.config;
|
|
63
|
+
playground.config.updateConfig({
|
|
64
|
+
maxZoom: maxZoom !== void 0 ? maxZoom : config.maxZoom,
|
|
65
|
+
minZoom: minZoom !== void 0 ? minZoom : config.minZoom
|
|
66
|
+
});
|
|
67
|
+
}, [playground, maxZoom, minZoom]);
|
|
68
|
+
return {
|
|
69
|
+
zoomin: handleZoomIn,
|
|
70
|
+
zoomout: handleZoomOut,
|
|
71
|
+
updateZoom: handleUpdateZoom,
|
|
72
|
+
zoom,
|
|
73
|
+
interactiveType: editorState.isMouseFriendlyMode() ? "MOUSE" : "PAD",
|
|
74
|
+
toggleIneractiveType: handleToggleIneractiveType
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/components/playground-react.tsx
|
|
79
|
+
import React2, { useMemo, forwardRef } from "react";
|
|
80
|
+
import {
|
|
81
|
+
createPlaygroundPlugin as createPlaygroundPlugin2,
|
|
82
|
+
PlaygroundReactProvider,
|
|
83
|
+
PlaygroundReactRenderer
|
|
84
|
+
} from "@flowgram.ai/core";
|
|
85
|
+
|
|
86
|
+
// src/preset/playground-react-preset.ts
|
|
87
|
+
import { createShortcutsPlugin } from "@flowgram.ai/shortcuts-plugin";
|
|
88
|
+
import {
|
|
89
|
+
createPlaygroundPlugin,
|
|
90
|
+
PlaygroundConfig,
|
|
91
|
+
PlaygroundLayer
|
|
92
|
+
} from "@flowgram.ai/core";
|
|
93
|
+
import { createBackgroundPlugin } from "@flowgram.ai/background-plugin";
|
|
94
|
+
function createPlaygroundReactPreset(opts, plugins = []) {
|
|
95
|
+
return (ctx) => {
|
|
96
|
+
plugins = plugins.slice();
|
|
97
|
+
if (opts.background || opts.background === void 0) {
|
|
98
|
+
const backgroundOptions = typeof opts.background === "object" ? opts.background : {};
|
|
99
|
+
plugins.push(createBackgroundPlugin(backgroundOptions));
|
|
100
|
+
}
|
|
101
|
+
if (opts.shortcuts) {
|
|
102
|
+
plugins.push(
|
|
103
|
+
createShortcutsPlugin({
|
|
104
|
+
registerShortcuts: (registry) => opts.shortcuts(registry, ctx)
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (opts.plugins) {
|
|
109
|
+
plugins.push(...opts.plugins(ctx));
|
|
110
|
+
}
|
|
111
|
+
plugins.push(
|
|
112
|
+
createPlaygroundPlugin({
|
|
113
|
+
onBind: (bindConfig) => {
|
|
114
|
+
opts.onBind?.(bindConfig);
|
|
115
|
+
},
|
|
116
|
+
onInit: (ctx2) => {
|
|
117
|
+
const playgroundConfig = ctx2.get(PlaygroundConfig);
|
|
118
|
+
if (opts.playground) {
|
|
119
|
+
if (opts.playground.autoFocus !== void 0) {
|
|
120
|
+
playgroundConfig.autoFocus = opts.playground.autoFocus;
|
|
121
|
+
}
|
|
122
|
+
if (opts.playground.autoResize !== void 0) {
|
|
123
|
+
playgroundConfig.autoResize = opts.playground.autoResize;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
playgroundConfig.autoFocus = false;
|
|
127
|
+
ctx2.playground.registerLayer(PlaygroundLayer, opts.playground);
|
|
128
|
+
if (opts.layers) {
|
|
129
|
+
ctx2.playground.registerLayers(...opts.layers);
|
|
130
|
+
}
|
|
131
|
+
if (opts.onInit) opts.onInit(ctx2);
|
|
132
|
+
},
|
|
133
|
+
onReady(ctx2) {
|
|
134
|
+
if (opts.onReady) opts.onReady(ctx2);
|
|
135
|
+
},
|
|
136
|
+
onAllLayersRendered() {
|
|
137
|
+
if (opts.onAllLayersRendered) opts.onAllLayersRendered(ctx);
|
|
138
|
+
},
|
|
139
|
+
onDispose() {
|
|
140
|
+
if (opts.onDispose) opts.onDispose(ctx);
|
|
141
|
+
},
|
|
142
|
+
containerModules: opts.containerModules || []
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
return plugins;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/layers/playground-content-layer.tsx
|
|
150
|
+
import React from "react";
|
|
151
|
+
import { injectable } from "inversify";
|
|
152
|
+
import { Layer } from "@flowgram.ai/core";
|
|
153
|
+
import { domUtils } from "@flowgram.ai/utils";
|
|
154
|
+
var PlaygroundContentLayer = class extends Layer {
|
|
155
|
+
constructor() {
|
|
156
|
+
super(...arguments);
|
|
157
|
+
this.node = domUtils.createDivWithClass(
|
|
158
|
+
"gedit-playground-layer gedit-playground-content-layer"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
onZoom(scale) {
|
|
162
|
+
this.node.style.transform = `scale(${scale})`;
|
|
163
|
+
}
|
|
164
|
+
onReady() {
|
|
165
|
+
this.node.style.left = "0px";
|
|
166
|
+
this.node.style.top = "0px";
|
|
167
|
+
}
|
|
168
|
+
updateOptions(opts) {
|
|
169
|
+
this.options = opts;
|
|
170
|
+
this.render();
|
|
171
|
+
}
|
|
172
|
+
render() {
|
|
173
|
+
return /* @__PURE__ */ React.createElement(
|
|
174
|
+
"div",
|
|
175
|
+
{
|
|
176
|
+
className: this.options.className,
|
|
177
|
+
style: { position: "absolute", ...this.options.style }
|
|
178
|
+
},
|
|
179
|
+
this.options.children
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
PlaygroundContentLayer.type = "PlaygroundContentLayer";
|
|
184
|
+
PlaygroundContentLayer = __decorateClass([
|
|
185
|
+
injectable()
|
|
186
|
+
], PlaygroundContentLayer);
|
|
187
|
+
|
|
188
|
+
// src/components/playground-react.tsx
|
|
189
|
+
var PlaygroundReact = forwardRef(
|
|
190
|
+
function PlaygroundReact2(props, ref) {
|
|
191
|
+
const { parentContainer, children, ...others } = props;
|
|
192
|
+
const contentLoadPlugin = useMemo(
|
|
193
|
+
() => createPlaygroundPlugin2({
|
|
194
|
+
onInit(ctx) {
|
|
195
|
+
ctx.playground.registerLayer(PlaygroundContentLayer);
|
|
196
|
+
}
|
|
197
|
+
}),
|
|
198
|
+
[]
|
|
199
|
+
);
|
|
200
|
+
const preset = useMemo(() => createPlaygroundReactPreset(others, [contentLoadPlugin]), []);
|
|
201
|
+
return /* @__PURE__ */ React2.createElement(PlaygroundReactProvider, { ref, plugins: preset, parentContainer }, /* @__PURE__ */ React2.createElement(PlaygroundReactRenderer, null, children));
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
// src/components/playground-react-content.tsx
|
|
206
|
+
import React3, { useMemo as useMemo2 } from "react";
|
|
207
|
+
import { usePlayground as usePlayground2 } from "@flowgram.ai/core";
|
|
208
|
+
var PlaygroundReactContent = (props) => {
|
|
209
|
+
const playground = usePlayground2();
|
|
210
|
+
useMemo2(() => {
|
|
211
|
+
const layer = playground.getLayer(PlaygroundContentLayer);
|
|
212
|
+
layer.updateOptions(props);
|
|
213
|
+
}, [props]);
|
|
214
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null);
|
|
215
|
+
};
|
|
216
|
+
export {
|
|
217
|
+
Disposable,
|
|
218
|
+
Emitter,
|
|
219
|
+
Event,
|
|
220
|
+
PlaygroundReact,
|
|
221
|
+
PlaygroundReactContent,
|
|
222
|
+
createPlaygroundReactPreset,
|
|
223
|
+
usePlaygroundTools,
|
|
224
|
+
useRefresh
|
|
225
|
+
};
|
|
226
|
+
//# 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":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport '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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useCallback, useEffect, useState } from 'react';\n\nimport { DisposableCollection } from '@flowgram.ai/utils';\nimport {\n EditorState,\n EditorStateConfigEntity,\n PlaygroundInteractiveType,\n useConfigEntity,\n usePlayground,\n} from '@flowgram.ai/core';\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, minZoom } = 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 playground.config.zoomout(easing);\n },\n [playground]\n );\n\n const handleZoomIn = useCallback(\n (easing?: boolean) => {\n playground.config.zoomin(easing);\n },\n [playground]\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 useEffect(() => {\n const config = playground.config.config;\n playground.config.updateConfig({\n maxZoom: maxZoom !== undefined ? maxZoom : config.maxZoom,\n minZoom: minZoom !== undefined ? minZoom : config.minZoom,\n });\n }, [playground, maxZoom, minZoom]);\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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport 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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { 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.background || opts.background === undefined) {\n const backgroundOptions = typeof opts.background === 'object' ? opts.background : {};\n plugins.push(createBackgroundPlugin(backgroundOptions));\n }\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 return plugins;\n };\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport 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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport 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":";;;;;;;;;;;;AAKA,OAAO;AAGP,SAAS,YAAY,SAAS,OAAO,kBAAkB;AACvD,cAAc;;;ACJd,SAAS,aAAa,WAAW,gBAAgB;AAEjD,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AAyCA,SAAS,mBAAmB,OAAmD;AACpF,QAAM,EAAE,SAAS,QAAQ,IAAI,SAAS,CAAC;AACvC,QAAM,aAAa,cAAc;AACjC,QAAM,cAAc,gBAAgB,yBAAyB,IAAI;AAEjE,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,CAAC;AAElC,QAAM,gBAAgB;AAAA,IACpB,CAAC,WAAqB;AACpB,iBAAW,OAAO,QAAQ,MAAM;AAAA,IAClC;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,WAAqB;AACpB,iBAAW,OAAO,OAAO,MAAM;AAAA,IACjC;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,mBAAmB;AAAA,IACvB,CAAC,OAAe,QAAkB,mBAA4B;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AAAC,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,150 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
11
|
+
* SPDX-License-Identifier: MIT
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface PlaygroundToolsPropsType {
|
|
15
|
+
/**
|
|
16
|
+
* 最大缩放比,默认 2
|
|
17
|
+
*/
|
|
18
|
+
maxZoom?: number;
|
|
19
|
+
/**
|
|
20
|
+
* 最小缩放比,默认 0.25
|
|
21
|
+
*/
|
|
22
|
+
minZoom?: number;
|
|
23
|
+
}
|
|
24
|
+
interface PlaygroundTools {
|
|
25
|
+
/**
|
|
26
|
+
* 缩放 zoom 大小比例
|
|
27
|
+
*/
|
|
28
|
+
zoom: number;
|
|
29
|
+
/**
|
|
30
|
+
* 放大
|
|
31
|
+
*/
|
|
32
|
+
zoomin: (easing?: boolean) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 缩小
|
|
35
|
+
*/
|
|
36
|
+
zoomout: (easing?: boolean) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 设置缩放比例
|
|
39
|
+
* @param zoom
|
|
40
|
+
*/
|
|
41
|
+
updateZoom: (newZoom: number, easing?: boolean, easingDuration?: number) => void;
|
|
42
|
+
/**
|
|
43
|
+
* 当前的交互模式, 鼠标友好模式 和 触摸板模式
|
|
44
|
+
*/
|
|
45
|
+
interactiveType: PlaygroundInteractiveType;
|
|
46
|
+
/**
|
|
47
|
+
* 切换交互模式
|
|
48
|
+
*/
|
|
49
|
+
toggleIneractiveType: () => void;
|
|
50
|
+
}
|
|
51
|
+
declare function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
55
|
+
* SPDX-License-Identifier: MIT
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 画布配置配置
|
|
60
|
+
*/
|
|
61
|
+
interface PlaygroundReactProps<CTX extends PluginContext = PluginContext> {
|
|
62
|
+
/**
|
|
63
|
+
* 背景开关,默认打开
|
|
64
|
+
*/
|
|
65
|
+
background?: BackgroundLayerOptions | boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 画布相关配置
|
|
68
|
+
*/
|
|
69
|
+
playground?: PlaygroundLayerOptions & {
|
|
70
|
+
autoFocus?: boolean;
|
|
71
|
+
autoResize?: boolean;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 注册快捷键
|
|
75
|
+
*/
|
|
76
|
+
shortcuts?: (shortcutsRegistry: ShortcutsRegistry, ctx: CTX) => void;
|
|
77
|
+
/**
|
|
78
|
+
* 插件 IOC 注册,等价于 containerModule
|
|
79
|
+
*/
|
|
80
|
+
onBind?: (bindConfig: PluginBindConfig) => void;
|
|
81
|
+
/**
|
|
82
|
+
* 画布模块注册阶段
|
|
83
|
+
*/
|
|
84
|
+
onInit?: (ctx: CTX) => void;
|
|
85
|
+
/**
|
|
86
|
+
* 画布事件注册阶段 (一般用于注册 dom 事件)
|
|
87
|
+
*/
|
|
88
|
+
onReady?: (ctx: CTX) => void;
|
|
89
|
+
/**
|
|
90
|
+
* 画布所有 layer 第一次渲染完成后触发
|
|
91
|
+
*/
|
|
92
|
+
onAllLayersRendered?: (ctx: CTX) => void;
|
|
93
|
+
/**
|
|
94
|
+
* 画布销毁阶段
|
|
95
|
+
*/
|
|
96
|
+
onDispose?: (ctx: CTX) => void;
|
|
97
|
+
/**
|
|
98
|
+
* 插件扩展
|
|
99
|
+
* @param ctx
|
|
100
|
+
*/
|
|
101
|
+
plugins?: (ctx: CTX) => Plugin[];
|
|
102
|
+
/**
|
|
103
|
+
* 注册 layer
|
|
104
|
+
*/
|
|
105
|
+
layers?: LayerRegistry[];
|
|
106
|
+
/**
|
|
107
|
+
* IOC 模块,用于更底层的插件扩展
|
|
108
|
+
*/
|
|
109
|
+
containerModules?: interfaces.ContainerModule[];
|
|
110
|
+
children?: React.ReactNode;
|
|
111
|
+
/**
|
|
112
|
+
* 父 IOC 容器
|
|
113
|
+
*/
|
|
114
|
+
parentContainer?: interfaces.Container;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
119
|
+
* SPDX-License-Identifier: MIT
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
declare function createPlaygroundReactPreset<CTX extends PluginContext = PluginContext>(opts: PlaygroundReactProps<CTX>, plugins?: Plugin[]): PluginsProvider<CTX>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
126
|
+
* SPDX-License-Identifier: MIT
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
type PlaygroundRef = PluginContext;
|
|
130
|
+
declare const PlaygroundReact: React.ForwardRefExoticComponent<PlaygroundReactProps<PluginContext> & React.RefAttributes<PluginContext>>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
134
|
+
* SPDX-License-Identifier: MIT
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
interface PlaygroundReactContentProps {
|
|
138
|
+
className?: string;
|
|
139
|
+
style?: React.CSSProperties;
|
|
140
|
+
children?: React.ReactNode;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
145
|
+
* SPDX-License-Identifier: MIT
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
declare const PlaygroundReactContent: React.FC<PlaygroundReactContentProps>;
|
|
149
|
+
|
|
150
|
+
export { PlaygroundReact, PlaygroundReactContent, type PlaygroundReactContentProps, type PlaygroundReactProps, type PlaygroundRef, createPlaygroundReactPreset, usePlaygroundTools };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
11
|
+
* SPDX-License-Identifier: MIT
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface PlaygroundToolsPropsType {
|
|
15
|
+
/**
|
|
16
|
+
* 最大缩放比,默认 2
|
|
17
|
+
*/
|
|
18
|
+
maxZoom?: number;
|
|
19
|
+
/**
|
|
20
|
+
* 最小缩放比,默认 0.25
|
|
21
|
+
*/
|
|
22
|
+
minZoom?: number;
|
|
23
|
+
}
|
|
24
|
+
interface PlaygroundTools {
|
|
25
|
+
/**
|
|
26
|
+
* 缩放 zoom 大小比例
|
|
27
|
+
*/
|
|
28
|
+
zoom: number;
|
|
29
|
+
/**
|
|
30
|
+
* 放大
|
|
31
|
+
*/
|
|
32
|
+
zoomin: (easing?: boolean) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 缩小
|
|
35
|
+
*/
|
|
36
|
+
zoomout: (easing?: boolean) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 设置缩放比例
|
|
39
|
+
* @param zoom
|
|
40
|
+
*/
|
|
41
|
+
updateZoom: (newZoom: number, easing?: boolean, easingDuration?: number) => void;
|
|
42
|
+
/**
|
|
43
|
+
* 当前的交互模式, 鼠标友好模式 和 触摸板模式
|
|
44
|
+
*/
|
|
45
|
+
interactiveType: PlaygroundInteractiveType;
|
|
46
|
+
/**
|
|
47
|
+
* 切换交互模式
|
|
48
|
+
*/
|
|
49
|
+
toggleIneractiveType: () => void;
|
|
50
|
+
}
|
|
51
|
+
declare function usePlaygroundTools(props?: PlaygroundToolsPropsType): PlaygroundTools;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
55
|
+
* SPDX-License-Identifier: MIT
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 画布配置配置
|
|
60
|
+
*/
|
|
61
|
+
interface PlaygroundReactProps<CTX extends PluginContext = PluginContext> {
|
|
62
|
+
/**
|
|
63
|
+
* 背景开关,默认打开
|
|
64
|
+
*/
|
|
65
|
+
background?: BackgroundLayerOptions | boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 画布相关配置
|
|
68
|
+
*/
|
|
69
|
+
playground?: PlaygroundLayerOptions & {
|
|
70
|
+
autoFocus?: boolean;
|
|
71
|
+
autoResize?: boolean;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 注册快捷键
|
|
75
|
+
*/
|
|
76
|
+
shortcuts?: (shortcutsRegistry: ShortcutsRegistry, ctx: CTX) => void;
|
|
77
|
+
/**
|
|
78
|
+
* 插件 IOC 注册,等价于 containerModule
|
|
79
|
+
*/
|
|
80
|
+
onBind?: (bindConfig: PluginBindConfig) => void;
|
|
81
|
+
/**
|
|
82
|
+
* 画布模块注册阶段
|
|
83
|
+
*/
|
|
84
|
+
onInit?: (ctx: CTX) => void;
|
|
85
|
+
/**
|
|
86
|
+
* 画布事件注册阶段 (一般用于注册 dom 事件)
|
|
87
|
+
*/
|
|
88
|
+
onReady?: (ctx: CTX) => void;
|
|
89
|
+
/**
|
|
90
|
+
* 画布所有 layer 第一次渲染完成后触发
|
|
91
|
+
*/
|
|
92
|
+
onAllLayersRendered?: (ctx: CTX) => void;
|
|
93
|
+
/**
|
|
94
|
+
* 画布销毁阶段
|
|
95
|
+
*/
|
|
96
|
+
onDispose?: (ctx: CTX) => void;
|
|
97
|
+
/**
|
|
98
|
+
* 插件扩展
|
|
99
|
+
* @param ctx
|
|
100
|
+
*/
|
|
101
|
+
plugins?: (ctx: CTX) => Plugin[];
|
|
102
|
+
/**
|
|
103
|
+
* 注册 layer
|
|
104
|
+
*/
|
|
105
|
+
layers?: LayerRegistry[];
|
|
106
|
+
/**
|
|
107
|
+
* IOC 模块,用于更底层的插件扩展
|
|
108
|
+
*/
|
|
109
|
+
containerModules?: interfaces.ContainerModule[];
|
|
110
|
+
children?: React.ReactNode;
|
|
111
|
+
/**
|
|
112
|
+
* 父 IOC 容器
|
|
113
|
+
*/
|
|
114
|
+
parentContainer?: interfaces.Container;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
119
|
+
* SPDX-License-Identifier: MIT
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
declare function createPlaygroundReactPreset<CTX extends PluginContext = PluginContext>(opts: PlaygroundReactProps<CTX>, plugins?: Plugin[]): PluginsProvider<CTX>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
126
|
+
* SPDX-License-Identifier: MIT
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
type PlaygroundRef = PluginContext;
|
|
130
|
+
declare const PlaygroundReact: React.ForwardRefExoticComponent<PlaygroundReactProps<PluginContext> & React.RefAttributes<PluginContext>>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
134
|
+
* SPDX-License-Identifier: MIT
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
interface PlaygroundReactContentProps {
|
|
138
|
+
className?: string;
|
|
139
|
+
style?: React.CSSProperties;
|
|
140
|
+
children?: React.ReactNode;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
145
|
+
* SPDX-License-Identifier: MIT
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
declare const PlaygroundReactContent: React.FC<PlaygroundReactContentProps>;
|
|
149
|
+
|
|
150
|
+
export { PlaygroundReact, PlaygroundReactContent, type PlaygroundReactContentProps, type PlaygroundReactProps, type PlaygroundRef, createPlaygroundReactPreset, usePlaygroundTools };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
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_utils = require("@flowgram.ai/utils");
|
|
59
|
+
var import_core = require("@flowgram.ai/core");
|
|
60
|
+
function usePlaygroundTools(props) {
|
|
61
|
+
const { maxZoom, minZoom } = 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
|
+
playground.config.zoomout(easing);
|
|
68
|
+
},
|
|
69
|
+
[playground]
|
|
70
|
+
);
|
|
71
|
+
const handleZoomIn = (0, import_react.useCallback)(
|
|
72
|
+
(easing) => {
|
|
73
|
+
playground.config.zoomin(easing);
|
|
74
|
+
},
|
|
75
|
+
[playground]
|
|
76
|
+
);
|
|
77
|
+
const handleUpdateZoom = (0, import_react.useCallback)(
|
|
78
|
+
(value, easing, easingDuration) => {
|
|
79
|
+
playground.config.updateZoom(value, easing, easingDuration);
|
|
80
|
+
},
|
|
81
|
+
[playground]
|
|
82
|
+
);
|
|
83
|
+
const handleToggleIneractiveType = (0, import_react.useCallback)(() => {
|
|
84
|
+
if (editorState.isMouseFriendlyMode()) {
|
|
85
|
+
editorState.changeState(import_core.EditorState.STATE_SELECT.id);
|
|
86
|
+
} else {
|
|
87
|
+
editorState.changeState(import_core.EditorState.STATE_MOUSE_FRIENDLY_SELECT.id);
|
|
88
|
+
}
|
|
89
|
+
}, [editorState]);
|
|
90
|
+
(0, import_react.useEffect)(() => {
|
|
91
|
+
const dispose = new import_utils.DisposableCollection();
|
|
92
|
+
dispose.push(playground.onZoom((z) => setZoom(z)));
|
|
93
|
+
return () => dispose.dispose();
|
|
94
|
+
}, [playground]);
|
|
95
|
+
(0, import_react.useEffect)(() => {
|
|
96
|
+
const config = playground.config.config;
|
|
97
|
+
playground.config.updateConfig({
|
|
98
|
+
maxZoom: maxZoom !== void 0 ? maxZoom : config.maxZoom,
|
|
99
|
+
minZoom: minZoom !== void 0 ? minZoom : config.minZoom
|
|
100
|
+
});
|
|
101
|
+
}, [playground, maxZoom, minZoom]);
|
|
102
|
+
return {
|
|
103
|
+
zoomin: handleZoomIn,
|
|
104
|
+
zoomout: handleZoomOut,
|
|
105
|
+
updateZoom: handleUpdateZoom,
|
|
106
|
+
zoom,
|
|
107
|
+
interactiveType: editorState.isMouseFriendlyMode() ? "MOUSE" : "PAD",
|
|
108
|
+
toggleIneractiveType: handleToggleIneractiveType
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/components/playground-react.tsx
|
|
113
|
+
var import_react3 = __toESM(require("react"));
|
|
114
|
+
var import_core4 = require("@flowgram.ai/core");
|
|
115
|
+
|
|
116
|
+
// src/preset/playground-react-preset.ts
|
|
117
|
+
var import_shortcuts_plugin = require("@flowgram.ai/shortcuts-plugin");
|
|
118
|
+
var import_core2 = require("@flowgram.ai/core");
|
|
119
|
+
var import_background_plugin = require("@flowgram.ai/background-plugin");
|
|
120
|
+
function createPlaygroundReactPreset(opts, plugins = []) {
|
|
121
|
+
return (ctx) => {
|
|
122
|
+
plugins = plugins.slice();
|
|
123
|
+
if (opts.background || opts.background === void 0) {
|
|
124
|
+
const backgroundOptions = typeof opts.background === "object" ? opts.background : {};
|
|
125
|
+
plugins.push((0, import_background_plugin.createBackgroundPlugin)(backgroundOptions));
|
|
126
|
+
}
|
|
127
|
+
if (opts.shortcuts) {
|
|
128
|
+
plugins.push(
|
|
129
|
+
(0, import_shortcuts_plugin.createShortcutsPlugin)({
|
|
130
|
+
registerShortcuts: (registry) => opts.shortcuts(registry, ctx)
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
if (opts.plugins) {
|
|
135
|
+
plugins.push(...opts.plugins(ctx));
|
|
136
|
+
}
|
|
137
|
+
plugins.push(
|
|
138
|
+
(0, import_core2.createPlaygroundPlugin)({
|
|
139
|
+
onBind: (bindConfig) => {
|
|
140
|
+
opts.onBind?.(bindConfig);
|
|
141
|
+
},
|
|
142
|
+
onInit: (ctx2) => {
|
|
143
|
+
const playgroundConfig = ctx2.get(import_core2.PlaygroundConfig);
|
|
144
|
+
if (opts.playground) {
|
|
145
|
+
if (opts.playground.autoFocus !== void 0) {
|
|
146
|
+
playgroundConfig.autoFocus = opts.playground.autoFocus;
|
|
147
|
+
}
|
|
148
|
+
if (opts.playground.autoResize !== void 0) {
|
|
149
|
+
playgroundConfig.autoResize = opts.playground.autoResize;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
playgroundConfig.autoFocus = false;
|
|
153
|
+
ctx2.playground.registerLayer(import_core2.PlaygroundLayer, opts.playground);
|
|
154
|
+
if (opts.layers) {
|
|
155
|
+
ctx2.playground.registerLayers(...opts.layers);
|
|
156
|
+
}
|
|
157
|
+
if (opts.onInit) opts.onInit(ctx2);
|
|
158
|
+
},
|
|
159
|
+
onReady(ctx2) {
|
|
160
|
+
if (opts.onReady) opts.onReady(ctx2);
|
|
161
|
+
},
|
|
162
|
+
onAllLayersRendered() {
|
|
163
|
+
if (opts.onAllLayersRendered) opts.onAllLayersRendered(ctx);
|
|
164
|
+
},
|
|
165
|
+
onDispose() {
|
|
166
|
+
if (opts.onDispose) opts.onDispose(ctx);
|
|
167
|
+
},
|
|
168
|
+
containerModules: opts.containerModules || []
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
return plugins;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/layers/playground-content-layer.tsx
|
|
176
|
+
var import_react2 = __toESM(require("react"));
|
|
177
|
+
var import_inversify = require("inversify");
|
|
178
|
+
var import_core3 = require("@flowgram.ai/core");
|
|
179
|
+
var import_utils2 = require("@flowgram.ai/utils");
|
|
180
|
+
var PlaygroundContentLayer = class extends import_core3.Layer {
|
|
181
|
+
constructor() {
|
|
182
|
+
super(...arguments);
|
|
183
|
+
this.node = import_utils2.domUtils.createDivWithClass(
|
|
184
|
+
"gedit-playground-layer gedit-playground-content-layer"
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
onZoom(scale) {
|
|
188
|
+
this.node.style.transform = `scale(${scale})`;
|
|
189
|
+
}
|
|
190
|
+
onReady() {
|
|
191
|
+
this.node.style.left = "0px";
|
|
192
|
+
this.node.style.top = "0px";
|
|
193
|
+
}
|
|
194
|
+
updateOptions(opts) {
|
|
195
|
+
this.options = opts;
|
|
196
|
+
this.render();
|
|
197
|
+
}
|
|
198
|
+
render() {
|
|
199
|
+
return /* @__PURE__ */ import_react2.default.createElement(
|
|
200
|
+
"div",
|
|
201
|
+
{
|
|
202
|
+
className: this.options.className,
|
|
203
|
+
style: { position: "absolute", ...this.options.style }
|
|
204
|
+
},
|
|
205
|
+
this.options.children
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
PlaygroundContentLayer.type = "PlaygroundContentLayer";
|
|
210
|
+
PlaygroundContentLayer = __decorateClass([
|
|
211
|
+
(0, import_inversify.injectable)()
|
|
212
|
+
], PlaygroundContentLayer);
|
|
213
|
+
|
|
214
|
+
// src/components/playground-react.tsx
|
|
215
|
+
var PlaygroundReact = (0, import_react3.forwardRef)(
|
|
216
|
+
function PlaygroundReact2(props, ref) {
|
|
217
|
+
const { parentContainer, children, ...others } = props;
|
|
218
|
+
const contentLoadPlugin = (0, import_react3.useMemo)(
|
|
219
|
+
() => (0, import_core4.createPlaygroundPlugin)({
|
|
220
|
+
onInit(ctx) {
|
|
221
|
+
ctx.playground.registerLayer(PlaygroundContentLayer);
|
|
222
|
+
}
|
|
223
|
+
}),
|
|
224
|
+
[]
|
|
225
|
+
);
|
|
226
|
+
const preset = (0, import_react3.useMemo)(() => createPlaygroundReactPreset(others, [contentLoadPlugin]), []);
|
|
227
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_core4.PlaygroundReactProvider, { ref, plugins: preset, parentContainer }, /* @__PURE__ */ import_react3.default.createElement(import_core4.PlaygroundReactRenderer, null, children));
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
// src/components/playground-react-content.tsx
|
|
232
|
+
var import_react4 = __toESM(require("react"));
|
|
233
|
+
var import_core5 = require("@flowgram.ai/core");
|
|
234
|
+
var PlaygroundReactContent = (props) => {
|
|
235
|
+
const playground = (0, import_core5.usePlayground)();
|
|
236
|
+
(0, import_react4.useMemo)(() => {
|
|
237
|
+
const layer = playground.getLayer(PlaygroundContentLayer);
|
|
238
|
+
layer.updateOptions(props);
|
|
239
|
+
}, [props]);
|
|
240
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null);
|
|
241
|
+
};
|
|
242
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
243
|
+
0 && (module.exports = {
|
|
244
|
+
Disposable,
|
|
245
|
+
Emitter,
|
|
246
|
+
Event,
|
|
247
|
+
PlaygroundReact,
|
|
248
|
+
PlaygroundReactContent,
|
|
249
|
+
createPlaygroundReactPreset,
|
|
250
|
+
usePlaygroundTools,
|
|
251
|
+
useRefresh,
|
|
252
|
+
...require("@flowgram.ai/core")
|
|
253
|
+
});
|
|
254
|
+
//# 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":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport '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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { useCallback, useEffect, useState } from 'react';\n\nimport { DisposableCollection } from '@flowgram.ai/utils';\nimport {\n EditorState,\n EditorStateConfigEntity,\n PlaygroundInteractiveType,\n useConfigEntity,\n usePlayground,\n} from '@flowgram.ai/core';\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, minZoom } = 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 playground.config.zoomout(easing);\n },\n [playground]\n );\n\n const handleZoomIn = useCallback(\n (easing?: boolean) => {\n playground.config.zoomin(easing);\n },\n [playground]\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 useEffect(() => {\n const config = playground.config.config;\n playground.config.updateConfig({\n maxZoom: maxZoom !== undefined ? maxZoom : config.maxZoom,\n minZoom: minZoom !== undefined ? minZoom : config.minZoom,\n });\n }, [playground, maxZoom, minZoom]);\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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport 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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { 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.background || opts.background === undefined) {\n const backgroundOptions = typeof opts.background === 'object' ? opts.background : {};\n plugins.push(createBackgroundPlugin(backgroundOptions));\n }\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 return plugins;\n };\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport 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","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport 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;AAKA,8BAAO;AAGP,IAAAA,gBAAuD;AACvD,wBAAc,8BATd;;;ACKA,mBAAiD;AAEjD,mBAAqC;AACrC,kBAMO;AAyCA,SAAS,mBAAmB,OAAmD;AACpF,QAAM,EAAE,SAAS,QAAQ,IAAI,SAAS,CAAC;AACvC,QAAM,iBAAa,2BAAc;AACjC,QAAM,kBAAc,6BAAgB,qCAAyB,IAAI;AAEjE,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,CAAC;AAElC,QAAM,oBAAgB;AAAA,IACpB,CAAC,WAAqB;AACpB,iBAAW,OAAO,QAAQ,MAAM;AAAA,IAClC;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,mBAAe;AAAA,IACnB,CAAC,WAAqB;AACpB,iBAAW,OAAO,OAAO,MAAM;AAAA,IACjC;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,uBAAmB;AAAA,IACvB,CAAC,OAAe,QAAkB,mBAA4B;AAC5D,iBAAW,OAAO,WAAW,OAAO,QAAQ,cAAc;AAAA,IAC5D;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,QAAM,iCAA6B,0BAAY,MAAM;AACnD,QAAI,YAAY,oBAAoB,GAAG;AACr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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,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
:root {
|
|
7
|
+
--g-selection-background: #4d53e8;
|
|
8
|
+
--g-editor-background: #f2f3f5;
|
|
9
|
+
--g-playground-select: var(--g-selection-background);
|
|
10
|
+
--g-playground-hover: var(--g-selection-background);
|
|
11
|
+
--g-playground-line: var(--g-selection-background);
|
|
12
|
+
--g-playground-blur: #999;
|
|
13
|
+
--g-playground-selectBox-outline: var(--g-selection-background);
|
|
14
|
+
--g-playground-selectBox-background: rgba(141, 144, 231, 0.1);
|
|
15
|
+
--g-playground-select-hover-background: rgba(77, 83, 232, 0.1);
|
|
16
|
+
--g-playground-select-control-size: 12px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.gedit-playground {
|
|
20
|
+
position: absolute;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
left: 0;
|
|
24
|
+
top: 0;
|
|
25
|
+
z-index: 10;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
user-select: none;
|
|
28
|
+
outline: none;
|
|
29
|
+
box-sizing: border-box;
|
|
30
|
+
background-color: var(--g-editor-background);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.gedit-playground-scroll-right {
|
|
34
|
+
position: absolute;
|
|
35
|
+
right: 2px;
|
|
36
|
+
height: 100vh;
|
|
37
|
+
width: 7px;
|
|
38
|
+
z-index: 10;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.gedit-playground-scroll-bottom {
|
|
42
|
+
position: absolute;
|
|
43
|
+
bottom: 2px;
|
|
44
|
+
width: 100vw;
|
|
45
|
+
height: 7px;
|
|
46
|
+
z-index: 10;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.gedit-playground-scroll-right-block {
|
|
50
|
+
position: absolute;
|
|
51
|
+
opacity: 0.3;
|
|
52
|
+
border-radius: 3.5px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.gedit-playground-scroll-right-block:hover {
|
|
56
|
+
opacity: 0.6;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.gedit-playground-scroll-bottom-block {
|
|
60
|
+
position: absolute;
|
|
61
|
+
opacity: 0.3;
|
|
62
|
+
border-radius: 3.5px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.gedit-playground-scroll-bottom-block:hover {
|
|
66
|
+
opacity: 0.6;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.gedit-playground-scroll-hidden {
|
|
70
|
+
opacity: 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.gedit-playground * {
|
|
74
|
+
box-sizing: border-box;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.gedit-playground-loading {
|
|
78
|
+
position: absolute;
|
|
79
|
+
color: white;
|
|
80
|
+
left: 50%;
|
|
81
|
+
top: 50%;
|
|
82
|
+
z-index: 100;
|
|
83
|
+
display: flex;
|
|
84
|
+
justify-content: center;
|
|
85
|
+
align-items: center;
|
|
86
|
+
transition: opacity 0.8s;
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
text-align: center;
|
|
89
|
+
opacity: 0.8;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.gedit-hidden {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.gedit-playground-pipeline {
|
|
97
|
+
position: absolute;
|
|
98
|
+
overflow: visible;
|
|
99
|
+
width: 100%;
|
|
100
|
+
height: 100%;
|
|
101
|
+
left: 0;
|
|
102
|
+
top: 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.gedit-playground-pipeline::before {
|
|
106
|
+
content: '';
|
|
107
|
+
position: absolute;
|
|
108
|
+
width: 1px;
|
|
109
|
+
height: 100%;
|
|
110
|
+
left: 0;
|
|
111
|
+
top: 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.gedit-playground-layer {
|
|
115
|
+
position: absolute;
|
|
116
|
+
overflow: visible;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.gedit-selector-box {
|
|
120
|
+
position: absolute;
|
|
121
|
+
left: 0;
|
|
122
|
+
top: 0;
|
|
123
|
+
width: 0;
|
|
124
|
+
height: 0;
|
|
125
|
+
z-index: 33;
|
|
126
|
+
outline: 1px solid var(--g-playground-selectBox-outline);
|
|
127
|
+
background-color: var(--g-playground-selectBox-background);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.gedit-selector-box-block {
|
|
131
|
+
position: absolute;
|
|
132
|
+
left: 0;
|
|
133
|
+
top: 0;
|
|
134
|
+
width: 0;
|
|
135
|
+
height: 0;
|
|
136
|
+
z-index: 9999;
|
|
137
|
+
display: none;
|
|
138
|
+
background-color: rgba(0, 0, 0, 0);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.gedit-selector-bounds-background {
|
|
142
|
+
position: absolute;
|
|
143
|
+
left: 0;
|
|
144
|
+
top: 0;
|
|
145
|
+
width: 0;
|
|
146
|
+
height: 0;
|
|
147
|
+
outline: 1px solid var(--g-playground-selectBox-outline);
|
|
148
|
+
background-color: #f0f4ff;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.gedit-selector-bounds-foreground {
|
|
152
|
+
position: absolute;
|
|
153
|
+
left: 0;
|
|
154
|
+
top: 0;
|
|
155
|
+
width: 0;
|
|
156
|
+
height: 0;
|
|
157
|
+
z-index: 33;
|
|
158
|
+
background: rgba(255, 255, 255, 0);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.gedit-grid-svg {
|
|
162
|
+
display: block;
|
|
163
|
+
position: absolute;
|
|
164
|
+
left: 20px;
|
|
165
|
+
top: 20px;
|
|
166
|
+
width: 0;
|
|
167
|
+
height: 0;
|
|
168
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowgram.ai/playground-react",
|
|
3
|
+
"version": "0.1.0-alpha.10",
|
|
4
|
+
"homepage": "https://flowgram.ai/",
|
|
5
|
+
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/esm/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./index.css": {
|
|
14
|
+
"import": "./index.css",
|
|
15
|
+
"require": "./index.css"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/esm/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"index.css"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"inversify": "^6.0.1",
|
|
27
|
+
"reflect-metadata": "~0.2.2",
|
|
28
|
+
"@flowgram.ai/background-plugin": "0.1.0-alpha.10",
|
|
29
|
+
"@flowgram.ai/core": "0.1.0-alpha.10",
|
|
30
|
+
"@flowgram.ai/shortcuts-plugin": "0.1.0-alpha.10",
|
|
31
|
+
"@flowgram.ai/utils": "0.1.0-alpha.10"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/bezier-js": "4.1.3",
|
|
35
|
+
"@types/lodash": "^4.14.137",
|
|
36
|
+
"@types/react": "^18",
|
|
37
|
+
"@types/react-dom": "^18",
|
|
38
|
+
"@vitest/coverage-v8": "^0.32.0",
|
|
39
|
+
"eslint": "^8.54.0",
|
|
40
|
+
"react": "^18",
|
|
41
|
+
"react-dom": "^18",
|
|
42
|
+
"tsup": "^8.0.1",
|
|
43
|
+
"typescript": "^5.0.4",
|
|
44
|
+
"vitest": "^0.34.6",
|
|
45
|
+
"@flowgram.ai/ts-config": "0.1.0-alpha.10",
|
|
46
|
+
"@flowgram.ai/eslint-config": "0.1.0-alpha.10"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=16.8",
|
|
50
|
+
"react-dom": ">=16.8"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public",
|
|
54
|
+
"registry": "https://registry.npmjs.org/"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "npm run build:fast -- --dts-resolve",
|
|
58
|
+
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
|
|
59
|
+
"build:watch": "npm run build:fast -- --dts-resolve",
|
|
60
|
+
"clean": "rimraf dist",
|
|
61
|
+
"test": "exit 0",
|
|
62
|
+
"test:cov": "exit 0",
|
|
63
|
+
"ts-check": "tsc --noEmit",
|
|
64
|
+
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
|
|
65
|
+
}
|
|
66
|
+
}
|