layplux 2.0.0 → 2.0.1

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.
Files changed (91) hide show
  1. package/dist/cjs/components/center-view/index.cjs +18 -28
  2. package/dist/cjs/components/corner-glow/index.cjs +11 -28
  3. package/dist/cjs/components/dropdown/index.cjs +136 -130
  4. package/dist/cjs/components/icon/index.cjs +29 -51
  5. package/dist/cjs/components/index.cjs +24 -25
  6. package/dist/cjs/components/panel-view/index.cjs +111 -114
  7. package/dist/cjs/components/popup/index.cjs +166 -151
  8. package/dist/cjs/components/title/index.cjs +34 -47
  9. package/dist/cjs/components/tooltip/index.cjs +70 -61
  10. package/dist/cjs/components/widget/index.cjs +52 -72
  11. package/dist/cjs/index.cjs +13 -40
  12. package/dist/cjs/layout/glass-overlay.cjs +15 -28
  13. package/dist/cjs/layout/layered-manager.cjs +20 -29
  14. package/dist/cjs/layout/layplux.cjs +19 -32
  15. package/dist/cjs/layout/root-pane.cjs +20 -38
  16. package/dist/cjs/layout/skeleton/bottom-area.cjs +26 -43
  17. package/dist/cjs/layout/skeleton/bottom-left-area.cjs +12 -29
  18. package/dist/cjs/layout/skeleton/bottom-right-area.cjs +11 -28
  19. package/dist/cjs/layout/skeleton/center-area.cjs +278 -371
  20. package/dist/cjs/layout/skeleton/index.cjs +7 -24
  21. package/dist/cjs/layout/skeleton/left-bottom-area.cjs +12 -29
  22. package/dist/cjs/layout/skeleton/left-top-area.cjs +12 -29
  23. package/dist/cjs/layout/skeleton/right-bottom-area.cjs +11 -28
  24. package/dist/cjs/layout/skeleton/right-top-area.cjs +11 -28
  25. package/dist/cjs/layout/skeleton/skeleton.cjs +55 -60
  26. package/dist/cjs/layout/skeleton/top-area.cjs +26 -43
  27. package/dist/cjs/locales/en-US.cjs +11 -30
  28. package/dist/cjs/locales/index.cjs +12 -30
  29. package/dist/cjs/locales/zh-CN.cjs +11 -30
  30. package/dist/cjs/managers/area.cjs +12 -25
  31. package/dist/cjs/managers/index.cjs +12 -20
  32. package/dist/cjs/managers/pane.cjs +12 -26
  33. package/dist/cjs/managers/skeleton.cjs +112 -124
  34. package/dist/cjs/managers/theme.cjs +8 -29
  35. package/dist/cjs/managers/widget-container.cjs +31 -31
  36. package/dist/cjs/managers/widget.cjs +63 -50
  37. package/dist/cjs/types/config.cjs +2 -16
  38. package/dist/cjs/types/index.cjs +2 -18
  39. package/dist/cjs/types/locale.cjs +2 -16
  40. package/dist/cjs/utils/event-bus.cjs +53 -49
  41. package/dist/cjs/utils/focus-tracker.cjs +66 -42
  42. package/dist/cjs/utils/index.cjs +23 -31
  43. package/dist/cjs/utils/unique-id.cjs +5 -24
  44. package/dist/cjs/utils/vue.cjs +20 -30
  45. package/dist/esm/components/center-view/index.mjs +15 -7
  46. package/dist/esm/components/corner-glow/index.mjs +8 -7
  47. package/dist/esm/components/dropdown/index.mjs +117 -101
  48. package/dist/esm/components/icon/index.mjs +24 -30
  49. package/dist/esm/components/index.mjs +7 -8
  50. package/dist/esm/components/panel-view/index.mjs +107 -98
  51. package/dist/esm/components/popup/index.mjs +155 -130
  52. package/dist/esm/components/title/index.mjs +29 -24
  53. package/dist/esm/components/tooltip/index.mjs +67 -40
  54. package/dist/esm/components/widget/index.mjs +45 -48
  55. package/dist/esm/index.mjs +4 -10
  56. package/dist/esm/layout/glass-overlay.mjs +12 -7
  57. package/dist/esm/layout/layered-manager.mjs +17 -8
  58. package/dist/esm/layout/layplux.mjs +14 -11
  59. package/dist/esm/layout/root-pane.mjs +16 -16
  60. package/dist/esm/layout/skeleton/bottom-area.mjs +23 -22
  61. package/dist/esm/layout/skeleton/bottom-left-area.mjs +9 -8
  62. package/dist/esm/layout/skeleton/bottom-right-area.mjs +8 -7
  63. package/dist/esm/layout/skeleton/center-area.mjs +251 -333
  64. package/dist/esm/layout/skeleton/index.mjs +1 -4
  65. package/dist/esm/layout/skeleton/left-bottom-area.mjs +9 -8
  66. package/dist/esm/layout/skeleton/left-top-area.mjs +9 -8
  67. package/dist/esm/layout/skeleton/right-bottom-area.mjs +8 -7
  68. package/dist/esm/layout/skeleton/right-top-area.mjs +8 -7
  69. package/dist/esm/layout/skeleton/skeleton.mjs +52 -39
  70. package/dist/esm/layout/skeleton/top-area.mjs +23 -22
  71. package/dist/esm/locales/en-US.mjs +9 -10
  72. package/dist/esm/locales/index.mjs +7 -9
  73. package/dist/esm/locales/zh-CN.mjs +9 -10
  74. package/dist/esm/managers/area.mjs +10 -5
  75. package/dist/esm/managers/index.mjs +3 -3
  76. package/dist/esm/managers/pane.mjs +9 -5
  77. package/dist/esm/managers/skeleton.mjs +97 -95
  78. package/dist/esm/managers/theme.mjs +6 -9
  79. package/dist/esm/managers/widget-container.mjs +28 -10
  80. package/dist/esm/managers/widget.mjs +55 -25
  81. package/dist/esm/types/config.mjs +1 -0
  82. package/dist/esm/types/index.mjs +1 -1
  83. package/dist/esm/types/locale.mjs +1 -0
  84. package/dist/esm/utils/event-bus.mjs +46 -17
  85. package/dist/esm/utils/focus-tracker.mjs +63 -23
  86. package/dist/esm/utils/index.mjs +7 -10
  87. package/dist/esm/utils/unique-id.mjs +3 -4
  88. package/dist/esm/utils/vue.mjs +13 -5
  89. package/dist/types/managers/skeleton.d.ts.map +1 -1
  90. package/dist/umd/index.js +0 -2
  91. package/package.json +11 -8
