@flowgram.ai/panel-manager-plugin 0.1.0-alpha.22 → 0.1.0-alpha.24

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.
@@ -9,13 +9,13 @@
9
9
  {"kind":"O","text":"\u001b[34mCLI\u001b[39m Target: es2020\n"}
10
10
  {"kind":"O","text":"\u001b[34mCJS\u001b[39m Build start\n"}
11
11
  {"kind":"O","text":"\u001b[34mESM\u001b[39m Build start\n"}
12
- {"kind":"O","text":"\u001b[32mESM\u001b[39m \u001b[1mdist/esm/index.js \u001b[22m\u001b[32m13.07 KB\u001b[39m\n"}
13
- {"kind":"O","text":"\u001b[32mESM\u001b[39m \u001b[1mdist/esm/index.js.map \u001b[22m\u001b[32m24.15 KB\u001b[39m\n"}
14
- {"kind":"O","text":"\u001b[32mESM\u001b[39m ⚡️ Build success in 91ms\n"}
15
- {"kind":"O","text":"\u001b[32mCJS\u001b[39m \u001b[1mdist/index.js \u001b[22m\u001b[32m15.42 KB\u001b[39m\n"}
16
- {"kind":"O","text":"\u001b[32mCJS\u001b[39m \u001b[1mdist/index.js.map \u001b[22m\u001b[32m24.71 KB\u001b[39m\n"}
17
- {"kind":"O","text":"\u001b[32mCJS\u001b[39m ⚡️ Build success in 107ms\n"}
12
+ {"kind":"O","text":"\u001b[32mCJS\u001b[39m \u001b[1mdist/index.js \u001b[22m\u001b[32m18.85 KB\u001b[39m\n"}
13
+ {"kind":"O","text":"\u001b[32mCJS\u001b[39m \u001b[1mdist/index.js.map \u001b[22m\u001b[32m31.19 KB\u001b[39m\n"}
14
+ {"kind":"O","text":"\u001b[32mCJS\u001b[39m ⚡️ Build success in 110ms\n"}
15
+ {"kind":"O","text":"\u001b[32mESM\u001b[39m \u001b[1mdist/esm/index.js \u001b[22m\u001b[32m16.16 KB\u001b[39m\n"}
16
+ {"kind":"O","text":"\u001b[32mESM\u001b[39m \u001b[1mdist/esm/index.js.map \u001b[22m\u001b[32m30.61 KB\u001b[39m\n"}
17
+ {"kind":"O","text":"\u001b[32mESM\u001b[39m ⚡️ Build success in 111ms\n"}
18
18
  {"kind":"O","text":"\u001b[34mDTS\u001b[39m Build start\n"}
