UNPKG

2.18 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { singleton } from 'mana-syringe'; // export const LayoutContribution = Syringe.defineToken('LayoutContribution');
3// // eslint-disable-next-line @typescript-eslint/no-redeclare
4// export interface LayoutContribution {
5// registerLayout: (layoutRegistry: LayoutRegistry) => void;
6// }
7
8var LayoutRegistry =
9/** @class */
10function () {
11 function LayoutRegistry() {
12 this.registry = new Map();
13 }
14
15 LayoutRegistry_1 = LayoutRegistry;
16 Object.defineProperty(LayoutRegistry.prototype, "size", {
17 get: function get() {
18 return this.registry.size;
19 },
20 enumerable: false,
21 configurable: true
22 });
23
24 LayoutRegistry.prototype.hasLayout = function (name) {
25 return this.registry.has(name);
26 };
27 /**
28 *
29 * @param name layout name, default to 'absolute'
30 * @returns layout object
31 */
32
33
34 LayoutRegistry.prototype.getLayout = function (name) {
35 if (name === void 0) {
36 name = 'absolute';
37 }
38
39 if (!this.hasLayout(name)) {
40 throw new Error("invalid layout property: ".concat(name));
41 }
42
43 return this.registry.get(name);
44 };
45
46 LayoutRegistry.prototype.updateLayout = function (name, layout) {
47 this.registry.set(name, layout);
48 };
49
50 LayoutRegistry.prototype.registerLayout = function (name, layout) {
51 if (name === '') {
52 throw new TypeError("layout name cant't be empty");
53 }
54
55 if (LayoutRegistry_1.reservedLayout.includes(name)) {
56 throw new Error("layout name '".concat(name, "' is a system reserved layout name, please use another name"));
57 }
58
59 if (this.hasLayout(name)) {
60 throw new Error("layout '".concat(name, "' already exist."));
61 }
62
63 this.registry.set(name, layout);
64 };
65
66 LayoutRegistry.prototype.deleteLayout = function (name) {
67 this.registry.delete(name);
68 };
69
70 var LayoutRegistry_1; // 系统保留的布局名称,外部用户不能使用
71 // private static reservedLayout = ['relative', 'absolute', 'fixed', 'flex', 'dagre', 'autolayout'];
72
73 LayoutRegistry.reservedLayout = [];
74 LayoutRegistry = LayoutRegistry_1 = __decorate([singleton()], LayoutRegistry);
75 return LayoutRegistry;
76}();
77
78export { LayoutRegistry };
\No newline at end of file