@@ -1,20 +1,12 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var managers_exports = {};
17
- module.exports = __toCommonJS(managers_exports);
18
- __reExport(managers_exports, require("./skeleton"), module.exports);
19
- __reExport(managers_exports, require("./area"), module.exports);
20
- __reExport(managers_exports, require("./widget"), module.exports);
1
+ 'use strict';
2
+
3
+ var skeleton = require('./skeleton.cjs');
4
+ var area = require('./area.cjs');
5
+ var widget = require('./widget.cjs');
6
+
7
+
8
+
9
+ exports.useSkeleton = skeleton.useSkeleton;
10
+ exports.useArea = area.useArea;
11
+ exports.isWidget = widget.isWidget;
12
+ exports.useWidget = widget.useWidget;
@@ -1,29 +1,13 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var pane_exports = {};
20
- __export(pane_exports, {
21
- usePane: () => usePane
22
- });
23
- module.exports = __toCommonJS(pane_exports);
24
- var import_vue = require("vue");
25
- function usePane(defaultViewMode = "DockPinned") {
26
- const viewMode = (0, import_vue.ref)(defaultViewMode);
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+
5
+ /**
6
+ * 没个widget都会对应自己的pane的状态
7
+ */
8
+
9
+ function usePane(defaultViewMode = 'DockPinned') {
10
+ const viewMode = vue.ref(defaultViewMode);
27
11
  function setViewMode(mode) {
28
12
  viewMode.value = mode;
29
13
  }
@@ -32,3 +16,5 @@ function usePane(defaultViewMode = "DockPinned") {
32
16
  setViewMode
33
17
  };
34
18
  }
19
+
20
+ exports.usePane = usePane;
@@ -1,135 +1,109 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var skeleton_exports = {};
20
- __export(skeleton_exports, {
21
- useSkeleton: () => useSkeleton
22
- });
23
- module.exports = __toCommonJS(skeleton_exports);
24
- var import_vue = require("vue");
25
- var import_area = require("./area");
26
- var import_widget = require("./widget");
27
- var import_widget_container = require("./widget-container");
28
- var import_utils = require("../utils");
29
- var import_theme = require("./theme");
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+ var area = require('./area.cjs');
5
+ var widget = require('./widget.cjs');
6
+ var widgetContainer = require('./widget-container.cjs');
7
+ var theme = require('./theme.cjs');
8
+ var eventBus = require('../utils/event-bus.cjs');
9
+ var index = require('../locales/index.cjs');
10
+ var focusTracker = require('../utils/focus-tracker.cjs');
11
+
30
12
  function useSkeleton() {
31
13
  const widgets = [];
32
14
  const self = {};
33
- const containers = /* @__PURE__ */ new Map();
34
- const focusTracker = new import_utils.FocusTracker();
35
- const event = (0, import_utils.createPluginEventBus)("skeleton");
36
- const locale = (0, import_vue.ref)((0, import_utils.getBuiltInLocale)("zh-CN"));
15
+ const containers = new Map();
16
+ const focusTracker$1 = new focusTracker.FocusTracker();
17
+ const event = eventBus.createPluginEventBus('skeleton');
18
+ const locale = vue.ref(index.getBuiltInLocale('zh-CN'));
37
19
  function setLocale(name) {
38
- locale.value = (0, import_utils.getBuiltInLocale)(name);
20
+ locale.value = index.getBuiltInLocale(name);
39
21
  }
40
- const theme = (0, import_vue.ref)("system");
41
- const systemDark = (0, import_vue.ref)(
42
- typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)").matches : false
43
- );
22
+ const theme$1 = vue.ref('system');
23
+ const systemDark = vue.ref(typeof window !== 'undefined' ? window.matchMedia('(prefers-color-scheme: dark)').matches : false);
44
24
  function resolveTheme() {
45
- if (theme.value === "system") {
46
- return systemDark.value ? "dark" : "light";
25
+ if (theme$1.value === 'system') {
26
+ return systemDark.value ? 'dark' : 'light';
47
27
  }
48
- return theme.value;
28
+ return theme$1.value;
49
29
  }
50
30
  function isDark() {
51
- return resolveTheme() === "dark";
31
+ return resolveTheme() === 'dark';
52
32
  }
53
33
  function setTheme(t) {
54
- theme.value = t;
34
+ theme$1.value = t;
55
35
  }
56
- const themeName = (0, import_vue.ref)("default");
36
+ const themeName = vue.ref('default');
57
37
  function setThemeName(name) {
58
38
  themeName.value = name;
59
39
  }
60
40
  function registerTheme(name, vars) {
61
- (0, import_theme.injectThemeCSS)(name, vars);
41
+ theme.injectThemeCSS(name, vars);
62
42
  }
63
- if (typeof window !== "undefined") {
64
- window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
43
+
44
+ // 监听系统主题变化
45
+ if (typeof window !== 'undefined') {
46
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
65
47
  systemDark.value = e.matches;
66
48
  });
67
49
  }
68
- const topArea = (0, import_area.useArea)(
69
- {
70
- createContainer
71
- },
72
- "topArea",
73
- (config, container) => createWidget(config, container)
74
- );
75
- const bottomArea = (0, import_area.useArea)(
76
- {
77
- createContainer
78
- },
79
- "bottomArea",
80
- (config, container) => createWidget(config, container)
81
- );
82
- const leftTopArea = (0, import_area.useArea)(
83
- {
84
- createContainer
85
- },
86
- "leftTopArea",
87
- (config, container) => createWidget(config, container)
88
- );
89
- const leftBottomArea = (0, import_area.useArea)(
90
- {
91
- createContainer
92
- },
93
- "leftBottomArea",
94
- (config, container) => createWidget(config, container)
95
- );
96
- const rightTopArea = (0, import_area.useArea)(
97
- { createContainer },
98
- "rightTopArea",
99
- (config, container) => createWidget(config, container)
100
- );
101
- const rightBottomArea = (0, import_area.useArea)(
102
- { createContainer },
103
- "rightBottomArea",
104
- (config, container) => createWidget(config, container)
105
- );
106
- const bottomRightArea = (0, import_area.useArea)(
107
- { createContainer },
108
- "bottomRightArea",
109
- (config, container) => createWidget(config, container)
110
- );
111
- const bottomLeftArea = (0, import_area.useArea)(
112
- {
113
- createContainer
114
- },
115
- "bottomLeftArea",
116
- (config, container) => createWidget(config, container)
117
- );
118
- const centerArea = (0, import_area.useArea)(
119
- { createContainer },
120
- "centerArea",
121
- (config, container) => createWidget(config, container)
122
- );
50
+
51
+ // 顶部工具栏
52
+ const topArea = area.useArea({
53
+ createContainer
54
+ }, 'topArea', (config, container) => createWidget(config, container));
55
+
56
+ // 底部状态栏
57
+ const bottomArea = area.useArea({
58
+ createContainer
59
+ }, 'bottomArea', (config, container) => createWidget(config, container));
60
+
61
+ // 左侧顶部主区域
62
+ const leftTopArea = area.useArea({
63
+ createContainer
64
+ }, 'leftTopArea', (config, container) => createWidget(config, container));
65
+
66
+ // 左侧底部快捷区域
67
+ const leftBottomArea = area.useArea({
68
+ createContainer
69
+ }, 'leftBottomArea', (config, container) => createWidget(config, container));
70
+
71
+ // 右侧顶部主区域
72
+ const rightTopArea = area.useArea({
73
+ createContainer
74
+ }, 'rightTopArea', (config, container) => createWidget(config, container));
75
+
76
+ // 右侧底部区域
77
+ const rightBottomArea = area.useArea({
78
+ createContainer
79
+ }, 'rightBottomArea', (config, container) => createWidget(config, container));
80
+
81
+ // 右侧最底部快捷操作
82
+ const bottomRightArea = area.useArea({
83
+ createContainer
84
+ }, 'bottomRightArea', (config, container) => createWidget(config, container));
85
+
86
+ // 左侧最底部快捷操作(交互型)
87
+ const bottomLeftArea = area.useArea({
88
+ createContainer
89
+ }, 'bottomLeftArea', (config, container) => createWidget(config, container));
90
+
91
+ // 中心区域
92
+ const centerArea = area.useArea({
93
+ createContainer
94
+ }, 'centerArea', (config, container) => createWidget(config, container));
123
95
  function createWidget(config, container) {
124
- if ((0, import_widget.isWidget)(config)) {
96
+ if (widget.isWidget(config)) {
125
97
  return config;
126
98
  }
127
- const widget = (0, import_widget.useWidget)(config, container, self);
128
- widgets.push(widget);
129
- event.emitGlobal("skeleton:widget-added", { widget });
130
- return widget;
99
+ const widget$1 = widget.useWidget(config, container, self);
100
+ widgets.push(widget$1);
101
+ event.emitGlobal('skeleton:widget-added', {
102
+ widget: widget$1
103
+ });
104
+ return widget$1;
131
105
  }
132
- const focusedId = (0, import_vue.ref)(null);
106
+ const focusedId = vue.ref(null);
133
107
  function toggleFocus(id) {
134
108
  if (focusedId.value === id) {
135
109
  blur();
@@ -139,42 +113,54 @@ function useSkeleton() {
139
113
  }
140
114
  function focus(id) {
141
115
  focusedId.value = id;
142
- event.emitGlobal("skeleton:focus-changed", { focusedId: id });
116
+ event.emitGlobal('skeleton:focus-changed', {
117
+ focusedId: id
118
+ });
143
119
  }
144
120
  function blur() {
145
121
  focusedId.value = null;
146
- event.emitGlobal("skeleton:focus-changed", { focusedId: null });
122
+ event.emitGlobal('skeleton:focus-changed', {
123
+ focusedId: null
124
+ });
147
125
  }
148
126
  function add(config, extraConfig) {
127
+ // TODO: 处理extraConfig
149
128
  if (extraConfig) {
150
- config = { ...config, ...extraConfig };
129
+ config = {
130
+ ...config,
131
+ ...extraConfig
132
+ };
151
133
  }
152
- const { area } = config;
153
- if (area === "topArea") {
134
+ const {
135
+ area
136
+ } = config;
137
+ if (area === 'topArea') {
154
138
  topArea.add(config);
155
- } else if (area === "bottomArea") {
139
+ } else if (area === 'bottomArea') {
156
140
  bottomArea.add(config);
157
- } else if (area === "leftTopArea") {
141
+ } else if (area === 'leftTopArea') {
158
142
  leftTopArea.add(config);
159
- } else if (area === "leftBottomArea") {
143
+ } else if (area === 'leftBottomArea') {
160
144
  leftBottomArea.add(config);
161
- } else if (area === "bottomLeftArea") {
145
+ } else if (area === 'bottomLeftArea') {
162
146
  bottomLeftArea.add(config);
163
- } else if (area === "rightTopArea") {
147
+ } else if (area === 'rightTopArea') {
164
148
  rightTopArea.add(config);
165
- } else if (area === "rightBottomArea") {
149
+ } else if (area === 'rightBottomArea') {
166
150
  rightBottomArea.add(config);
167
- } else if (area === "bottomRightArea") {
151
+ } else if (area === 'bottomRightArea') {
168
152
  bottomRightArea.add(config);
169
- } else if (area === "centerArea") {
153
+ } else if (area === 'centerArea') {
170
154
  centerArea.add(config);
171
155
  }
172
156
  }
173
157
  function createContainer(name, handle) {
174
- const container = (0, import_widget_container.useWidgetContainer)(handle, self);
158
+ const container = widgetContainer.useWidgetContainer(handle, self);
175
159
  containers.set(name, container);
176
160
  return container;
177
161
  }
162
+
163
+ // 4. 填充 self 的真正属性
178
164
  Object.assign(self, {
179
165
  widgets,
180
166
  topArea,
@@ -187,11 +173,11 @@ function useSkeleton() {
187
173
  bottomLeftArea,
188
174
  centerArea,
189
175
  focusedId,
190
- focusTracker,
176
+ focusTracker: focusTracker$1,
191
177
  event,
192
178
  locale,
193
179
  setLocale,
194
- theme,
180
+ theme: theme$1,
195
181
  resolveTheme,
196
182
  isDark,
197
183
  setTheme,
@@ -206,3 +192,5 @@ function useSkeleton() {
206
192
  });
207
193
  return self;
208
194
  }
195
+
196
+ exports.useSkeleton = useSkeleton;
@@ -1,37 +1,16 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var theme_exports = {};
20
- __export(theme_exports, {
21
- injectThemeCSS: () => injectThemeCSS
22
- });
23
- module.exports = __toCommonJS(theme_exports);
1
+ 'use strict';
2
+
3
+ /** 为指定 theme 注入 CSS 变量样式,重复注册会替换 */
24
4
  function injectThemeCSS(name, vars) {
25
5
  const styleId = `layplux-theme-${name}`;
26
6
  let styleEl = document.getElementById(styleId);
27
7
  if (!styleEl) {
28
- styleEl = document.createElement("style");
8
+ styleEl = document.createElement('style');
29
9
  styleEl.id = styleId;
30
10
  document.head.appendChild(styleEl);
31
11
  }
32
- const varLines = Object.entries(vars).map(([key, value]) => ` ${key}: ${value};`).join("\n");
33
- styleEl.textContent = `.layplux-root[data-theme='${name}'] {
34
- ${varLines}
35
- }
36
- `;
12
+ const varLines = Object.entries(vars).map(([key, value]) => ` ${key}: ${value};`).join('\n');
13
+ styleEl.textContent = `.layplux-root[data-theme='${name}'] {\n${varLines}\n}\n`;
37
14
  }
15
+
16
+ exports.injectThemeCSS = injectThemeCSS;
@@ -1,31 +1,22 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var widget_container_exports = {};
20
- __export(widget_container_exports, {
21
- useWidgetContainer: () => useWidgetContainer
22
- });
23
- module.exports = __toCommonJS(widget_container_exports);
24
- var import_vue = require("vue");
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+
5
+ /**
6
+ * handle 函数签名:把原始 item(config widget)转换成 widget 实例。
7
+ * 第二个参数是所属 container 的引用,方便在创建 widget 时回引。
8
+ */
9
+
10
+ /**
11
+ * widget container 用于管理 widget 的添加、删除、获取等操作
12
+ * T widget 的类型
13
+ * G widgetconfig 的配置类型
14
+ */
25
15
  function useWidgetContainer(handle, skeleton) {
26
16
  const maps = {};
27
- const items = (0, import_vue.ref)([]);
28
- const activeId = (0, import_vue.ref)(null);
17
+ const items = vue.ref([]);
18
+ const activeId = vue.ref(null); // ✅ 单一数据源
19
+
29
20
  const self = {
30
21
  items,
31
22
  activeId,
@@ -39,6 +30,7 @@ function useWidgetContainer(handle, skeleton) {
39
30
  toggleActive
40
31
  };
41
32
  function add(item) {
33
+ // 将config转换为widget,将创建widget的能力交给外部,并把 container 自身传出去
42
34
  const nItem = handle(item, self);
43
35
  const origin = get(nItem.name);
44
36
  if (origin === nItem) return origin;
@@ -66,23 +58,29 @@ function useWidgetContainer(handle, skeleton) {
66
58
  const i = items.value.indexOf(item);
67
59
  if (i > -1) items.value.splice(i, 1);
68
60
  delete maps[name];
69
- skeleton.event.emitGlobal("skeleton:widget-removed", { name });
61
+ skeleton.event.emitGlobal('skeleton:widget-removed', {
62
+ name
63
+ });
70
64
  return item;
71
65
  }
72
66
  function activate(id) {
73
67
  if (!maps[id]) return;
74
68
  activeId.value = id;
75
69
  skeleton.focus(id);
76
- maps[id].focusable.active();
77
- skeleton.event.emitGlobal(`widget:${id}:activated`, { widget: maps[id] });
70
+ maps[id].focusable.active(); // 面板激活 → 同步焦点栈
71
+ skeleton.event.emitGlobal(`widget:${id}:activated`, {
72
+ widget: maps[id]
73
+ });
78
74
  }
79
75
  function deactivate() {
80
76
  const current = activeId.value;
81
77
  activeId.value = null;
82
78
  skeleton.blur();
83
79
  if (current && maps[current]) {
84
- maps[current].focusable.suspense();
85
- skeleton.event.emitGlobal(`widget:${current}:deactivated`, { widget: maps[current] });
80
+ maps[current].focusable.suspense(); // 面板收起 → 从焦点栈移除
81
+ skeleton.event.emitGlobal(`widget:${current}:deactivated`, {
82
+ widget: maps[current]
83
+ });
86
84
  }
87
85
  }
88
86
  function toggleActive(id) {
@@ -94,3 +92,5 @@ function useWidgetContainer(handle, skeleton) {
94
92
  }
95
93
  return self;
96
94
  }
95
+
96
+ exports.useWidgetContainer = useWidgetContainer;