19
- {"kind":"O","text":"\u001b[32mDTS\u001b[39m ⚡️ Build success in 3627ms\n"}
20
- {"kind":"O","text":"\u001b[32mDTS\u001b[39m \u001b[1mdist/index.d.ts \u001b[22m\u001b[32m3.49 KB\u001b[39m\n"}
21
- {"kind":"O","text":"\u001b[32mDTS\u001b[39m \u001b[1mdist/index.d.mts \u001b[22m\u001b[32m3.49 KB\u001b[39m\n"}
19
+ {"kind":"O","text":"\u001b[32mDTS\u001b[39m ⚡️ Build success in 3544ms\n"}
20
+ {"kind":"O","text":"\u001b[32mDTS\u001b[39m \u001b[1mdist/index.d.ts \u001b[22m\u001b[32m4.74 KB\u001b[39m\n"}
21
+ {"kind":"O","text":"\u001b[32mDTS\u001b[39m \u001b[1mdist/index.d.mts \u001b[22m\u001b[32m4.74 KB\u001b[39m\n"}
@@ -1,24 +1,27 @@
1
1
  {
2
2
  "files": {
3
3
  "packages/plugins/panel-manager-plugin/.eslintrc.cjs": "6b30cfc55136d429873e780785bf8d775edaaa74",
4
- "packages/plugins/panel-manager-plugin/.rush/temp/shrinkwrap-deps.json": "31768a71cb9a14b49720a461fe04680fabc8c1b4",
5
- "packages/plugins/panel-manager-plugin/package.json": "b578806137a3da06d5e4a79c98329da16ba385b0",
6
- "packages/plugins/panel-manager-plugin/src/components/panel-layer/css.ts": "50466641de472439cf80c60160512d35846f72d5",
4
+ "packages/plugins/panel-manager-plugin/.rush/temp/shrinkwrap-deps.json": "75dbadf340a3fdaa60befb137b12769e13b91282",
5
+ "packages/plugins/panel-manager-plugin/package.json": "cb0835394b1db5cfb167091ca40438cdbc571dbd",
6
+ "packages/plugins/panel-manager-plugin/src/components/panel-layer/css.ts": "b697da100336b58dddff4dfc1c5754eba7a87533",
7
7
  "packages/plugins/panel-manager-plugin/src/components/panel-layer/docked-panel-layer.tsx": "232cd8edbac3a8d8b17b2a5a07c463e57ee8f5c8",
8
- "packages/plugins/panel-manager-plugin/src/components/panel-layer/float-panel.tsx": "2a1b7bf6dbbe5864d852e92bd57b49be191d88ca",
9
8
  "packages/plugins/panel-manager-plugin/src/components/panel-layer/index.ts": "4c78ec72d6acde8f2192ac956436a870cccc583f",
10
- "packages/plugins/panel-manager-plugin/src/components/panel-layer/panel-layer.tsx": "62f84e44b6ac000524bb8f4d5ebcf03b07fda831",
9
+ "packages/plugins/panel-manager-plugin/src/components/panel-layer/panel-layer.tsx": "d5a9464fa66a9819fa1b0055071990532fd819d9",
10
+ "packages/plugins/panel-manager-plugin/src/components/panel-layer/panel.tsx": "0e708acecffeb5f3a8924e15a5db37e86e050bca",
11
11
  "packages/plugins/panel-manager-plugin/src/components/resize-bar/index.tsx": "7712eb70c08b0826ac8940be64582287d279d564",
12
- "packages/plugins/panel-manager-plugin/src/create-panel-manager-plugin.ts": "a1872d870751a839ec2353eda3e02e6711dba779",
12
+ "packages/plugins/panel-manager-plugin/src/contexts.ts": "21e828a3c16a060f92c62c52dd978224f2ab7436",
13
+ "packages/plugins/panel-manager-plugin/src/create-panel-manager-plugin.ts": "660998495abbabc247370c3525e0009415e6f752",
13
14
  "packages/plugins/panel-manager-plugin/src/hooks/use-global-css.ts": "be94fd4759d691bdcc5eb8a03f90995956ce4bf0",
14
15
  "packages/plugins/panel-manager-plugin/src/hooks/use-panel-manager.ts": "0e0073c6ad9a1552a9896085b011b79dbfe6309d",
15
- "packages/plugins/panel-manager-plugin/src/index.ts": "dc7ce8533d3205790491ded0c96d83bba159a24b",
16
- "packages/plugins/panel-manager-plugin/src/services/float-panel.ts": "579889c8dd30051a92c722856be1229960b57d16",
17
- "packages/plugins/panel-manager-plugin/src/services/index.ts": "bb44c19958ea0a21d5669480edaac6fd9b493f2b",
18
- "packages/plugins/panel-manager-plugin/src/services/panel-config.ts": "6fd1a71698eb71b8180a6d0e06f9ee872bfc774f",
16
+ "packages/plugins/panel-manager-plugin/src/hooks/use-panel.ts": "869332ced78092cad212cdac4777c66b3f1c215e",
17
+ "packages/plugins/panel-manager-plugin/src/index.ts": "990c6bff8e5f16e876a903a8e52fe764f30b3a88",
18
+ "packages/plugins/panel-manager-plugin/src/services/index.ts": "9cb6cc67c05c10f00bd7b5fffdf44c3fcd0a4c28",
19
+ "packages/plugins/panel-manager-plugin/src/services/panel-config.ts": "b5b96aa95acf3dd188894a739d534e599a1cd755",
20
+ "packages/plugins/panel-manager-plugin/src/services/panel-factory.ts": "ca57e3899b0d923227b7a50ebe0b62dc45d25715",
19
21
  "packages/plugins/panel-manager-plugin/src/services/panel-layer.ts": "e456afb5e28d3c93846521fa29ed352aca282bec",
20
- "packages/plugins/panel-manager-plugin/src/services/panel-manager.ts": "ba1d87dca960c9a12b3f1dbc5cb03094c3122cbc",
21
- "packages/plugins/panel-manager-plugin/src/types.ts": "55fb77e160b875cedb8545f258a5dbd1a57fe29b",
22
+ "packages/plugins/panel-manager-plugin/src/services/panel-manager.ts": "084133a6439823c83b2b9a25cce1310456a8a88a",
23
+ "packages/plugins/panel-manager-plugin/src/services/panel-restore.ts": "c3151b5281cc35efb262654f8500556a23811829",
24
+ "packages/plugins/panel-manager-plugin/src/types.ts": "3de81af3e3d6235f83fbfcbb16039e77a18eb492",
22
25
  "packages/plugins/panel-manager-plugin/tsconfig.json": "4b7a4f197dc4f9c62c2938fb3b77780944ad7675"
23
26
  },
24
27
  "arguments": "npm run build:fast -- --dts-resolve "
@@ -1,5 +1,5 @@
1
1
  {
2
- "../../packages/plugins/panel-manager-plugin": "../../packages/plugins/panel-manager-plugin:yX1mXvP2pUoHg+kWBxzailD0ct7xEMiUBGKeTuOw+zI=:",
2
+ "../../packages/plugins/panel-manager-plugin": "../../packages/plugins/panel-manager-plugin:6NvHMKeGiIW3XkE78MP0g5Cr6dz80O0NqneafG0tgHE=:",
3
3
  "@esbuild/aix-ppc64@0.25.9": "sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==",
4
4
  "@esbuild/android-arm64@0.25.9": "sha512-IDrddSmpSv51ftWslJMvl3Q2ZT98fUSL2/rlUXuVqRXHCs5EUF1/f+jbjF5+NG9UffUDMCiTyh8iec7u8RlTLg==",
5
5
  "@esbuild/android-arm@0.25.9": "sha512-5WNI1DaMtxQ7t7B6xa572XMXpHAaI/9Hnhk8lcxF4zVN4xstUgTlvuGDorBguKEnZO70qwEcLpfifMLoxiPqHQ==",
@@ -91,6 +91,7 @@
91
91
  "get-tsconfig@4.10.1": "sha512-auHyJ4AgMz7vgS8Hp3N6HXSmlMdUyhSUrfBF16w153rxtLIEOE+HGqaBppczZvnHLqQJfiHotCYpNhl0lUROFQ==",
92
92
  "glob@10.4.5": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==",
93
93
  "has-flag@3.0.0": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
94
+ "immer@10.1.3": "sha512-tmjF/k8QDKydUlm3mZU+tjM6zeq9/fFpPqH9SzWmBnVVKsPBg/V66qsMwb3/Bo90cgUN+ghdVBess+hPsxUyRw==",
94
95
  "inversify@6.2.2(reflect-metadata@0.2.2)": "sha512-KB836KHbZ9WrUnB8ax5MtadOwnqQYa+ZJO3KWbPFgcr4RIEnHM621VaqFZzOZd9+U7ln6upt9n0wJei7x2BNqw==",
95
96
  "is-fullwidth-code-point@3.0.0": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
96
97
  "isexe@2.0.0": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
@@ -111,6 +112,7 @@
111
112
  "ms@2.1.3": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
112
113
  "mz@2.7.0": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==",
113
114
  "nanoid@3.3.11": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==",
115
+ "nanoid@5.1.5": "sha512-Ir/+ZpE9fDsNH0hQ3C68uyThDXzYcim2EqcZ8zn8Chtt1iylPT9xXJB0kPCnqzgcEGikO9RxSrh63MsmVCU7Fw==",
114
116
  "object-assign@4.1.1": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
115
117
  "package-json-from-dist@1.0.1": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
116
118
  "path-key@3.1.1": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
@@ -153,10 +155,12 @@
153
155
  "tsx@4.19.4": "sha512-gK5GVzDkJK1SI1zwHf32Mqxf2tSJkNx+eYcNly5+nHvWqXUJYUkWBQtKauoESz3ymezAI++ZwT855x5p5eop+Q==",
154
156
  "typescript@5.9.2": "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==",
155
157
  "ufo@1.6.1": "sha512-9a4/uxlTWJ4+a5i0ooc1rU7C7YOw3wT+UGqdeNNHWnOF9qcMBgLRS+4IYUqbczewFx4mLEig6gawh7X6mFlEkA==",
158
+ "use-sync-external-store@1.6.0(react@18.3.1)": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==",
156
159
  "webidl-conversions@4.0.2": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==",
157
160
  "whatwg-url@7.1.0": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==",
158
161
  "which@2.0.2": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
159
162
  "wrap-ansi@7.0.0": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
160
163
  "wrap-ansi@8.1.0": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==",
161
- "yaml@2.8.1": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw=="
164
+ "yaml@2.8.1": "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw==",
165
+ "zustand@5.0.8(@types/react@18.3.24)(immer@10.1.3)(react@18.3.1)(use-sync-external-store@1.6.0(react@18.3.1))": "sha512-gyPKpIaxY9XcO2vSMrLbiER7QMAMGOQZVRdJ6Zi782jkbzZygq5GI9nG8g+sMgitRtndwaBSl7uiqC49o1SSiw=="
162
166
  }
package/dist/esm/index.js CHANGED
@@ -12,6 +12,82 @@ var __decorateClass = (decorators, target, key, kind) => {
12
12
  // src/create-panel-manager-plugin.ts
13
13
  import { definePluginCreator } from "@flowgram.ai/core";
14
14
 
15
+ // src/services/panel-factory.ts
16
+ import { createStore } from "zustand/vanilla";
17
+ import { nanoid } from "nanoid";
18
+ import { inject, injectable as injectable2 } from "inversify";
19
+
20
+ // src/services/panel-restore.ts
21
+ import { injectable } from "inversify";
22
+ var PanelRestore = Symbol("PanelRestore");
23
+ var PanelRestoreImpl = class {
24
+ constructor() {
25
+ this.map = /* @__PURE__ */ new Map();
26
+ }
27
+ store(k, v) {
28
+ this.map.set(k, v);
29
+ }
30
+ restore(k) {
31
+ return this.map.get(k);
32
+ }
33
+ };
34
+ PanelRestoreImpl = __decorateClass([
35
+ injectable()
36
+ ], PanelRestoreImpl);
37
+
38
+ // src/services/panel-factory.ts
39
+ var PanelEntityFactory = Symbol("PanelEntityFactory");
40
+ var PanelEntityFactoryConstant = Symbol("PanelEntityFactoryConstant");
41
+ var PanelEntityConfigConstant = Symbol("PanelEntityConfigConstant");
42
+ var PANEL_SIZE_DEFAULT = 400;
43
+ var PanelEntity = class {
44
+ constructor() {
45
+ this.initialized = false;
46
+ /** 实例唯一标识 */
47
+ this.id = nanoid();
48
+ /** 渲染缓存 */
49
+ this.node = null;
50
+ }
51
+ get area() {
52
+ return this.config.area;
53
+ }
54
+ get key() {
55
+ return this.factory.key;
56
+ }
57
+ get renderer() {
58
+ if (!this.node) {
59
+ this.node = this.factory.render(this.config.props);
60
+ }
61
+ return this.node;
62
+ }
63
+ init() {
64
+ if (this.initialized) {
65
+ return;
66
+ }
67
+ this.initialized = true;
68
+ const cache = this.restore.restore(this.key);
69
+ this.store = createStore(() => ({
70
+ size: this.config.defaultSize || this.factory.defaultSize || PANEL_SIZE_DEFAULT,
71
+ ...cache ?? {}
72
+ }));
73
+ }
74
+ dispose() {
75
+ this.restore.store(this.key, this.store.getState());
76
+ }
77
+ };
78
+ __decorateClass([
79
+ inject(PanelRestore)
80
+ ], PanelEntity.prototype, "restore", 2);
81
+ __decorateClass([
82
+ inject(PanelEntityFactoryConstant)
83
+ ], PanelEntity.prototype, "factory", 2);
84
+ __decorateClass([
85
+ inject(PanelEntityConfigConstant)
86
+ ], PanelEntity.prototype, "config", 2);
87
+ PanelEntity = __decorateClass([
88
+ injectable2()
89
+ ], PanelEntity);
90
+
15
91
  // src/components/resize-bar/index.tsx
16
92
  import { useRef, useState } from "react";
17
93
  import { jsx } from "react/jsx-runtime";
@@ -112,130 +188,114 @@ var defineConfig = (config) => {
112
188
  };
113
189
 
114
190
  // src/services/panel-manager.ts
115
- import { injectable, inject } from "inversify";
116
- import { Playground } from "@flowgram.ai/core";
117
-
118
- // src/services/float-panel.ts
191
+ import { injectable as injectable3, inject as inject2 } from "inversify";
119
192
  import { Emitter } from "@flowgram.ai/utils";
120
- var PANEL_SIZE_DEFAULT = 400;
121
- var FloatPanel = class {
122
- constructor(config) {
123
- this.config = config;
124
- this.elements = [];
125
- this.onUpdateEmitter = new Emitter();
126
- this.sizeMap = /* @__PURE__ */ new Map();
127
- this.onUpdate = this.onUpdateEmitter.event;
128
- this.currentFactoryKey = "";
129
- }
130
- updateSize(newSize) {
131
- this.sizeMap.set(this.currentFactoryKey, newSize);
132
- this.onUpdateEmitter.fire();
133
- }
134
- get currentSize() {
135
- return this.sizeMap.get(this.currentFactoryKey) || PANEL_SIZE_DEFAULT;
136
- }
137
- open(factory, options) {
138
- const el = factory.render(options?.props);
139
- const idx = this.elements.findIndex((e) => e.key === factory.key);
140
- this.currentFactoryKey = factory.key;
141
- if (!this.sizeMap.has(factory.key)) {
142
- this.sizeMap.set(factory.key, factory.defaultSize || PANEL_SIZE_DEFAULT);
143
- }
144
- if (idx >= 0) {
145
- this.elements[idx] = { el, key: factory.key, style: factory.style };
146
- } else {
147
- this.elements.push({ el, key: factory.key, style: factory.style });
148
- if (this.elements.length > this.config.max) {
149
- this.elements.shift();
150
- }
151
- }
152
- this.onUpdateEmitter.fire();
153
- }
154
- get visible() {
155
- return this.elements.length > 0;
156
- }
157
- close(key) {
158
- if (!key) {
159
- this.elements = [];
160
- } else {
161
- this.elements = this.elements.filter((e) => e.key !== key);
162
- }
163
- this.onUpdateEmitter.fire();
164
- }
165
- dispose() {
166
- this.elements = [];
167
- this.onUpdateEmitter.dispose();
168
- }
169
- };
170
-
171
- // src/services/panel-manager.ts
172
193
  var PanelManager = class {
173
194
  constructor() {
174
195
  this.panelRegistry = /* @__PURE__ */ new Map();
196
+ this.panels = /* @__PURE__ */ new Map();
197
+ this.onPanelsChangeEvent = new Emitter();
198
+ this.onPanelsChange = this.onPanelsChangeEvent.event;
175
199
  }
176
200
  init() {
177
201
  this.config.factories.forEach((factory) => this.register(factory));
178
- this.right = new FloatPanel(this.config.right);
179
- this.bottom = new FloatPanel(this.config.bottom);
180
- this.dockedRight = new FloatPanel(this.config.dockedRight);
181
- this.dockedBottom = new FloatPanel(this.config.dockedBottom);
182
202
  }
203
+ /** registry panel factory */
183
204
  register(factory) {
184
205
  this.panelRegistry.set(factory.key, factory);
185
206
  }
207
+ /** open panel */
186
208
  open(key, area = "right", options) {
187
209
  const factory = this.panelRegistry.get(key);
188
210
  if (!factory) {
189
211
  return;
190
212
  }
191
- const panel = this.getPanel(area);
192
- panel.open(factory, options);
213
+ const sameKeyPanels = this.getPanels(area).filter((p) => p.key === key);
214
+ if (!factory.allowDuplicates && sameKeyPanels.length) {
215
+ sameKeyPanels.forEach((p) => this.remove(p.id));
216
+ }
217
+ const panel = this.createPanel({
218
+ factory,
219
+ config: {
220
+ area,
221
+ ...options
222
+ }
223
+ });
224
+ this.panels.set(panel.id, panel);
225
+ this.trim(area);
226
+ this.onPanelsChangeEvent.fire();
227
+ console.log("jxj", this.panels);
193
228
  }
229
+ /** close panel */
194
230
  close(key) {
195
- this.right.close(key);
196
- this.bottom.close(key);
197
- this.dockedRight.close(key);
198
- this.dockedBottom.close(key);
231
+ const panels = this.getPanels();
232
+ const closedPanels = key ? panels.filter((p) => p.key === key) : panels;
233
+ closedPanels.forEach((p) => this.remove(p.id));
234
+ this.onPanelsChangeEvent.fire();
199
235
  }
200
- getPanel(area) {
236
+ trim(area) {
237
+ const panels = this.getPanels(area);
238
+ const areaConfig = this.getAreaConfig(area);
239
+ console.log("jxj", areaConfig.max, panels.length);
240
+ while (panels.length > areaConfig.max) {
241
+ const removed = panels.shift();
242
+ if (removed) {
243
+ this.remove(removed.id);
244
+ }
245
+ }
246
+ }
247
+ remove(id) {
248
+ const panel = this.panels.get(id);
249
+ if (panel) {
250
+ panel.dispose();
251
+ this.panels.delete(id);
252
+ }
253
+ }
254
+ getPanels(area) {
255
+ const panels = [];
256
+ this.panels.forEach((panel) => {
257
+ if (!area || panel.area === area) {
258
+ panels.push(panel);
259
+ }
260
+ });
261
+ return panels;
262
+ }
263
+ getAreaConfig(area) {
201
264
  switch (area) {
202
265
  case "docked-bottom":
203
- return this.dockedBottom;
266
+ return this.config.dockedBottom;
204
267
  case "docked-right":
205
- return this.dockedRight;
268
+ return this.config.dockedRight;
206
269
  case "bottom":
207
- return this.bottom;
270
+ return this.config.bottom;
208
271
  case "right":
209
272
  default:
210
- return this.right;
273
+ return this.config.right;
211
274
  }
212
275
  }
213
276
  dispose() {
214
- this.right.dispose();
215
- this.bottom.dispose();
216
- this.dockedBottom.dispose();
217
- this.dockedRight.dispose();
277
+ this.onPanelsChangeEvent.dispose();
218
278
  }
219
279
  };
220
280
  __decorateClass([
221
- inject(Playground)
222
- ], PanelManager.prototype, "playground", 2);
223
- __decorateClass([
224
- inject(PanelManagerConfig)
281
+ inject2(PanelManagerConfig)
225
282
  ], PanelManager.prototype, "config", 2);
283
+ __decorateClass([
284
+ inject2(PanelEntityFactory)
285
+ ], PanelManager.prototype, "createPanel", 2);
226
286
  PanelManager = __decorateClass([
227
- injectable()
287
+ injectable3()
228
288
  ], PanelManager);
229
289
 
230
290
  // src/services/panel-layer.ts
231
291
  import ReactDOM from "react-dom";
232
292
  import { createElement } from "react";
233
- import { injectable as injectable2, inject as inject2 } from "inversify";
293
+ import { injectable as injectable4, inject as inject3 } from "inversify";
234
294
  import { domUtils, Disposable } from "@flowgram.ai/utils";
235
295
  import { Layer, PluginContext } from "@flowgram.ai/core";
236
296
 
237
297
  // src/components/panel-layer/panel-layer.tsx
238
- import clsx from "clsx";
298
+ import clsx2 from "clsx";
239
299
 
240
300
  // src/hooks/use-global-css.ts
241
301
  import { useEffect } from "react";
@@ -254,13 +314,80 @@ var useGlobalCSS = ({ cssText, id, cleanup }) => {
254
314
  }, [id]);
255
315
  };
256
316
 
257
- // src/components/panel-layer/float-panel.tsx
258
- import { useEffect as useEffect2, useRef as useRef2, startTransition, useState as useState2, useCallback } from "react";
317
+ // src/components/panel-layer/panel.tsx
318
+ import { useEffect as useEffect2, startTransition, useState as useState2, useRef as useRef2 } from "react";
319
+ import { useStoreWithEqualityFn } from "zustand/traditional";
320
+ import { shallow } from "zustand/shallow";
321
+ import clsx from "clsx";
259
322
 
260
323
  // src/hooks/use-panel-manager.ts
261
324
  import { useService } from "@flowgram.ai/core";
262
325
  var usePanelManager = () => useService(PanelManager);
263
326
 
327
+ // src/contexts.ts
328
+ import { createContext } from "react";
329
+ var PanelContext = createContext({});
330
+
331
+ // src/components/panel-layer/panel.tsx
332
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
333
+ var PanelItem = ({ panel }) => {
334
+ const panelManager = usePanelManager();
335
+ const ref = useRef2(null);
336
+ const resize = panel.factory.resize !== void 0 ? panel.factory.resize : panelManager.config.autoResize;
337
+ const isHorizontal = ["right", "docked-right"].includes(panel.area);
338
+ const size = useStoreWithEqualityFn(panel.store, (s) => s.size, shallow);
339
+ const sizeStyle = isHorizontal ? { width: size } : { height: size };
340
+ const handleResize = (next) => {
341
+ let nextSize = next;
342
+ if (typeof panel.factory.maxSize === "number" && nextSize > panel.factory.maxSize) {
343
+ nextSize = panel.factory.maxSize;
344
+ } else if (typeof panel.factory.minSize === "number" && nextSize < panel.factory.minSize) {
345
+ nextSize = panel.factory.minSize;
346
+ }
347
+ panel.store.setState({ size: nextSize });
348
+ };
349
+ useEffect2(() => {
350
+ if (ref.current) {
351
+ const { width, height } = ref.current.getBoundingClientRect();
352
+ const realSize = isHorizontal ? width : height;
353
+ panel.store.setState({ size: realSize });
354
+ }
355
+ }, []);
356
+ return /* @__PURE__ */ jsxs(
357
+ "div",
358
+ {
359
+ className: clsx(
360
+ "gedit-flow-panel-wrap",
361
+ isHorizontal ? "panel-horizontal" : "panel-vertical"
362
+ ),
363
+ ref,
364
+ style: { ...panel.factory.style, ...panel.config.style, ...sizeStyle },
365
+ children: [
366
+ resize && panelManager.config.resizeBarRender({
367
+ size,
368
+ direction: isHorizontal ? "vertical" : "horizontal",
369
+ onResize: handleResize
370
+ }),
371
+ panel.renderer
372
+ ]
373
+ },
374
+ panel.id
375
+ );
376
+ };
377
+ var PanelArea = ({ area }) => {
378
+ const panelManager = usePanelManager();
379
+ const [panels, setPanels] = useState2(panelManager.getPanels(area));
380
+ useEffect2(() => {
381
+ const dispose = panelManager.onPanelsChange(() => {
382
+ startTransition(() => {
383
+ setPanels(panelManager.getPanels(area));
384
+ });
385
+ });
386
+ return () => dispose.dispose();
387
+ }, []);
388
+ return /* @__PURE__ */ jsx2(Fragment, { children: panels.map((panel) => /* @__PURE__ */ jsx2(PanelContext.Provider, { value: panel, children: /* @__PURE__ */ jsx2(PanelItem, { panel }) }, panel.id)) });
389
+ };
390
+
264
391
  // src/components/panel-layer/css.ts
265
392
  var globalCSS = `
266
393
  .gedit-flow-panel-layer-wrap * {
@@ -302,8 +429,9 @@ var globalCSS = `
302
429
  min-width: 0;
303
430
  display: flex;
304
431
  column-gap: 4px;
432
+ max-width: 100%;
305
433
  }
