@flowgram-vue/panel-manager-plugin 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/dist/index.cjs +757 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +187 -0
- package/dist/index.js +746 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
- package/src/components/panel-layer/css.ts +68 -0
- package/src/components/panel-layer/docked-panel-layer.ts +28 -0
- package/src/components/panel-layer/index.ts +7 -0
- package/src/components/panel-layer/panel-layer.ts +59 -0
- package/src/components/panel-layer/panel.ts +167 -0
- package/src/components/resize-bar/index.ts +109 -0
- package/src/composables/use-global-css.ts +30 -0
- package/src/composables/use-panel-manager.ts +10 -0
- package/src/composables/use-panel.ts +32 -0
- package/src/contexts.ts +10 -0
- package/src/create-panel-manager-plugin.ts +51 -0
- package/src/env.d.ts +10 -0
- package/src/index.ts +20 -0
- package/src/services/index.ts +9 -0
- package/src/services/panel-config.ts +58 -0
- package/src/services/panel-factory.ts +138 -0
- package/src/services/panel-layer.ts +77 -0
- package/src/services/panel-manager.ts +132 -0
- package/src/services/panel-restore.ts +25 -0
- package/src/types.ts +34 -0
- package/src/utils.ts +22 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,757 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@flowgram-vue/core');
|
|
4
|
+
var vanilla = require('zustand/vanilla');
|
|
5
|
+
var nanoid = require('nanoid');
|
|
6
|
+
var inversify = require('inversify');
|
|
7
|
+
var vue = require('vue');
|
|
8
|
+
var utils = require('@flowgram-vue/utils');
|
|
9
|
+
var clsx = require('clsx');
|
|
10
|
+
var shallow = require('zustand/shallow');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var clsx__default = /*#__PURE__*/_interopDefault(clsx);
|
|
15
|
+
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
18
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
19
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
20
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
21
|
+
if (decorator = decorators[i])
|
|
22
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
23
|
+
if (kind && result) __defProp(target, key, result);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var PanelRestore = /* @__PURE__ */ Symbol("PanelRestore");
|
|
27
|
+
var PanelRestoreImpl = class {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.map = /* @__PURE__ */ new Map();
|
|
30
|
+
}
|
|
31
|
+
store(k, v) {
|
|
32
|
+
this.map.set(k, v);
|
|
33
|
+
}
|
|
34
|
+
restore(k) {
|
|
35
|
+
return this.map.get(k);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
PanelRestoreImpl = __decorateClass([
|
|
39
|
+
inversify.injectable()
|
|
40
|
+
], PanelRestoreImpl);
|
|
41
|
+
var ResizeBarInner = vue.defineComponent({
|
|
42
|
+
name: "ResizeBar",
|
|
43
|
+
props: {
|
|
44
|
+
size: { type: Number, required: true },
|
|
45
|
+
direction: { type: String, default: void 0 },
|
|
46
|
+
onResize: { type: Function, required: true }
|
|
47
|
+
},
|
|
48
|
+
setup(props) {
|
|
49
|
+
const currentPoint = vue.ref(null);
|
|
50
|
+
const isDragging = vue.ref(false);
|
|
51
|
+
const isHovered = vue.ref(false);
|
|
52
|
+
const isVertical = () => props.direction === "vertical";
|
|
53
|
+
const onMouseMove = (e) => {
|
|
54
|
+
const delta = currentPoint.value - (isVertical() ? e.clientX : e.clientY);
|
|
55
|
+
props.onResize(props.size + delta);
|
|
56
|
+
};
|
|
57
|
+
const onMouseUp = () => {
|
|
58
|
+
currentPoint.value = null;
|
|
59
|
+
document.body.removeEventListener("mouseup", onMouseUp);
|
|
60
|
+
document.body.removeEventListener("mousemove", onMouseMove);
|
|
61
|
+
isDragging.value = false;
|
|
62
|
+
};
|
|
63
|
+
vue.onBeforeUnmount(() => {
|
|
64
|
+
document.body.removeEventListener("mouseup", onMouseUp);
|
|
65
|
+
document.body.removeEventListener("mousemove", onMouseMove);
|
|
66
|
+
});
|
|
67
|
+
return () => vue.h(
|
|
68
|
+
"div",
|
|
69
|
+
{
|
|
70
|
+
onMousedown: (e) => {
|
|
71
|
+
currentPoint.value = isVertical() ? e.clientX : e.clientY;
|
|
72
|
+
e.stopPropagation();
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
isDragging.value = true;
|
|
75
|
+
document.body.addEventListener("mouseup", onMouseUp);
|
|
76
|
+
document.body.addEventListener("mousemove", onMouseMove);
|
|
77
|
+
},
|
|
78
|
+
onMouseenter: () => {
|
|
79
|
+
isHovered.value = true;
|
|
80
|
+
},
|
|
81
|
+
onMouseleave: () => {
|
|
82
|
+
isHovered.value = false;
|
|
83
|
+
},
|
|
84
|
+
style: {
|
|
85
|
+
position: "absolute",
|
|
86
|
+
top: "0",
|
|
87
|
+
left: "0",
|
|
88
|
+
zIndex: 999,
|
|
89
|
+
display: "flex",
|
|
90
|
+
alignItems: "center",
|
|
91
|
+
justifyContent: "center",
|
|
92
|
+
pointerEvents: "auto",
|
|
93
|
+
...isVertical() ? {
|
|
94
|
+
cursor: "ew-resize",
|
|
95
|
+
height: "100%",
|
|
96
|
+
marginLeft: "-5px",
|
|
97
|
+
width: "10px"
|
|
98
|
+
} : {
|
|
99
|
+
cursor: "ns-resize",
|
|
100
|
+
width: "100%",
|
|
101
|
+
marginTop: "-5px",
|
|
102
|
+
height: "10px"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
[
|
|
107
|
+
vue.h("div", {
|
|
108
|
+
style: {
|
|
109
|
+
...isVertical() ? {
|
|
110
|
+
width: "3px",
|
|
111
|
+
height: "100%"
|
|
112
|
+
} : {
|
|
113
|
+
height: "3px",
|
|
114
|
+
width: "100%"
|
|
115
|
+
},
|
|
116
|
+
backgroundColor: isDragging.value || isHovered.value ? "var(--g-playground-line)" : "transparent"
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
function ResizeBar(props) {
|
|
124
|
+
return vue.h(ResizeBarInner, props);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/services/panel-config.ts
|
|
128
|
+
var PanelManagerConfig = /* @__PURE__ */ Symbol("PanelManagerConfig");
|
|
129
|
+
var defineConfig = (config) => {
|
|
130
|
+
const defaultConfig = {
|
|
131
|
+
right: {
|
|
132
|
+
max: 1
|
|
133
|
+
},
|
|
134
|
+
bottom: {
|
|
135
|
+
max: 1
|
|
136
|
+
},
|
|
137
|
+
dockedRight: {
|
|
138
|
+
max: 1
|
|
139
|
+
},
|
|
140
|
+
dockedBottom: {
|
|
141
|
+
max: 1
|
|
142
|
+
},
|
|
143
|
+
factories: [],
|
|
144
|
+
autoResize: true,
|
|
145
|
+
layerProps: {},
|
|
146
|
+
resizeBarRender: ResizeBar,
|
|
147
|
+
getPopupContainer: (ctx) => ctx.playground.node.parentNode
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
...defaultConfig,
|
|
151
|
+
...config
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/utils.ts
|
|
156
|
+
var merge = (...objs) => {
|
|
157
|
+
const result = {};
|
|
158
|
+
for (const obj of objs) {
|
|
159
|
+
if (!obj || typeof obj !== "object") continue;
|
|
160
|
+
for (const key of Object.keys(obj)) {
|
|
161
|
+
const value = obj[key];
|
|
162
|
+
if (result[key] === void 0) {
|
|
163
|
+
result[key] = value;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/services/panel-factory.ts
|
|
171
|
+
var PanelEntityFactory = /* @__PURE__ */ Symbol("PanelEntityFactory");
|
|
172
|
+
var PanelEntityFactoryConstant = /* @__PURE__ */ Symbol("PanelEntityFactoryConstant");
|
|
173
|
+
var PanelEntityConfigConstant = /* @__PURE__ */ Symbol("PanelEntityConfigConstant");
|
|
174
|
+
var PANEL_SIZE_DEFAULT = 400;
|
|
175
|
+
var PanelEntity = class {
|
|
176
|
+
constructor() {
|
|
177
|
+
this.initialized = false;
|
|
178
|
+
/** 实例唯一标识 */
|
|
179
|
+
this.id = nanoid.nanoid();
|
|
180
|
+
/** 渲染缓存 */
|
|
181
|
+
this.node = null;
|
|
182
|
+
}
|
|
183
|
+
get area() {
|
|
184
|
+
return this.config.area;
|
|
185
|
+
}
|
|
186
|
+
get mode() {
|
|
187
|
+
return this.config.area.startsWith("docked") ? "docked" : "floating";
|
|
188
|
+
}
|
|
189
|
+
get key() {
|
|
190
|
+
return this.factory.key;
|
|
191
|
+
}
|
|
192
|
+
get renderer() {
|
|
193
|
+
if (!this.node) {
|
|
194
|
+
this.node = this.factory.render(this.config.props);
|
|
195
|
+
}
|
|
196
|
+
return this.node;
|
|
197
|
+
}
|
|
198
|
+
get fullscreen() {
|
|
199
|
+
return this.store.getState().fullscreen;
|
|
200
|
+
}
|
|
201
|
+
set fullscreen(next) {
|
|
202
|
+
this.store.setState({ fullscreen: next });
|
|
203
|
+
}
|
|
204
|
+
get resizable() {
|
|
205
|
+
if (this.fullscreen) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return this.factory.resize !== void 0 ? this.factory.resize : this.globalConfig.autoResize;
|
|
209
|
+
}
|
|
210
|
+
get keepDOM() {
|
|
211
|
+
return this.factory.keepDOM;
|
|
212
|
+
}
|
|
213
|
+
get visible() {
|
|
214
|
+
return this.store.getState().visible;
|
|
215
|
+
}
|
|
216
|
+
set visible(next) {
|
|
217
|
+
this.store.setState({ visible: next });
|
|
218
|
+
}
|
|
219
|
+
get layer() {
|
|
220
|
+
return document.querySelector(
|
|
221
|
+
this.mode ? ".gedit-flow-panel-layer-wrap-docked" : ".gedit-flow-panel-layer-wrap-floating"
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
init() {
|
|
225
|
+
if (this.initialized) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
this.initialized = true;
|
|
229
|
+
const cache = this.restore.restore(this.key);
|
|
230
|
+
const initialState = merge(
|
|
231
|
+
{
|
|
232
|
+
size: this.config.defaultSize,
|
|
233
|
+
fullscreen: this.config.fullscreen
|
|
234
|
+
},
|
|
235
|
+
cache ? cache : {},
|
|
236
|
+
{
|
|
237
|
+
size: this.factory.defaultSize || PANEL_SIZE_DEFAULT,
|
|
238
|
+
fullscreen: this.factory.fullscreen || false,
|
|
239
|
+
...this.factory.keepDOM ? { visible: true } : {}
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
this.store = vanilla.createStore(() => initialState);
|
|
243
|
+
}
|
|
244
|
+
mergeState() {
|
|
245
|
+
}
|
|
246
|
+
dispose() {
|
|
247
|
+
this.restore.store(this.key, this.store.getState());
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
__decorateClass([
|
|
251
|
+
inversify.inject(PanelRestore)
|
|
252
|
+
], PanelEntity.prototype, "restore", 2);
|
|
253
|
+
__decorateClass([
|
|
254
|
+
inversify.inject(PanelEntityFactoryConstant)
|
|
255
|
+
], PanelEntity.prototype, "factory", 2);
|
|
256
|
+
__decorateClass([
|
|
257
|
+
inversify.inject(PanelEntityConfigConstant)
|
|
258
|
+
], PanelEntity.prototype, "config", 2);
|
|
259
|
+
__decorateClass([
|
|
260
|
+
inversify.inject(PanelManagerConfig)
|
|
261
|
+
], PanelEntity.prototype, "globalConfig", 2);
|
|
262
|
+
PanelEntity = __decorateClass([
|
|
263
|
+
inversify.injectable()
|
|
264
|
+
], PanelEntity);
|
|
265
|
+
exports.PanelManager = class PanelManager {
|
|
266
|
+
constructor() {
|
|
267
|
+
this.panelRegistry = /* @__PURE__ */ new Map();
|
|
268
|
+
this.panels = /* @__PURE__ */ new Map();
|
|
269
|
+
this.onPanelsChangeEvent = new utils.Emitter();
|
|
270
|
+
this.onPanelsChange = this.onPanelsChangeEvent.event;
|
|
271
|
+
}
|
|
272
|
+
init() {
|
|
273
|
+
this.config.factories.forEach((factory) => this.register(factory));
|
|
274
|
+
}
|
|
275
|
+
/** registry panel factory */
|
|
276
|
+
register(factory) {
|
|
277
|
+
this.panelRegistry.set(factory.key, factory);
|
|
278
|
+
}
|
|
279
|
+
/** open panel */
|
|
280
|
+
open(key, area = "right", options) {
|
|
281
|
+
const factory = this.panelRegistry.get(key);
|
|
282
|
+
if (!factory) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const sameKeyPanels = this.getPanels(area).filter((p) => p.key === key);
|
|
286
|
+
if (factory.keepDOM && sameKeyPanels.length) {
|
|
287
|
+
const [panel] = sameKeyPanels;
|
|
288
|
+
this.panels.delete(panel.id);
|
|
289
|
+
this.panels.set(panel.id, panel);
|
|
290
|
+
panel.visible = true;
|
|
291
|
+
} else {
|
|
292
|
+
if (!factory.allowDuplicates && sameKeyPanels.length) {
|
|
293
|
+
sameKeyPanels.forEach((p) => this.remove(p.id));
|
|
294
|
+
}
|
|
295
|
+
const panel = this.createPanel({
|
|
296
|
+
factory,
|
|
297
|
+
config: {
|
|
298
|
+
area,
|
|
299
|
+
...options
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
this.panels.set(panel.id, panel);
|
|
303
|
+
}
|
|
304
|
+
this.trim(area);
|
|
305
|
+
this.onPanelsChangeEvent.fire();
|
|
306
|
+
}
|
|
307
|
+
/** close panel */
|
|
308
|
+
close(key) {
|
|
309
|
+
const panels = this.getPanels();
|
|
310
|
+
const closedPanels = key ? panels.filter((p) => p.key === key) : panels;
|
|
311
|
+
closedPanels.forEach((panel) => {
|
|
312
|
+
this.remove(panel.id);
|
|
313
|
+
});
|
|
314
|
+
this.onPanelsChangeEvent.fire();
|
|
315
|
+
}
|
|
316
|
+
trim(area) {
|
|
317
|
+
const panels = this.getPanels(area).filter((p) => !p.keepDOM || p.visible);
|
|
318
|
+
const areaConfig = this.getAreaConfig(area);
|
|
319
|
+
while (panels.length > areaConfig.max) {
|
|
320
|
+
const removed = panels.shift();
|
|
321
|
+
if (removed) {
|
|
322
|
+
this.remove(removed.id);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
remove(id) {
|
|
327
|
+
const panel = this.panels.get(id);
|
|
328
|
+
if (!panel) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (panel.keepDOM) {
|
|
332
|
+
panel.visible = false;
|
|
333
|
+
} else {
|
|
334
|
+
panel.dispose();
|
|
335
|
+
this.panels.delete(id);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
getPanels(area) {
|
|
339
|
+
const panels = [];
|
|
340
|
+
this.panels.forEach((panel) => {
|
|
341
|
+
if (!area || panel.area === area) {
|
|
342
|
+
panels.push(panel);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
return panels;
|
|
346
|
+
}
|
|
347
|
+
getAreaConfig(area) {
|
|
348
|
+
switch (area) {
|
|
349
|
+
case "docked-bottom":
|
|
350
|
+
return this.config.dockedBottom;
|
|
351
|
+
case "docked-right":
|
|
352
|
+
return this.config.dockedRight;
|
|
353
|
+
case "bottom":
|
|
354
|
+
return this.config.bottom;
|
|
355
|
+
case "right":
|
|
356
|
+
default:
|
|
357
|
+
return this.config.right;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
dispose() {
|
|
361
|
+
this.onPanelsChangeEvent.dispose();
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
__decorateClass([
|
|
365
|
+
inversify.inject(PanelManagerConfig)
|
|
366
|
+
], exports.PanelManager.prototype, "config", 2);
|
|
367
|
+
__decorateClass([
|
|
368
|
+
inversify.inject(PanelEntityFactory)
|
|
369
|
+
], exports.PanelManager.prototype, "createPanel", 2);
|
|
370
|
+
exports.PanelManager = __decorateClass([
|
|
371
|
+
inversify.injectable()
|
|
372
|
+
], exports.PanelManager);
|
|
373
|
+
var useGlobalCSS = ({ cssText, id, cleanup }) => {
|
|
374
|
+
vue.onMounted(() => {
|
|
375
|
+
if (typeof document === "undefined") return;
|
|
376
|
+
if (document.getElementById(id)) return;
|
|
377
|
+
const style = document.createElement("style");
|
|
378
|
+
style.id = id;
|
|
379
|
+
style.textContent = cssText;
|
|
380
|
+
document.head.appendChild(style);
|
|
381
|
+
});
|
|
382
|
+
vue.onBeforeUnmount(() => {
|
|
383
|
+
const existing = document.getElementById(id);
|
|
384
|
+
if (existing && cleanup) existing.remove();
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
var usePanelManager = () => core.useService(exports.PanelManager);
|
|
388
|
+
|
|
389
|
+
// src/contexts.ts
|
|
390
|
+
var PanelContextKey = /* @__PURE__ */ Symbol("PanelContext");
|
|
391
|
+
|
|
392
|
+
// src/composables/use-panel.ts
|
|
393
|
+
var usePanel = () => {
|
|
394
|
+
const panel = vue.inject(PanelContextKey);
|
|
395
|
+
if (!panel) {
|
|
396
|
+
throw new Error("usePanel must be used within a PanelContext provider");
|
|
397
|
+
}
|
|
398
|
+
return panel;
|
|
399
|
+
};
|
|
400
|
+
var usePanelStore = (selector) => {
|
|
401
|
+
const panel = usePanel();
|
|
402
|
+
const selected = vue.shallowRef(selector(panel.store.getState()));
|
|
403
|
+
const unsubscribe = panel.store.subscribe((state) => {
|
|
404
|
+
const next = selector(state);
|
|
405
|
+
if (!shallow.shallow(selected.value, next)) {
|
|
406
|
+
selected.value = next;
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
vue.onBeforeUnmount(unsubscribe);
|
|
410
|
+
return selected;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// src/components/panel-layer/panel.ts
|
|
414
|
+
var PanelItem = vue.defineComponent({
|
|
415
|
+
name: "PanelItem",
|
|
416
|
+
props: {
|
|
417
|
+
panel: { type: Object, required: true },
|
|
418
|
+
hidden: { type: Boolean, default: false }
|
|
419
|
+
},
|
|
420
|
+
setup(props) {
|
|
421
|
+
const panelManager = usePanelManager();
|
|
422
|
+
const elRef = vue.ref(null);
|
|
423
|
+
const isHorizontal = vue.computed(() => ["right", "docked-right"].includes(props.panel.area));
|
|
424
|
+
const storeState = usePanelStore((s) => ({
|
|
425
|
+
size: s.size,
|
|
426
|
+
fullscreen: s.fullscreen
|
|
427
|
+
}));
|
|
428
|
+
const layerSize = vue.ref(storeState.value.size);
|
|
429
|
+
const currentSize = vue.computed(
|
|
430
|
+
() => storeState.value.fullscreen ? layerSize.value : storeState.value.size
|
|
431
|
+
);
|
|
432
|
+
const sizeStyle = vue.computed(
|
|
433
|
+
() => isHorizontal.value ? { width: `${currentSize.value}px` } : { height: `${currentSize.value}px` }
|
|
434
|
+
);
|
|
435
|
+
const handleResize = (next) => {
|
|
436
|
+
let nextSize = next;
|
|
437
|
+
if (typeof props.panel.factory.maxSize === "number" && nextSize > props.panel.factory.maxSize) {
|
|
438
|
+
nextSize = props.panel.factory.maxSize;
|
|
439
|
+
} else if (typeof props.panel.factory.minSize === "number" && nextSize < props.panel.factory.minSize) {
|
|
440
|
+
nextSize = props.panel.factory.minSize;
|
|
441
|
+
}
|
|
442
|
+
props.panel.store.setState({ size: nextSize });
|
|
443
|
+
};
|
|
444
|
+
vue.onMounted(() => {
|
|
445
|
+
if (elRef.value && !storeState.value.fullscreen) {
|
|
446
|
+
const { width, height } = elRef.value.getBoundingClientRect();
|
|
447
|
+
const realSize = isHorizontal.value ? width : height;
|
|
448
|
+
props.panel.store.setState({ size: realSize });
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
let observer;
|
|
452
|
+
const syncObserver = () => {
|
|
453
|
+
observer?.disconnect();
|
|
454
|
+
observer = void 0;
|
|
455
|
+
if (!storeState.value.fullscreen) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const layer = props.panel.layer;
|
|
459
|
+
if (!layer) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
observer = new ResizeObserver(([entry]) => {
|
|
463
|
+
const { width, height } = entry.contentRect;
|
|
464
|
+
layerSize.value = isHorizontal.value ? width : height;
|
|
465
|
+
});
|
|
466
|
+
observer.observe(layer);
|
|
467
|
+
};
|
|
468
|
+
vue.onMounted(syncObserver);
|
|
469
|
+
vue.onBeforeUnmount(() => observer?.disconnect());
|
|
470
|
+
return () => {
|
|
471
|
+
void storeState.value.fullscreen;
|
|
472
|
+
syncObserver();
|
|
473
|
+
const resizeBar = props.panel.resizable ? panelManager.config.resizeBarRender({
|
|
474
|
+
size: storeState.value.size,
|
|
475
|
+
direction: isHorizontal.value ? "vertical" : "horizontal",
|
|
476
|
+
onResize: handleResize
|
|
477
|
+
}) : null;
|
|
478
|
+
return vue.h(
|
|
479
|
+
"div",
|
|
480
|
+
{
|
|
481
|
+
class: clsx__default.default(
|
|
482
|
+
"gedit-flow-panel-wrap",
|
|
483
|
+
isHorizontal.value ? "panel-horizontal" : "panel-vertical"
|
|
484
|
+
),
|
|
485
|
+
ref: elRef,
|
|
486
|
+
style: {
|
|
487
|
+
display: props.hidden ? "none" : "block",
|
|
488
|
+
...props.panel.factory.style,
|
|
489
|
+
...props.panel.config.style,
|
|
490
|
+
...sizeStyle.value
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
[resizeBar, props.panel.renderer]
|
|
494
|
+
);
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
var PanelContextWrap = vue.defineComponent({
|
|
499
|
+
name: "PanelContextWrap",
|
|
500
|
+
props: {
|
|
501
|
+
panel: { type: Object, required: true },
|
|
502
|
+
hidden: { type: Boolean, default: false }
|
|
503
|
+
},
|
|
504
|
+
setup(props) {
|
|
505
|
+
vue.provide(PanelContextKey, props.panel);
|
|
506
|
+
return () => vue.h(PanelItem, { panel: props.panel, hidden: props.hidden });
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
var PanelArea = vue.defineComponent({
|
|
510
|
+
name: "PanelArea",
|
|
511
|
+
props: {
|
|
512
|
+
area: { type: String, required: true }
|
|
513
|
+
},
|
|
514
|
+
setup(props) {
|
|
515
|
+
const panelManager = usePanelManager();
|
|
516
|
+
const panels = vue.ref(panelManager.getPanels(props.area));
|
|
517
|
+
let pending;
|
|
518
|
+
const dispose = panelManager.onPanelsChange(() => {
|
|
519
|
+
if (pending) {
|
|
520
|
+
clearTimeout(pending);
|
|
521
|
+
}
|
|
522
|
+
pending = setTimeout(() => {
|
|
523
|
+
panels.value = panelManager.getPanels(props.area);
|
|
524
|
+
}, 0);
|
|
525
|
+
});
|
|
526
|
+
vue.onBeforeUnmount(() => {
|
|
527
|
+
if (pending) {
|
|
528
|
+
clearTimeout(pending);
|
|
529
|
+
}
|
|
530
|
+
dispose.dispose();
|
|
531
|
+
});
|
|
532
|
+
return () => panels.value.map(
|
|
533
|
+
(panel) => vue.h(PanelContextWrap, {
|
|
534
|
+
key: panel.id,
|
|
535
|
+
panel,
|
|
536
|
+
hidden: !!(panel.keepDOM && !panel.visible)
|
|
537
|
+
})
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// src/components/panel-layer/css.ts
|
|
543
|
+
var globalCSS = `
|
|
544
|
+
.gedit-flow-panel-layer-wrap * {
|
|
545
|
+
box-sizing: border-box;
|
|
546
|
+
}
|
|
547
|
+
.gedit-flow-panel-layer-wrap {
|
|
548
|
+
position: absolute;
|
|
549
|
+
top: 0;
|
|
550
|
+
left: 0;
|
|
551
|
+
display: flex;
|
|
552
|
+
width: 100%;
|
|
553
|
+
height: 100%;
|
|
554
|
+
overflow: hidden;
|
|
555
|
+
}
|
|
556
|
+
.gedit-flow-panel-layer-wrap-docked {
|
|
557
|
+
|
|
558
|
+
}
|
|
559
|
+
.gedit-flow-panel-layer-wrap-floating {
|
|
560
|
+
pointer-events: none;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
.gedit-flow-panel-left-area {
|
|
564
|
+
width: 100%;
|
|
565
|
+
min-width: 0;
|
|
566
|
+
flex-grow: 0;
|
|
567
|
+
flex-shrink: 1;
|
|
568
|
+
display: flex;
|
|
569
|
+
flex-direction: column;
|
|
570
|
+
}
|
|
571
|
+
.gedit-flow-panel-right-area {
|
|
572
|
+
height: 100%;
|
|
573
|
+
flex-grow: 1;
|
|
574
|
+
flex-shrink: 0;
|
|
575
|
+
min-width: 0;
|
|
576
|
+
display: flex;
|
|
577
|
+
max-width: 100%;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
.gedit-flow-panel-main-area {
|
|
581
|
+
position: relative;
|
|
582
|
+
overflow: hidden;
|
|
583
|
+
flex-grow: 0;
|
|
584
|
+
flex-shrink: 1;
|
|
585
|
+
width: 100%;
|
|
586
|
+
height: 100%;
|
|
587
|
+
}
|
|
588
|
+
.gedit-flow-panel-bottom-area {
|
|
589
|
+
flex-grow: 1;
|
|
590
|
+
flex-shrink: 0;
|
|
591
|
+
width: 100%;
|
|
592
|
+
min-height: 0;
|
|
593
|
+
}
|
|
594
|
+
.gedit-flow-panel-wrap {
|
|
595
|
+
pointer-events: auto;
|
|
596
|
+
overflow: auto;
|
|
597
|
+
position: relative;
|
|
598
|
+
}
|
|
599
|
+
.gedit-flow-panel-wrap.panel-horizontal {
|
|
600
|
+
height: 100%;
|
|
601
|
+
}
|
|
602
|
+
.gedit-flow-panel-wrap.panel-vertical {
|
|
603
|
+
width: 100%;
|
|
604
|
+
}
|
|
605
|
+
`;
|
|
606
|
+
|
|
607
|
+
// src/components/panel-layer/panel-layer.ts
|
|
608
|
+
var PanelLayer = vue.defineComponent({
|
|
609
|
+
name: "PanelLayer",
|
|
610
|
+
props: {
|
|
611
|
+
mode: { type: String, default: "floating" },
|
|
612
|
+
className: { type: String, default: void 0 },
|
|
613
|
+
style: { type: Object, default: void 0 }
|
|
614
|
+
},
|
|
615
|
+
setup(props, { slots }) {
|
|
616
|
+
useGlobalCSS({
|
|
617
|
+
cssText: globalCSS,
|
|
618
|
+
id: "flow-panel-layer-css"
|
|
619
|
+
});
|
|
620
|
+
return () => vue.h(
|
|
621
|
+
"div",
|
|
622
|
+
{
|
|
623
|
+
class: clsx__default.default(
|
|
624
|
+
"gedit-flow-panel-layer-wrap",
|
|
625
|
+
props.mode === "docked" && "gedit-flow-panel-layer-wrap-docked",
|
|
626
|
+
props.mode === "floating" && "gedit-flow-panel-layer-wrap-floating",
|
|
627
|
+
props.className
|
|
628
|
+
),
|
|
629
|
+
style: props.style
|
|
630
|
+
},
|
|
631
|
+
[
|
|
632
|
+
vue.h("div", { class: "gedit-flow-panel-left-area" }, [
|
|
633
|
+
vue.h("div", { class: "gedit-flow-panel-main-area" }, slots.default?.()),
|
|
634
|
+
vue.h("div", { class: "gedit-flow-panel-bottom-area" }, [
|
|
635
|
+
vue.h(PanelArea, { area: props.mode === "docked" ? "docked-bottom" : "bottom" })
|
|
636
|
+
])
|
|
637
|
+
]),
|
|
638
|
+
vue.h("div", { class: "gedit-flow-panel-right-area" }, [
|
|
639
|
+
vue.h(PanelArea, { area: props.mode === "docked" ? "docked-right" : "right" })
|
|
640
|
+
])
|
|
641
|
+
]
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
var DockedPanelLayer = vue.defineComponent({
|
|
646
|
+
name: "DockedPanelLayer",
|
|
647
|
+
setup(_props, { attrs, slots }) {
|
|
648
|
+
return () => vue.h(
|
|
649
|
+
PanelLayer,
|
|
650
|
+
{
|
|
651
|
+
mode: "docked",
|
|
652
|
+
className: attrs.className,
|
|
653
|
+
style: attrs.style
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
default: () => slots.default?.()
|
|
657
|
+
}
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
// src/services/panel-layer.ts
|
|
663
|
+
var PanelLayer2 = class extends core.Layer {
|
|
664
|
+
constructor() {
|
|
665
|
+
super(...arguments);
|
|
666
|
+
this.panelRoot = utils.domUtils.createDivWithClass("gedit-flow-panel-layer");
|
|
667
|
+
this.layout = null;
|
|
668
|
+
}
|
|
669
|
+
onReady() {
|
|
670
|
+
this.panelConfig.getPopupContainer(this.pluginContext).appendChild(this.panelRoot);
|
|
671
|
+
this.toDispose.push(
|
|
672
|
+
utils.Disposable.create(() => {
|
|
673
|
+
this.panelRoot.remove();
|
|
674
|
+
})
|
|
675
|
+
);
|
|
676
|
+
const commonStyle = {
|
|
677
|
+
pointerEvents: "none",
|
|
678
|
+
width: "100%",
|
|
679
|
+
height: "100%",
|
|
680
|
+
position: "absolute",
|
|
681
|
+
left: 0,
|
|
682
|
+
top: 0,
|
|
683
|
+
zIndex: 100
|
|
684
|
+
};
|
|
685
|
+
utils.domUtils.setStyle(this.panelRoot, commonStyle);
|
|
686
|
+
}
|
|
687
|
+
render() {
|
|
688
|
+
if (!this.layout) {
|
|
689
|
+
const { children, ...layoutProps } = this.panelConfig.layerProps;
|
|
690
|
+
const playgroundContainer = this.playgroundContainer;
|
|
691
|
+
const panelRoot = this.panelRoot;
|
|
692
|
+
const LayerProvide = vue.defineComponent({
|
|
693
|
+
name: "PanelLayerProvide",
|
|
694
|
+
setup() {
|
|
695
|
+
vue.provide(core.PlaygroundVueContainerKey, playgroundContainer);
|
|
696
|
+
try {
|
|
697
|
+
vue.provide(core.PlaygroundVueRefKey, playgroundContainer.get(core.Playground));
|
|
698
|
+
} catch {
|
|
699
|
+
}
|
|
700
|
+
return () => vue.h(vue.Teleport, { to: panelRoot }, [
|
|
701
|
+
vue.h(PanelLayer, layoutProps, () => children)
|
|
702
|
+
]);
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
this.layout = vue.h(LayerProvide);
|
|
706
|
+
}
|
|
707
|
+
return this.layout;
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
__decorateClass([
|
|
711
|
+
inversify.inject(PanelManagerConfig)
|
|
712
|
+
], PanelLayer2.prototype, "panelConfig", 2);
|
|
713
|
+
__decorateClass([
|
|
714
|
+
inversify.inject(core.PluginContext)
|
|
715
|
+
], PanelLayer2.prototype, "pluginContext", 2);
|
|
716
|
+
__decorateClass([
|
|
717
|
+
inversify.inject(core.PlaygroundContainerFactory)
|
|
718
|
+
], PanelLayer2.prototype, "playgroundContainer", 2);
|
|
719
|
+
PanelLayer2 = __decorateClass([
|
|
720
|
+
inversify.injectable()
|
|
721
|
+
], PanelLayer2);
|
|
722
|
+
|
|
723
|
+
// src/create-panel-manager-plugin.ts
|
|
724
|
+
var createPanelManagerPlugin = core.definePluginCreator({
|
|
725
|
+
onBind: ({ bind }, opt) => {
|
|
726
|
+
bind(exports.PanelManager).to(exports.PanelManager).inSingletonScope();
|
|
727
|
+
bind(PanelRestore).to(PanelRestoreImpl).inSingletonScope();
|
|
728
|
+
bind(PanelManagerConfig).toConstantValue(defineConfig(opt));
|
|
729
|
+
bind(PanelEntityFactory).toFactory(
|
|
730
|
+
(context) => ({
|
|
731
|
+
factory,
|
|
732
|
+
config
|
|
733
|
+
}) => {
|
|
734
|
+
const container = context.container.createChild();
|
|
735
|
+
container.bind(PanelEntityFactoryConstant).toConstantValue(factory);
|
|
736
|
+
container.bind(PanelEntityConfigConstant).toConstantValue(config);
|
|
737
|
+
const panel = container.resolve(PanelEntity);
|
|
738
|
+
panel.init();
|
|
739
|
+
return panel;
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
},
|
|
743
|
+
onInit(ctx) {
|
|
744
|
+
ctx.playground.registerLayer(PanelLayer2);
|
|
745
|
+
const panelManager = ctx.container.get(exports.PanelManager);
|
|
746
|
+
panelManager.init();
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
exports.DockedPanelLayer = DockedPanelLayer;
|
|
751
|
+
exports.PanelRestore = PanelRestore;
|
|
752
|
+
exports.ResizeBar = ResizeBar;
|
|
753
|
+
exports.createPanelManagerPlugin = createPanelManagerPlugin;
|
|
754
|
+
exports.usePanel = usePanel;
|
|
755
|
+
exports.usePanelManager = usePanelManager;
|
|
756
|
+
//# sourceMappingURL=index.cjs.map
|
|
757
|
+
//# sourceMappingURL=index.cjs.map
|