306
-
434
+
307
435
  .gedit-flow-panel-main-area {
308
436
  position: relative;
309
437
  overflow: hidden;
@@ -318,55 +446,18 @@ var globalCSS = `
318
446
  width: 100%;
319
447
  min-height: 0;
320
448
  }
449
+ .gedit-flow-panel-wrap {
450
+ pointer-events: auto;
451
+ overflow: auto;
452
+ position: relative;
453
+ }
454
+ .gedit-flow-panel-wrap.panel-horizontal {
455
+ height: 100%;
456
+ }
457
+ .gedit-flow-panel-wrap.panel-vertical {
458
+ width: 100%;
459
+ }
321
460
  `;
322
- var floatPanelWrap = {
323
- pointerEvents: "auto",
324
- height: "100%",
325
- width: "100%",
326
- overflow: "auto"
327
- };
328
-
329
- // src/components/panel-layer/float-panel.tsx
330
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
331
- var FloatPanel2 = ({ area }) => {
332
- const [, setVersion] = useState2(0);
333
- const panelManager = usePanelManager();
334
- const panel = useRef2(panelManager.getPanel(area));
335
- const isHorizontal = ["right", "docked-right"].includes(area);
336
- const render = () => panel.current.elements.map((i) => /* @__PURE__ */ jsx2("div", { className: "float-panel-wrap", style: { ...floatPanelWrap, ...i.style }, children: i.el }, i.key));
337
- const node = useRef2(render());
338
- useEffect2(() => {
339
- const dispose = panel.current.onUpdate(() => {
340
- startTransition(() => {
341
- node.current = render();
342
- setVersion((v) => v + 1);
343
- });
344
- });
345
- return () => dispose.dispose();
346
- }, [panel]);
347
- const onResize = useCallback((newSize) => panel.current.updateSize(newSize), []);
348
- const size = panel.current.currentSize;
349
- const sizeStyle = isHorizontal ? { width: size, height: "100%" } : { height: size, width: "100%" };
350
- return /* @__PURE__ */ jsxs(
351
- "div",
352
- {
353
- className: "gedit-flow-panel",
354
- style: {
355
- position: "relative",
356
- display: panel.current.visible ? "block" : "none",
357
- ...sizeStyle
358
- },
359
- children: [
360
- panelManager.config.resizeBarRender({
361
- size,
362
- direction: isHorizontal ? "vertical" : "horizontal",
363
- onResize
364
- }),
365
- node.current
366
- ]
367
- }
368
- );
369
- };
370
461
 
371
462
  // src/components/panel-layer/panel-layer.tsx
372
463
  import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
@@ -383,7 +474,7 @@ var PanelLayer = ({
383
474
  return /* @__PURE__ */ jsxs2(
384
475
  "div",
385
476
  {
386
- className: clsx(
477
+ className: clsx2(
387
478
  "gedit-flow-panel-layer-wrap",
388
479
  mode === "docked" && "gedit-flow-panel-layer-wrap-docked",
389
480
  mode === "floating" && "gedit-flow-panel-layer-wrap-floating",
@@ -393,9 +484,9 @@ var PanelLayer = ({
393
484
  children: [
394
485
  /* @__PURE__ */ jsxs2("div", { className: "gedit-flow-panel-left-area", children: [
395
486
  /* @__PURE__ */ jsx3("div", { className: "gedit-flow-panel-main-area", children }),
396
- /* @__PURE__ */ jsx3("div", { className: "gedit-flow-panel-bottom-area", children: /* @__PURE__ */ jsx3(FloatPanel2, { area: mode === "docked" ? "docked-bottom" : "bottom" }) })
487
+ /* @__PURE__ */ jsx3("div", { className: "gedit-flow-panel-bottom-area", children: /* @__PURE__ */ jsx3(PanelArea, { area: mode === "docked" ? "docked-bottom" : "bottom" }) })
397
488
  ] }),
398
- /* @__PURE__ */ jsx3("div", { className: "gedit-flow-panel-right-area", children: /* @__PURE__ */ jsx3(FloatPanel2, { area: mode === "docked" ? "docked-right" : "right" }) })
489
+ /* @__PURE__ */ jsx3("div", { className: "gedit-flow-panel-right-area", children: /* @__PURE__ */ jsx3(PanelArea, { area: mode === "docked" ? "docked-right" : "right" }) })
399
490
  ]
400
491
  }
401
492
  );
@@ -439,20 +530,34 @@ var PanelLayer2 = class extends Layer {
439
530
  }
440
531
  };
441
532
  __decorateClass([
442
- inject2(PanelManagerConfig)
533
+ inject3(PanelManagerConfig)
443
534
  ], PanelLayer2.prototype, "panelConfig", 2);
444
535
  __decorateClass([
445
- inject2(PluginContext)
536
+ inject3(PluginContext)
446
537
  ], PanelLayer2.prototype, "pluginContext", 2);
447
538
  PanelLayer2 = __decorateClass([
448
- injectable2()
539
+ injectable4()
449
540
  ], PanelLayer2);
450
541
 
451
542
  // src/create-panel-manager-plugin.ts
452
543
  var createPanelManagerPlugin = definePluginCreator({
453
544
  onBind: ({ bind }, opt) => {
454
545
  bind(PanelManager).to(PanelManager).inSingletonScope();
546
+ bind(PanelRestore).to(PanelRestoreImpl).inSingletonScope();
455
547
  bind(PanelManagerConfig).toConstantValue(defineConfig(opt));
548
+ bind(PanelEntityFactory).toFactory(
549
+ (context) => ({
550
+ factory,
551
+ config
552
+ }) => {
553
+ const container = context.container.createChild();
554
+ container.bind(PanelEntityFactoryConstant).toConstantValue(factory);
555
+ container.bind(PanelEntityConfigConstant).toConstantValue(config);
556
+ const panel = container.resolve(PanelEntity);
557
+ panel.init();
558
+ return panel;
559
+ }
560
+ );
456
561
  },
457
562
  onInit(ctx) {
458
563
  ctx.playground.registerLayer(PanelLayer2);
@@ -460,11 +565,17 @@ var createPanelManagerPlugin = definePluginCreator({
460
565
  panelManager.init();
461
566
  }
462
567
  });
568
+
569
+ // src/hooks/use-panel.ts
570
+ import { useContext } from "react";
571
+ var usePanel = () => useContext(PanelContext);
463
572
  export {
464
573
  DockedPanelLayer,
465
574
  PanelManager,
575
+ PanelRestore,
466
576
  ResizeBar,
467
577
  createPanelManagerPlugin,
578
+ usePanel,
468
579
  usePanelManager
469
580
  };
470
581
  //# sourceMappingURL=index.js.map