@univerjs/ui 0.1.0-alpha.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 (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -0
  3. package/lib/cjs/index.js +4671 -0
  4. package/lib/cjs/locale/en-US.js +46 -0
  5. package/lib/cjs/locale/zh-CN.js +35 -0
  6. package/lib/esm/index.js +4507 -0
  7. package/lib/esm/locale/en-US.js +25 -0
  8. package/lib/esm/locale/zh-CN.js +14 -0
  9. package/lib/index.css +474 -0
  10. package/lib/types/BaseComponent.d.ts +8 -0
  11. package/lib/types/BaseComponent.d.ts.map +1 -0
  12. package/lib/types/commands/operations/toggle-shortcut-panel.operation.d.ts +4 -0
  13. package/lib/types/commands/operations/toggle-shortcut-panel.operation.d.ts.map +1 -0
  14. package/lib/types/common/component-manager.d.ts +14 -0
  15. package/lib/types/common/component-manager.d.ts.map +1 -0
  16. package/lib/types/common/index.d.ts +3 -0
  17. package/lib/types/common/index.d.ts.map +1 -0
  18. package/lib/types/common/lifecycle.d.ts +4 -0
  19. package/lib/types/common/lifecycle.d.ts.map +1 -0
  20. package/lib/types/common/z-index-manager.d.ts +8 -0
  21. package/lib/types/common/z-index-manager.d.ts.map +1 -0
  22. package/lib/types/components/custom-label/CustomLabel.d.ts +14 -0
  23. package/lib/types/components/custom-label/CustomLabel.d.ts.map +1 -0
  24. package/lib/types/components/custom-label/index.d.ts +2 -0
  25. package/lib/types/components/custom-label/index.d.ts.map +1 -0
  26. package/lib/types/components/hooks/observable.d.ts +4 -0
  27. package/lib/types/components/hooks/observable.d.ts.map +1 -0
  28. package/lib/types/components/index.d.ts +3 -0
  29. package/lib/types/components/index.d.ts.map +1 -0
  30. package/lib/types/components/menu/Menu.d.ts +11 -0
  31. package/lib/types/components/menu/Menu.d.ts.map +1 -0
  32. package/lib/types/components/menu/index.d.ts +2 -0
  33. package/lib/types/components/menu/index.d.ts.map +1 -0
  34. package/lib/types/components/notification/Notification.d.ts +41 -0
  35. package/lib/types/components/notification/Notification.d.ts.map +1 -0
  36. package/lib/types/controllers/error/error.controller.d.ts +8 -0
  37. package/lib/types/controllers/error/error.controller.d.ts.map +1 -0
  38. package/lib/types/controllers/menus/menus.d.ts +5 -0
  39. package/lib/types/controllers/menus/menus.d.ts.map +1 -0
  40. package/lib/types/controllers/shared-shortcut.controller.d.ts +25 -0
  41. package/lib/types/controllers/shared-shortcut.controller.d.ts.map +1 -0
  42. package/lib/types/controllers/shortcut-display/menu.d.ts +3 -0
  43. package/lib/types/controllers/shortcut-display/menu.d.ts.map +1 -0
  44. package/lib/types/controllers/shortcut-display/shortcut-panel.controller.d.ts +10 -0
  45. package/lib/types/controllers/shortcut-display/shortcut-panel.controller.d.ts.map +1 -0
  46. package/lib/types/controllers/ui/ui-desktop.controller.d.ts +55 -0
  47. package/lib/types/controllers/ui/ui-desktop.controller.d.ts.map +1 -0
  48. package/lib/types/controllers/ui/ui.controller.d.ts +14 -0
  49. package/lib/types/controllers/ui/ui.controller.d.ts.map +1 -0
  50. package/lib/types/index.d.ts +30 -0
  51. package/lib/types/index.d.ts.map +1 -0
  52. package/lib/types/locale/en-US.d.ts +23 -0
  53. package/lib/types/locale/en-US.d.ts.map +1 -0
  54. package/lib/types/locale/index.d.ts +3 -0
  55. package/lib/types/locale/index.d.ts.map +1 -0
  56. package/lib/types/locale/zh-CN.d.ts +12 -0
  57. package/lib/types/locale/zh-CN.d.ts.map +1 -0
  58. package/lib/types/services/before-close/before-close.service.d.ts +21 -0
  59. package/lib/types/services/before-close/before-close.service.d.ts.map +1 -0
  60. package/lib/types/services/clipboard/clipboard-interface.service.d.ts +36 -0
  61. package/lib/types/services/clipboard/clipboard-interface.service.d.ts.map +1 -0
  62. package/lib/types/services/clipboard/clipboard.command.d.ts +5 -0
  63. package/lib/types/services/clipboard/clipboard.command.d.ts.map +1 -0
  64. package/lib/types/services/confirm/confirm.service.d.ts +10 -0
  65. package/lib/types/services/confirm/confirm.service.d.ts.map +1 -0
  66. package/lib/types/services/confirm/desktop-confirm.service.d.ts +12 -0
  67. package/lib/types/services/confirm/desktop-confirm.service.d.ts.map +1 -0
  68. package/lib/types/services/contextmenu/contextmenu.service.d.ts +18 -0
  69. package/lib/types/services/contextmenu/contextmenu.service.d.ts.map +1 -0
  70. package/lib/types/services/dialog/desktop-dialog.service.d.ts +12 -0
  71. package/lib/types/services/dialog/desktop-dialog.service.d.ts.map +1 -0
  72. package/lib/types/services/dialog/dialog.service.d.ts +10 -0
  73. package/lib/types/services/dialog/dialog.service.d.ts.map +1 -0
  74. package/lib/types/services/focus/focus.service.d.ts +22 -0
  75. package/lib/types/services/focus/focus.service.d.ts.map +1 -0
  76. package/lib/types/services/local-storage/local-storage.service.d.ts +11 -0
  77. package/lib/types/services/local-storage/local-storage.service.d.ts.map +1 -0
  78. package/lib/types/services/menu/menu.d.ts +103 -0
  79. package/lib/types/services/menu/menu.d.ts.map +1 -0
  80. package/lib/types/services/menu/menu.service.d.ts +28 -0
  81. package/lib/types/services/menu/menu.service.d.ts.map +1 -0
  82. package/lib/types/services/message/desktop-message.service.d.ts +11 -0
  83. package/lib/types/services/message/desktop-message.service.d.ts.map +1 -0
  84. package/lib/types/services/message/message.service.d.ts +8 -0
  85. package/lib/types/services/message/message.service.d.ts.map +1 -0
  86. package/lib/types/services/notification/desktop-notification.service.d.ts +7 -0
  87. package/lib/types/services/notification/desktop-notification.service.d.ts.map +1 -0
  88. package/lib/types/services/notification/notification.service.d.ts +7 -0
  89. package/lib/types/services/notification/notification.service.d.ts.map +1 -0
  90. package/lib/types/services/platform/platform.service.d.ts +15 -0
  91. package/lib/types/services/platform/platform.service.d.ts.map +1 -0
  92. package/lib/types/services/shortcut/keycode.d.ts +79 -0
  93. package/lib/types/services/shortcut/keycode.d.ts.map +1 -0
  94. package/lib/types/services/shortcut/shortcut-experience.service.d.ts +31 -0
  95. package/lib/types/services/shortcut/shortcut-experience.service.d.ts.map +1 -0
  96. package/lib/types/services/shortcut/shortcut-panel.service.d.ts +10 -0
  97. package/lib/types/services/shortcut/shortcut-panel.service.d.ts.map +1 -0
  98. package/lib/types/services/shortcut/shortcut.service.d.ts +55 -0
  99. package/lib/types/services/shortcut/shortcut.service.d.ts.map +1 -0
  100. package/lib/types/services/sidebar/desktop-sidebar.service.d.ts +12 -0
  101. package/lib/types/services/sidebar/desktop-sidebar.service.d.ts.map +1 -0
  102. package/lib/types/services/sidebar/sidebar.service.d.ts +10 -0
  103. package/lib/types/services/sidebar/sidebar.service.d.ts.map +1 -0
  104. package/lib/types/ui-plugin.d.ts +20 -0
  105. package/lib/types/ui-plugin.d.ts.map +1 -0
  106. package/lib/types/utils/cell.d.ts +34 -0
  107. package/lib/types/utils/cell.d.ts.map +1 -0
  108. package/lib/types/utils/index.d.ts +3 -0
  109. package/lib/types/utils/index.d.ts.map +1 -0
  110. package/lib/types/utils/util.d.ts +2 -0
  111. package/lib/types/utils/util.d.ts.map +1 -0
  112. package/lib/types/views/App.d.ts +13 -0
  113. package/lib/types/views/App.d.ts.map +1 -0
  114. package/lib/types/views/components/ComponentContainer.d.ts +6 -0
  115. package/lib/types/views/components/ComponentContainer.d.ts.map +1 -0
  116. package/lib/types/views/components/confirm-part/ConfirmPart.d.ts +3 -0
  117. package/lib/types/views/components/confirm-part/ConfirmPart.d.ts.map +1 -0
  118. package/lib/types/views/components/confirm-part/interface.d.ts +8 -0
  119. package/lib/types/views/components/confirm-part/interface.d.ts.map +1 -0
  120. package/lib/types/views/components/context-menu/ContextMenu.d.ts +5 -0
  121. package/lib/types/views/components/context-menu/ContextMenu.d.ts.map +1 -0
  122. package/lib/types/views/components/dialog-part/DialogPart.d.ts +3 -0
  123. package/lib/types/views/components/dialog-part/DialogPart.d.ts.map +1 -0
  124. package/lib/types/views/components/dialog-part/interface.d.ts +10 -0
  125. package/lib/types/views/components/dialog-part/interface.d.ts.map +1 -0
  126. package/lib/types/views/components/doc-bars/Button/ToolbarButton.d.ts +28 -0
  127. package/lib/types/views/components/doc-bars/Button/ToolbarButton.d.ts.map +1 -0
  128. package/lib/types/views/components/doc-bars/MenuBar.d.ts +7 -0
  129. package/lib/types/views/components/doc-bars/MenuBar.d.ts.map +1 -0
  130. package/lib/types/views/components/doc-bars/Toolbar.d.ts +3 -0
  131. package/lib/types/views/components/doc-bars/Toolbar.d.ts.map +1 -0
  132. package/lib/types/views/components/doc-bars/ToolbarItem.d.ts +4 -0
  133. package/lib/types/views/components/doc-bars/ToolbarItem.d.ts.map +1 -0
  134. package/lib/types/views/components/doc-bars/hooks/menu.d.ts +10 -0
  135. package/lib/types/views/components/doc-bars/hooks/menu.d.ts.map +1 -0
  136. package/lib/types/views/components/shortcut-panel/ShortcutPanel.d.ts +6 -0
  137. package/lib/types/views/components/shortcut-panel/ShortcutPanel.d.ts.map +1 -0
  138. package/lib/types/views/components/sidebar/Sidebar.d.ts +3 -0
  139. package/lib/types/views/components/sidebar/Sidebar.d.ts.map +1 -0
  140. package/lib/types/views/components/sidebar/interface.d.ts +11 -0
  141. package/lib/types/views/components/sidebar/interface.d.ts.map +1 -0
  142. package/lib/types/views/parts.d.ts +3 -0
  143. package/lib/types/views/parts.d.ts.map +1 -0
  144. package/package.json +77 -0
@@ -0,0 +1,4671 @@
1
+ "use strict";
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function _array_without_holes(arr) {
11
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
12
+ }
13
+ function _assert_this_initialized(self) {
14
+ if (self === void 0) {
15
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
16
+ }
17
+ return self;
18
+ }
19
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20
+ try {
21
+ var info = gen[key](arg);
22
+ var value = info.value;
23
+ } catch (error) {
24
+ reject(error);
25
+ return;
26
+ }
27
+ if (info.done) {
28
+ resolve(value);
29
+ } else {
30
+ Promise.resolve(value).then(_next, _throw);
31
+ }
32
+ }
33
+ function _async_to_generator(fn) {
34
+ return function() {
35
+ var self = this, args = arguments;
36
+ return new Promise(function(resolve, reject) {
37
+ var gen = fn.apply(self, args);
38
+ function _next(value) {
39
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
40
+ }
41
+ function _throw(err) {
42
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
43
+ }
44
+ _next(undefined);
45
+ });
46
+ };
47
+ }
48
+ function _class_call_check(instance, Constructor) {
49
+ if (!(instance instanceof Constructor)) {
50
+ throw new TypeError("Cannot call a class as a function");
51
+ }
52
+ }
53
+ function _defineProperties(target, props) {
54
+ for(var i = 0; i < props.length; i++){
55
+ var descriptor = props[i];
56
+ descriptor.enumerable = descriptor.enumerable || false;
57
+ descriptor.configurable = true;
58
+ if ("value" in descriptor) descriptor.writable = true;
59
+ Object.defineProperty(target, descriptor.key, descriptor);
60
+ }
61
+ }
62
+ function _create_class(Constructor, protoProps, staticProps) {
63
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
64
+ if (staticProps) _defineProperties(Constructor, staticProps);
65
+ return Constructor;
66
+ }
67
+ function _define_property(obj, key, value) {
68
+ if (key in obj) {
69
+ Object.defineProperty(obj, key, {
70
+ value: value,
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true
74
+ });
75
+ } else {
76
+ obj[key] = value;
77
+ }
78
+ return obj;
79
+ }
80
+ function _get(target, property, receiver) {
81
+ if (typeof Reflect !== "undefined" && Reflect.get) {
82
+ _get = Reflect.get;
83
+ } else {
84
+ _get = function get(target, property, receiver) {
85
+ var base = _super_prop_base(target, property);
86
+ if (!base) return;
87
+ var desc = Object.getOwnPropertyDescriptor(base, property);
88
+ if (desc.get) {
89
+ return desc.get.call(receiver || target);
90
+ }
91
+ return desc.value;
92
+ };
93
+ }
94
+ return _get(target, property, receiver || target);
95
+ }
96
+ function _get_prototype_of(o) {
97
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
98
+ return o.__proto__ || Object.getPrototypeOf(o);
99
+ };
100
+ return _get_prototype_of(o);
101
+ }
102
+ function _inherits(subClass, superClass) {
103
+ if (typeof superClass !== "function" && superClass !== null) {
104
+ throw new TypeError("Super expression must either be null or a function");
105
+ }
106
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
107
+ constructor: {
108
+ value: subClass,
109
+ writable: true,
110
+ configurable: true
111
+ }
112
+ });
113
+ if (superClass) _set_prototype_of(subClass, superClass);
114
+ }
115
+ function _instanceof(left, right) {
116
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
117
+ return !!right[Symbol.hasInstance](left);
118
+ } else {
119
+ return left instanceof right;
120
+ }
121
+ }
122
+ function _iterable_to_array(iter) {
123
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
124
+ }
125
+ function _iterable_to_array_limit(arr, i) {
126
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
127
+ if (_i == null) return;
128
+ var _arr = [];
129
+ var _n = true;
130
+ var _d = false;
131
+ var _s, _e;
132
+ try {
133
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
134
+ _arr.push(_s.value);
135
+ if (i && _arr.length === i) break;
136
+ }
137
+ } catch (err) {
138
+ _d = true;
139
+ _e = err;
140
+ } finally{
141
+ try {
142
+ if (!_n && _i["return"] != null) _i["return"]();
143
+ } finally{
144
+ if (_d) throw _e;
145
+ }
146
+ }
147
+ return _arr;
148
+ }
149
+ function _non_iterable_rest() {
150
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
151
+ }
152
+ function _non_iterable_spread() {
153
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
154
+ }
155
+ function _object_spread(target) {
156
+ for(var i = 1; i < arguments.length; i++){
157
+ var source = arguments[i] != null ? arguments[i] : {};
158
+ var ownKeys = Object.keys(source);
159
+ if (typeof Object.getOwnPropertySymbols === "function") {
160
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
161
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
162
+ }));
163
+ }
164
+ ownKeys.forEach(function(key) {
165
+ _define_property(target, key, source[key]);
166
+ });
167
+ }
168
+ return target;
169
+ }
170
+ function ownKeys(object, enumerableOnly) {
171
+ var keys = Object.keys(object);
172
+ if (Object.getOwnPropertySymbols) {
173
+ var symbols = Object.getOwnPropertySymbols(object);
174
+ if (enumerableOnly) {
175
+ symbols = symbols.filter(function(sym) {
176
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
177
+ });
178
+ }
179
+ keys.push.apply(keys, symbols);
180
+ }
181
+ return keys;
182
+ }
183
+ function _object_spread_props(target, source) {
184
+ source = source != null ? source : {};
185
+ if (Object.getOwnPropertyDescriptors) {
186
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
187
+ } else {
188
+ ownKeys(Object(source)).forEach(function(key) {
189
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
190
+ });
191
+ }
192
+ return target;
193
+ }
194
+ function _object_without_properties(source, excluded) {
195
+ if (source == null) return {};
196
+ var target = _object_without_properties_loose(source, excluded);
197
+ var key, i;
198
+ if (Object.getOwnPropertySymbols) {
199
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
200
+ for(i = 0; i < sourceSymbolKeys.length; i++){
201
+ key = sourceSymbolKeys[i];
202
+ if (excluded.indexOf(key) >= 0) continue;
203
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
204
+ target[key] = source[key];
205
+ }
206
+ }
207
+ return target;
208
+ }
209
+ function _object_without_properties_loose(source, excluded) {
210
+ if (source == null) return {};
211
+ var target = {};
212
+ var sourceKeys = Object.keys(source);
213
+ var key, i;
214
+ for(i = 0; i < sourceKeys.length; i++){
215
+ key = sourceKeys[i];
216
+ if (excluded.indexOf(key) >= 0) continue;
217
+ target[key] = source[key];
218
+ }
219
+ return target;
220
+ }
221
+ function _possible_constructor_return(self, call) {
222
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
223
+ return call;
224
+ }
225
+ return _assert_this_initialized(self);
226
+ }
227
+ function _set_prototype_of(o, p) {
228
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
229
+ o.__proto__ = p;
230
+ return o;
231
+ };
232
+ return _set_prototype_of(o, p);
233
+ }
234
+ function _sliced_to_array(arr, i) {
235
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
236
+ }
237
+ function _super_prop_base(object, property) {
238
+ while(!Object.prototype.hasOwnProperty.call(object, property)){
239
+ object = _get_prototype_of(object);
240
+ if (object === null) break;
241
+ }
242
+ return object;
243
+ }
244
+ function _to_consumable_array(arr) {
245
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
246
+ }
247
+ function _type_of(obj) {
248
+ "@swc/helpers - typeof";
249
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
250
+ }
251
+ function _unsupported_iterable_to_array(o, minLen) {
252
+ if (!o) return;
253
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
254
+ var n = Object.prototype.toString.call(o).slice(8, -1);
255
+ if (n === "Object" && o.constructor) n = o.constructor.name;
256
+ if (n === "Map" || n === "Set") return Array.from(n);
257
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
258
+ }
259
+ function _is_native_reflect_construct() {
260
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
261
+ if (Reflect.construct.sham) return false;
262
+ if (typeof Proxy === "function") return true;
263
+ try {
264
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
265
+ return true;
266
+ } catch (e) {
267
+ return false;
268
+ }
269
+ }
270
+ function _create_super(Derived) {
271
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
272
+ return function _createSuperInternal() {
273
+ var Super = _get_prototype_of(Derived), result;
274
+ if (hasNativeReflectConstruct) {
275
+ var NewTarget = _get_prototype_of(this).constructor;
276
+ result = Reflect.construct(Super, arguments, NewTarget);
277
+ } else {
278
+ result = Super.apply(this, arguments);
279
+ }
280
+ return _possible_constructor_return(this, result);
281
+ };
282
+ }
283
+ function _ts_generator(thisArg, body) {
284
+ var f, y, t, g, _ = {
285
+ label: 0,
286
+ sent: function() {
287
+ if (t[0] & 1) throw t[1];
288
+ return t[1];
289
+ },
290
+ trys: [],
291
+ ops: []
292
+ };
293
+ return g = {
294
+ next: verb(0),
295
+ "throw": verb(1),
296
+ "return": verb(2)
297
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
298
+ return this;
299
+ }), g;
300
+ function verb(n) {
301
+ return function(v) {
302
+ return step([
303
+ n,
304
+ v
305
+ ]);
306
+ };
307
+ }
308
+ function step(op) {
309
+ if (f) throw new TypeError("Generator is already executing.");
310
+ while(_)try {
311
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
312
+ if (y = 0, t) op = [
313
+ op[0] & 2,
314
+ t.value
315
+ ];
316
+ switch(op[0]){
317
+ case 0:
318
+ case 1:
319
+ t = op;
320
+ break;
321
+ case 4:
322
+ _.label++;
323
+ return {
324
+ value: op[1],
325
+ done: false
326
+ };
327
+ case 5:
328
+ _.label++;
329
+ y = op[1];
330
+ op = [
331
+ 0
332
+ ];
333
+ continue;
334
+ case 7:
335
+ op = _.ops.pop();
336
+ _.trys.pop();
337
+ continue;
338
+ default:
339
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
340
+ _ = 0;
341
+ continue;
342
+ }
343
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
344
+ _.label = op[1];
345
+ break;
346
+ }
347
+ if (op[0] === 6 && _.label < t[1]) {
348
+ _.label = t[1];
349
+ t = op;
350
+ break;
351
+ }
352
+ if (t && _.label < t[2]) {
353
+ _.label = t[2];
354
+ _.ops.push(op);
355
+ break;
356
+ }
357
+ if (t[2]) _.ops.pop();
358
+ _.trys.pop();
359
+ continue;
360
+ }
361
+ op = body.call(thisArg, _);
362
+ } catch (e) {
363
+ op = [
364
+ 6,
365
+ e
366
+ ];
367
+ y = 0;
368
+ } finally{
369
+ f = t = 0;
370
+ }
371
+ if (op[0] & 5) throw op[1];
372
+ return {
373
+ value: op[0] ? op[1] : void 0,
374
+ done: true
375
+ };
376
+ }
377
+ }
378
+ var _import_core29_Plugin, _class;
379
+ var __create = Object.create;
380
+ var __defProp = Object.defineProperty;
381
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
382
+ var __getOwnPropNames = Object.getOwnPropertyNames;
383
+ var __getProtoOf = Object.getPrototypeOf;
384
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
385
+ var __export = function(target, all) {
386
+ for(var name in all)__defProp(target, name, {
387
+ get: all[name],
388
+ enumerable: true
389
+ });
390
+ };
391
+ var __copyProps = function(to, from, except, desc) {
392
+ if (from && typeof from === "object" || typeof from === "function") {
393
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
394
+ try {
395
+ var _loop = function() {
396
+ var key = _step.value;
397
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
398
+ get: function() {
399
+ return from[key];
400
+ },
401
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
402
+ });
403
+ };
404
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
405
+ } catch (err) {
406
+ _didIteratorError = true;
407
+ _iteratorError = err;
408
+ } finally{
409
+ try {
410
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
411
+ _iterator.return();
412
+ }
413
+ } finally{
414
+ if (_didIteratorError) {
415
+ throw _iteratorError;
416
+ }
417
+ }
418
+ }
419
+ }
420
+ return to;
421
+ };
422
+ var __toESM = function(mod, isNodeMode, target) {
423
+ return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
424
+ // file that has been converted to a CommonJS file using a Babel-
425
+ // compatible transform (i.e. "__esModule" has not been set), then set
426
+ // "default" to the CommonJS "module.exports" for node compatibility.
427
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
428
+ value: mod,
429
+ enumerable: true
430
+ }) : target, mod);
431
+ };
432
+ var __toCommonJS = function(mod) {
433
+ return __copyProps(__defProp({}, "__esModule", {
434
+ value: true
435
+ }), mod);
436
+ };
437
+ var __decorateClass = function(decorators, target, key, kind) {
438
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
439
+ for(var i = decorators.length - 1, decorator; i >= 0; i--)if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
440
+ if (kind && result) __defProp(target, key, result);
441
+ return result;
442
+ };
443
+ var __decorateParam = function(index, decorator) {
444
+ return function(target, key) {
445
+ return decorator(target, key, index);
446
+ };
447
+ };
448
+ // src/index.ts
449
+ var src_exports = {};
450
+ __export(src_exports, {
451
+ BrowserClipboardService: function() {
452
+ return BrowserClipboardService;
453
+ },
454
+ ComponentManager: function() {
455
+ return ComponentManager;
456
+ },
457
+ CopyCommand: function() {
458
+ return CopyCommand;
459
+ },
460
+ CopyShortcutItem: function() {
461
+ return CopyShortcutItem;
462
+ },
463
+ CustomLabel: function() {
464
+ return CustomLabel;
465
+ },
466
+ CutCommand: function() {
467
+ return CutCommand;
468
+ },
469
+ CutShortcutItem: function() {
470
+ return CutShortcutItem;
471
+ },
472
+ DesktopBeforeCloseService: function() {
473
+ return DesktopBeforeCloseService;
474
+ },
475
+ DesktopConfirmService: function() {
476
+ return DesktopConfirmService;
477
+ },
478
+ DesktopContextMenuService: function() {
479
+ return DesktopContextMenuService;
480
+ },
481
+ DesktopDialogService: function() {
482
+ return DesktopDialogService;
483
+ },
484
+ DesktopMenuService: function() {
485
+ return DesktopMenuService;
486
+ },
487
+ DesktopMessageService: function() {
488
+ return DesktopMessageService;
489
+ },
490
+ DesktopNotificationService: function() {
491
+ return DesktopNotificationService;
492
+ },
493
+ DesktopPlatformService: function() {
494
+ return DesktopPlatformService;
495
+ },
496
+ DesktopShortcutService: function() {
497
+ return DesktopShortcutService;
498
+ },
499
+ DesktopSidebarService: function() {
500
+ return DesktopSidebarService;
501
+ },
502
+ DesktopUIPart: function() {
503
+ return DesktopUIPart;
504
+ },
505
+ HTML_CLIPBOARD_MIME_TYPE: function() {
506
+ return HTML_CLIPBOARD_MIME_TYPE;
507
+ },
508
+ IBeforeCloseService: function() {
509
+ return IBeforeCloseService;
510
+ },
511
+ IClipboardInterfaceService: function() {
512
+ return IClipboardInterfaceService;
513
+ },
514
+ IConfirmService: function() {
515
+ return IConfirmService;
516
+ },
517
+ IContextMenuService: function() {
518
+ return IContextMenuService;
519
+ },
520
+ IDialogService: function() {
521
+ return IDialogService;
522
+ },
523
+ IMenuService: function() {
524
+ return IMenuService;
525
+ },
526
+ IMessageService: function() {
527
+ return IMessageService;
528
+ },
529
+ INotificationService: function() {
530
+ return INotificationService;
531
+ },
532
+ IPlatformService: function() {
533
+ return IPlatformService;
534
+ },
535
+ IShortcutService: function() {
536
+ return IShortcutService;
537
+ },
538
+ ISidebarService: function() {
539
+ return ISidebarService;
540
+ },
541
+ IUIController: function() {
542
+ return IUIController;
543
+ },
544
+ KeyCode: function() {
545
+ return KeyCode;
546
+ },
547
+ Menu: function() {
548
+ return Menu;
549
+ },
550
+ MenuGroup: function() {
551
+ return MenuGroup;
552
+ },
553
+ MenuItemType: function() {
554
+ return MenuItemType;
555
+ },
556
+ MenuPosition: function() {
557
+ return MenuPosition;
558
+ },
559
+ MetaKeys: function() {
560
+ return MetaKeys;
561
+ },
562
+ PLAIN_TEXT_CLIPBOARD_MIME_TYPE: function() {
563
+ return PLAIN_TEXT_CLIPBOARD_MIME_TYPE;
564
+ },
565
+ PasteCommand: function() {
566
+ return PasteCommand;
567
+ },
568
+ PasteShortcutItem: function() {
569
+ return PasteShortcutItem;
570
+ },
571
+ RedoShortcutItem: function() {
572
+ return RedoShortcutItem;
573
+ },
574
+ SharedController: function() {
575
+ return SharedController;
576
+ },
577
+ ShortcutExperienceService: function() {
578
+ return ShortcutExperienceService;
579
+ },
580
+ UIPlugin: function() {
581
+ return UIPlugin;
582
+ },
583
+ UndoShortcutItem: function() {
584
+ return UndoShortcutItem;
585
+ },
586
+ ZIndexManager: function() {
587
+ return ZIndexManager;
588
+ },
589
+ handelExcelToJson: function() {
590
+ return handelExcelToJson;
591
+ },
592
+ handelTableToJson: function() {
593
+ return handelTableToJson;
594
+ },
595
+ handleDomToJson: function() {
596
+ return handleDomToJson;
597
+ },
598
+ handlePlainToJson: function() {
599
+ return handlePlainToJson;
600
+ },
601
+ handleStringToStyle: function() {
602
+ return handleStringToStyle;
603
+ },
604
+ handleTableColgroup: function() {
605
+ return handleTableColgroup;
606
+ },
607
+ handleTableMergeData: function() {
608
+ return handleTableMergeData;
609
+ },
610
+ handleTableRowGroup: function() {
611
+ return handleTableRowGroup;
612
+ },
613
+ splitSpanText: function() {
614
+ return splitSpanText;
615
+ },
616
+ textTrim: function() {
617
+ return textTrim;
618
+ },
619
+ useObservable: function() {
620
+ return useObservable;
621
+ }
622
+ });
623
+ module.exports = __toCommonJS(src_exports);
624
+ // src/common/component-manager.ts
625
+ var import_core = require("@univerjs/core");
626
+ var import_icons = require("@univerjs/icons");
627
+ var ComponentManager = /*#__PURE__*/ function() {
628
+ function ComponentManager() {
629
+ _class_call_check(this, ComponentManager);
630
+ _define_property(this, "_components", /* @__PURE__ */ new Map());
631
+ var iconList = {
632
+ AlignBottomSingle: import_icons.AlignBottomSingle,
633
+ AlignTopSingle: import_icons.AlignTopSingle,
634
+ AllBorderSingle: import_icons.AllBorderSingle,
635
+ AutowrapSingle: import_icons.AutowrapSingle,
636
+ BoldSingle: import_icons.BoldSingle,
637
+ BrushSingle: import_icons.BrushSingle,
638
+ Copy: import_icons.Copy,
639
+ ClearFormat: import_icons.ClearFormat,
640
+ DownBorder: import_icons.DownBorder,
641
+ FontColor: import_icons.FontColor,
642
+ FunctionSingle: import_icons.FunctionSingle,
643
+ HorizontallySingle: import_icons.HorizontallySingle,
644
+ InnerBorder: import_icons.InnerBorder,
645
+ ItalicSingle: import_icons.ItalicSingle,
646
+ KeyboardSingle: import_icons.KeyboardSingle,
647
+ ContentSingle16: import_icons.ContentSingle16,
648
+ LeftBorder: import_icons.LeftBorder,
649
+ LeftJustifyingSingle: import_icons.LeftJustifyingSingle,
650
+ LeftRotationFortyFiveDegreesSingle: import_icons.LeftRotationFortyFiveDegreesSingle,
651
+ LeftRotationNinetyDegreesSingle: import_icons.LeftRotationNinetyDegreesSingle,
652
+ MergeAllSingle: import_icons.MergeAllSingle,
653
+ HorizontalMergeSingle: import_icons.HorizontalMergeSingle,
654
+ VerticalIntegrationSingle: import_icons.VerticalIntegrationSingle,
655
+ CancelMergeSingle: import_icons.CancelMergeSingle,
656
+ NoBorderSingle: import_icons.NoBorderSingle,
657
+ NoColor: import_icons.NoColor,
658
+ NoRotationSingle: import_icons.NoRotationSingle,
659
+ OuterBorder: import_icons.OuterBorder,
660
+ OverflowSingle: import_icons.OverflowSingle,
661
+ PaintBucket: import_icons.PaintBucket,
662
+ PasteSpecial: import_icons.PasteSpecial,
663
+ RedoSingle: import_icons.RedoSingle,
664
+ RightBorder: import_icons.RightBorder,
665
+ RightJustifyingSingle: import_icons.RightJustifyingSingle,
666
+ RightRotationFortyFiveDegreesSingle: import_icons.RightRotationFortyFiveDegreesSingle,
667
+ RightRotationNinetyDegreesSingle: import_icons.RightRotationNinetyDegreesSingle,
668
+ StrikethroughSingle: import_icons.StrikethroughSingle,
669
+ TruncationSingle: import_icons.TruncationSingle,
670
+ UnderlineSingle: import_icons.UnderlineSingle,
671
+ UndoSingle: import_icons.UndoSingle,
672
+ UpBorder: import_icons.UpBorder,
673
+ VerticalCenterSingle: import_icons.VerticalCenterSingle,
674
+ VerticalTextSingle: import_icons.VerticalTextSingle,
675
+ Insert: import_icons.Insert,
676
+ InsertCellDown: import_icons.InsertCellDown,
677
+ InsertCellShiftRight: import_icons.InsertCellShiftRight,
678
+ InsertRowAbove: import_icons.InsertRowAbove,
679
+ InsertRowBelow: import_icons.InsertRowBelow,
680
+ LeftInsertColumn: import_icons.LeftInsertColumn,
681
+ RightInsertColumn: import_icons.RightInsertColumn,
682
+ DeleteColumn: import_icons.DeleteColumn,
683
+ DeleteRow: import_icons.DeleteRow,
684
+ DeleteCellShiftUp: import_icons.DeleteCellShiftUp,
685
+ DeleteCellShiftRight: import_icons.DeleteCellShiftRight,
686
+ DeleteCellShiftLeft: import_icons.DeleteCellShiftLeft,
687
+ DeleteCellMoveDown: import_icons.DeleteCellMoveDown,
688
+ Reduce: import_icons.Reduce,
689
+ Hide: import_icons.Hide,
690
+ AutoHeight: import_icons.AutoHeight,
691
+ AdjustHeight: import_icons.AdjustHeight,
692
+ AdjustWidth: import_icons.AdjustWidth,
693
+ AvgSingle: import_icons.AvgSingle,
694
+ CntSingle: import_icons.CntSingle,
695
+ MaxSingle: import_icons.MaxSingle,
696
+ MinSingle: import_icons.MinSingle,
697
+ SumSingle: import_icons.SumSingle,
698
+ CancelFreezeSingle: import_icons.CancelFreezeSingle,
699
+ FreezeColumnSingle: import_icons.FreezeColumnSingle,
700
+ FreezeRowSingle: import_icons.FreezeRowSingle,
701
+ FreezeToSelectedSingle: import_icons.FreezeToSelectedSingle,
702
+ CodeSingle: import_icons.CodeSingle
703
+ };
704
+ for(var k in iconList){
705
+ this.register(k, iconList[k]);
706
+ }
707
+ }
708
+ _create_class(ComponentManager, [
709
+ {
710
+ key: "register",
711
+ value: function register(name, component) {
712
+ var _this = this;
713
+ if (this._components.has(name)) {
714
+ console.warn("Component ".concat(name, " already exists."));
715
+ }
716
+ this._components.set(name, component);
717
+ return (0, import_core.toDisposable)(function() {
718
+ return _this._components.delete(name);
719
+ });
720
+ }
721
+ },
722
+ {
723
+ key: "get",
724
+ value: function get(name) {
725
+ return this._components.get(name);
726
+ }
727
+ },
728
+ {
729
+ key: "delete",
730
+ value: function _delete(name) {
731
+ this._components.delete(name);
732
+ }
733
+ }
734
+ ]);
735
+ return ComponentManager;
736
+ }();
737
+ // src/common/z-index-manager.ts
738
+ var ZIndexManager = /*#__PURE__*/ function() {
739
+ function ZIndexManager() {
740
+ _class_call_check(this, ZIndexManager);
741
+ _define_property(this, "_list", /* @__PURE__ */ new Map());
742
+ }
743
+ _create_class(ZIndexManager, [
744
+ {
745
+ key: "setIndex",
746
+ value: function setIndex(name, index) {
747
+ this._list.set(name, index);
748
+ }
749
+ },
750
+ {
751
+ key: "getIndex",
752
+ value: function getIndex(name) {
753
+ return this._list.get(name);
754
+ }
755
+ },
756
+ {
757
+ key: "removeIndex",
758
+ value: function removeIndex(name) {
759
+ this._list.delete(name);
760
+ }
761
+ },
762
+ {
763
+ key: "getMaxIndex",
764
+ value: function getMaxIndex() {
765
+ var max = -9999999;
766
+ this._list.forEach(function(item) {
767
+ if (+item > max) {
768
+ max = +item;
769
+ }
770
+ });
771
+ return max;
772
+ }
773
+ }
774
+ ]);
775
+ return ZIndexManager;
776
+ }();
777
+ // src/components/custom-label/CustomLabel.tsx
778
+ var import_tinycolor = require("@ctrl/tinycolor");
779
+ var import_core2 = require("@univerjs/core");
780
+ var import_react_bindings = require("@wendellhu/redi/react-bindings");
781
+ var import_react2 = __toESM(require("react"));
782
+ var import_rxjs = require("rxjs");
783
+ // src/components/hooks/observable.ts
784
+ var import_react = require("react");
785
+ function useObservable(observable, defaultValue, shouldHaveSyncValue) {
786
+ var observableRef = (0, import_react.useRef)(null);
787
+ var subscriptionRef = (0, import_react.useRef)(null);
788
+ var setValue;
789
+ var initialized = false;
790
+ var innerDefaultValue;
791
+ if (!observableRef.current || observableRef.current !== observable) {
792
+ var _subscriptionRef_current;
793
+ (_subscriptionRef_current = subscriptionRef.current) === null || _subscriptionRef_current === void 0 ? void 0 : _subscriptionRef_current.unsubscribe();
794
+ subscriptionRef.current = observable.subscribe(function(v) {
795
+ if (setValue) {
796
+ setValue(v);
797
+ } else {
798
+ innerDefaultValue = v;
799
+ initialized = true;
800
+ }
801
+ });
802
+ }
803
+ if (shouldHaveSyncValue && !initialized) {
804
+ throw new Error("[useObservable]: expect shouldHaveSyncValue but not getting a sync value!");
805
+ }
806
+ var s = (0, import_react.useState)(innerDefaultValue || defaultValue);
807
+ var value = s[0];
808
+ setValue = s[1];
809
+ return value;
810
+ }
811
+ // src/components/custom-label/CustomLabel.tsx
812
+ function CustomLabel(props) {
813
+ var title = props.title, icon = props.icon, label = props.label, value = props.value, value$ = props.value$;
814
+ var localeService = (0, import_react_bindings.useDependency)(import_core2.LocaleService);
815
+ var componentManager = (0, import_react_bindings.useDependency)(ComponentManager);
816
+ var nodes = [];
817
+ var index = 0;
818
+ var realValue = value;
819
+ if (value$) {
820
+ realValue = useObservable(value$, void 0, true);
821
+ }
822
+ var realIcon;
823
+ if ((0, import_rxjs.isObservable)(icon)) {
824
+ realIcon = useObservable(icon, void 0, true);
825
+ } else {
826
+ realIcon = icon;
827
+ }
828
+ var isValid = new import_tinycolor.TinyColor(realValue).isValid;
829
+ if (icon) {
830
+ var Icon = componentManager.get(realIcon !== null && realIcon !== void 0 ? realIcon : "");
831
+ Icon && nodes.push(/* @__PURE__ */ import_react2.default.createElement(Icon, {
832
+ key: index++,
833
+ extend: {
834
+ colorChannel1: isValid ? realValue : "rgb(var(--primary-color))"
835
+ }
836
+ }));
837
+ }
838
+ if (label) {
839
+ var isStringLabel = typeof label === "string";
840
+ var customProps = isStringLabel ? _object_spread({}, props) : _object_spread({}, label === null || label === void 0 ? void 0 : label.props, props);
841
+ var labelName = isStringLabel ? label : label === null || label === void 0 ? void 0 : label.name;
842
+ var CustomComponent = componentManager.get(labelName);
843
+ if (CustomComponent) {
844
+ nodes.push(/* @__PURE__ */ import_react2.default.createElement(CustomComponent, _object_spread_props(_object_spread({
845
+ key: index++
846
+ }, customProps), {
847
+ value: realValue
848
+ })));
849
+ } else {
850
+ nodes.push(/* @__PURE__ */ import_react2.default.createElement("span", {
851
+ key: index++
852
+ }, localeService.t(labelName)));
853
+ }
854
+ }
855
+ if (title) {
856
+ nodes.push(/* @__PURE__ */ import_react2.default.createElement("span", {
857
+ key: index++
858
+ }, localeService.t(title)));
859
+ }
860
+ return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, nodes);
861
+ }
862
+ // src/components/menu/Menu.tsx
863
+ var import_core6 = require("@univerjs/core");
864
+ var import_design = require("@univerjs/design");
865
+ var import_icons2 = require("@univerjs/icons");
866
+ var import_react_bindings2 = require("@wendellhu/redi/react-bindings");
867
+ var import_clsx = __toESM(require("clsx"));
868
+ var import_react3 = __toESM(require("react"));
869
+ var import_rxjs4 = require("rxjs");
870
+ // src/services/menu/menu.ts
871
+ var MenuPosition = /* @__PURE__ */ function(MenuPosition2) {
872
+ MenuPosition2["VOID"] = "void";
873
+ MenuPosition2["TOOLBAR_START"] = "uiToolbar.start";
874
+ MenuPosition2["TOOLBAR_INSERT"] = "uiToolbar.insert";
875
+ MenuPosition2["TOOLBAR_FORMULAS"] = "uiToolbar.formulas";
876
+ MenuPosition2["TOOLBAR_DATA"] = "uiToolbar.data";
877
+ MenuPosition2["TOOLBAR_VIEW"] = "uiToolbar.view";
878
+ MenuPosition2["TOOLBAR_OTHERS"] = "uiToolbar.others";
879
+ MenuPosition2["CONTEXT_MENU"] = "contextMenu";
880
+ return MenuPosition2;
881
+ }(MenuPosition || {});
882
+ var MenuGroup = /* @__PURE__ */ function(MenuGroup2) {
883
+ MenuGroup2[MenuGroup2["TOOLBAR_HISTORY"] = 0] = "TOOLBAR_HISTORY";
884
+ MenuGroup2[MenuGroup2["TOOLBAR_FORMAT"] = 1] = "TOOLBAR_FORMAT";
885
+ MenuGroup2[MenuGroup2["TOOLBAR_LAYOUT"] = 2] = "TOOLBAR_LAYOUT";
886
+ MenuGroup2[MenuGroup2["TOOLBAR_FORMULAS_INSERT"] = 3] = "TOOLBAR_FORMULAS_INSERT";
887
+ MenuGroup2[MenuGroup2["TOOLBAR_FORMULAS_VIEW"] = 4] = "TOOLBAR_FORMULAS_VIEW";
888
+ MenuGroup2[MenuGroup2["TOOLBAR_FILE"] = 5] = "TOOLBAR_FILE";
889
+ MenuGroup2[MenuGroup2["TOOLBAR_OTHERS"] = 6] = "TOOLBAR_OTHERS";
890
+ MenuGroup2[MenuGroup2["CONTEXT_MENU_FORMAT"] = 7] = "CONTEXT_MENU_FORMAT";
891
+ MenuGroup2[MenuGroup2["CONTEXT_MENU_LAYOUT"] = 8] = "CONTEXT_MENU_LAYOUT";
892
+ MenuGroup2[MenuGroup2["CONTEXT_MENU_DATA"] = 9] = "CONTEXT_MENU_DATA";
893
+ MenuGroup2[MenuGroup2["CONTEXT_MENU_OTHERS"] = 10] = "CONTEXT_MENU_OTHERS";
894
+ return MenuGroup2;
895
+ }(MenuGroup || {});
896
+ var MenuItemType = /* @__PURE__ */ function(MenuItemType2) {
897
+ MenuItemType2[MenuItemType2["BUTTON"] = 0] = "BUTTON";
898
+ MenuItemType2[MenuItemType2["SELECTOR"] = 1] = "SELECTOR";
899
+ MenuItemType2[MenuItemType2["BUTTON_SELECTOR"] = 2] = "BUTTON_SELECTOR";
900
+ MenuItemType2[MenuItemType2["SUBITEMS"] = 3] = "SUBITEMS";
901
+ return MenuItemType2;
902
+ }(MenuItemType || {});
903
+ // src/services/menu/menu.service.ts
904
+ var import_core5 = require("@univerjs/core");
905
+ var import_redi3 = require("@wendellhu/redi");
906
+ var import_rxjs3 = require("rxjs");
907
+ // src/services/shortcut/shortcut.service.ts
908
+ var import_core4 = require("@univerjs/core");
909
+ var import_redi2 = require("@wendellhu/redi");
910
+ var import_rxjs2 = require("rxjs");
911
+ // src/common/lifecycle.ts
912
+ var import_core3 = require("@univerjs/core");
913
+ function fromDocumentEvent(type, listener, options) {
914
+ document.addEventListener(type, listener, options);
915
+ return (0, import_core3.toDisposable)(function() {
916
+ return document.removeEventListener(type, listener, options);
917
+ });
918
+ }
919
+ // src/services/platform/platform.service.ts
920
+ var import_redi = require("@wendellhu/redi");
921
+ var IPlatformService = (0, import_redi.createIdentifier)("univer.platform-service");
922
+ var DesktopPlatformService = /*#__PURE__*/ function() {
923
+ function DesktopPlatformService() {
924
+ _class_call_check(this, DesktopPlatformService);
925
+ }
926
+ _create_class(DesktopPlatformService, [
927
+ {
928
+ key: "isMac",
929
+ get: function get() {
930
+ return /Mac/.test(navigator.appVersion);
931
+ }
932
+ },
933
+ {
934
+ key: "isWindows",
935
+ get: function get() {
936
+ return /Windows/.test(navigator.appVersion);
937
+ }
938
+ },
939
+ {
940
+ key: "isLinux",
941
+ get: function get() {
942
+ return /Linux/.test(navigator.appVersion);
943
+ }
944
+ }
945
+ ]);
946
+ return DesktopPlatformService;
947
+ }();
948
+ var _obj;
949
+ // src/services/shortcut/keycode.ts
950
+ var KeyCodeToChar = (_obj = {}, _define_property(_obj, 8 /* BACKSPACE */ , "Backspace"), _define_property(_obj, 9 /* TAB */ , "Tab"), _define_property(_obj, 13 /* ENTER */ , "Enter"), _define_property(_obj, 46 /* DELETE */ , "Del"), _define_property(_obj, 27 /* ESC */ , "Esc"), _define_property(_obj, 32 /* SPACE */ , "Space"), _define_property(_obj, 37 /* ARROW_LEFT */ , "←"), _define_property(_obj, 39 /* ARROW_RIGHT */ , "→"), _define_property(_obj, 38 /* ARROW_UP */ , "↑"), _define_property(_obj, 40 /* ARROW_DOWN */ , "↓"), _define_property(_obj, 48 /* Digit0 */ , "0"), _define_property(_obj, 49 /* Digit1 */ , "1"), _define_property(_obj, 50 /* Digit2 */ , "2"), _define_property(_obj, 51 /* Digit3 */ , "3"), _define_property(_obj, 52 /* Digit4 */ , "4"), _define_property(_obj, 53 /* Digit5 */ , "5"), _define_property(_obj, 54 /* Digit6 */ , "6"), _define_property(_obj, 55 /* Digit7 */ , "7"), _define_property(_obj, 56 /* Digit8 */ , "8"), _define_property(_obj, 57 /* Digit9 */ , "9"), _define_property(_obj, 65 /* A */ , "A"), _define_property(_obj, 66 /* B */ , "B"), _define_property(_obj, 67 /* C */ , "C"), _define_property(_obj, 68 /* D */ , "D"), _define_property(_obj, 69 /* E */ , "E"), _define_property(_obj, 70 /* F */ , "F"), _define_property(_obj, 71 /* G */ , "G"), _define_property(_obj, 72 /* H */ , "H"), _define_property(_obj, 73 /* I */ , "I"), _define_property(_obj, 74 /* J */ , "J"), _define_property(_obj, 75 /* K */ , "K"), _define_property(_obj, 76 /* L */ , "L"), _define_property(_obj, 77 /* M */ , "M"), _define_property(_obj, 78 /* N */ , "N"), _define_property(_obj, 79 /* O */ , "O"), _define_property(_obj, 80 /* P */ , "P"), _define_property(_obj, 81 /* Q */ , "Q"), _define_property(_obj, 82 /* R */ , "R"), _define_property(_obj, 83 /* S */ , "S"), _define_property(_obj, 84 /* T */ , "T"), _define_property(_obj, 85 /* U */ , "U"), _define_property(_obj, 86 /* V */ , "V"), _define_property(_obj, 87 /* W */ , "W"), _define_property(_obj, 88 /* X */ , "X"), _define_property(_obj, 89 /* Y */ , "Y"), _define_property(_obj, 90 /* Z */ , "Z"), _define_property(_obj, 189 /* MINUS */ , "-"), _define_property(_obj, 187 /* EQUAL */ , "="), _obj);
951
+ var KeyCode = /* @__PURE__ */ function(KeyCode2) {
952
+ KeyCode2[KeyCode2["UNKNOWN"] = 0] = "UNKNOWN";
953
+ KeyCode2[KeyCode2["BACKSPACE"] = 8] = "BACKSPACE";
954
+ KeyCode2[KeyCode2["TAB"] = 9] = "TAB";
955
+ KeyCode2[KeyCode2["ENTER"] = 13] = "ENTER";
956
+ KeyCode2[KeyCode2["ESC"] = 27] = "ESC";
957
+ KeyCode2[KeyCode2["SPACE"] = 32] = "SPACE";
958
+ KeyCode2[KeyCode2["ARROW_LEFT"] = 37] = "ARROW_LEFT";
959
+ KeyCode2[KeyCode2["ARROW_UP"] = 38] = "ARROW_UP";
960
+ KeyCode2[KeyCode2["ARROW_RIGHT"] = 39] = "ARROW_RIGHT";
961
+ KeyCode2[KeyCode2["ARROW_DOWN"] = 40] = "ARROW_DOWN";
962
+ KeyCode2[KeyCode2["INSERT"] = 45] = "INSERT";
963
+ KeyCode2[KeyCode2["DELETE"] = 46] = "DELETE";
964
+ KeyCode2[KeyCode2["Digit0"] = 48] = "Digit0";
965
+ KeyCode2[KeyCode2["Digit1"] = 49] = "Digit1";
966
+ KeyCode2[KeyCode2["Digit2"] = 50] = "Digit2";
967
+ KeyCode2[KeyCode2["Digit3"] = 51] = "Digit3";
968
+ KeyCode2[KeyCode2["Digit4"] = 52] = "Digit4";
969
+ KeyCode2[KeyCode2["Digit5"] = 53] = "Digit5";
970
+ KeyCode2[KeyCode2["Digit6"] = 54] = "Digit6";
971
+ KeyCode2[KeyCode2["Digit7"] = 55] = "Digit7";
972
+ KeyCode2[KeyCode2["Digit8"] = 56] = "Digit8";
973
+ KeyCode2[KeyCode2["Digit9"] = 57] = "Digit9";
974
+ KeyCode2[KeyCode2["A"] = 65] = "A";
975
+ KeyCode2[KeyCode2["B"] = 66] = "B";
976
+ KeyCode2[KeyCode2["C"] = 67] = "C";
977
+ KeyCode2[KeyCode2["D"] = 68] = "D";
978
+ KeyCode2[KeyCode2["E"] = 69] = "E";
979
+ KeyCode2[KeyCode2["F"] = 70] = "F";
980
+ KeyCode2[KeyCode2["G"] = 71] = "G";
981
+ KeyCode2[KeyCode2["H"] = 72] = "H";
982
+ KeyCode2[KeyCode2["I"] = 73] = "I";
983
+ KeyCode2[KeyCode2["J"] = 74] = "J";
984
+ KeyCode2[KeyCode2["K"] = 75] = "K";
985
+ KeyCode2[KeyCode2["L"] = 76] = "L";
986
+ KeyCode2[KeyCode2["M"] = 77] = "M";
987
+ KeyCode2[KeyCode2["N"] = 78] = "N";
988
+ KeyCode2[KeyCode2["O"] = 79] = "O";
989
+ KeyCode2[KeyCode2["P"] = 80] = "P";
990
+ KeyCode2[KeyCode2["Q"] = 81] = "Q";
991
+ KeyCode2[KeyCode2["R"] = 82] = "R";
992
+ KeyCode2[KeyCode2["S"] = 83] = "S";
993
+ KeyCode2[KeyCode2["T"] = 84] = "T";
994
+ KeyCode2[KeyCode2["U"] = 85] = "U";
995
+ KeyCode2[KeyCode2["V"] = 86] = "V";
996
+ KeyCode2[KeyCode2["W"] = 87] = "W";
997
+ KeyCode2[KeyCode2["X"] = 88] = "X";
998
+ KeyCode2[KeyCode2["Y"] = 89] = "Y";
999
+ KeyCode2[KeyCode2["Z"] = 90] = "Z";
1000
+ KeyCode2[KeyCode2["F1"] = 112] = "F1";
1001
+ KeyCode2[KeyCode2["F2"] = 113] = "F2";
1002
+ KeyCode2[KeyCode2["F3"] = 114] = "F3";
1003
+ KeyCode2[KeyCode2["F4"] = 115] = "F4";
1004
+ KeyCode2[KeyCode2["F5"] = 116] = "F5";
1005
+ KeyCode2[KeyCode2["F6"] = 117] = "F6";
1006
+ KeyCode2[KeyCode2["F7"] = 118] = "F7";
1007
+ KeyCode2[KeyCode2["F8"] = 119] = "F8";
1008
+ KeyCode2[KeyCode2["F9"] = 120] = "F9";
1009
+ KeyCode2[KeyCode2["F10"] = 121] = "F10";
1010
+ KeyCode2[KeyCode2["F11"] = 122] = "F11";
1011
+ KeyCode2[KeyCode2["F12"] = 123] = "F12";
1012
+ KeyCode2[KeyCode2["NUM_LOCK"] = 144] = "NUM_LOCK";
1013
+ KeyCode2[KeyCode2["SCROLL_LOCK"] = 145] = "SCROLL_LOCK";
1014
+ KeyCode2[KeyCode2["MINUS"] = 189] = "MINUS";
1015
+ KeyCode2[KeyCode2["EQUAL"] = 187] = "EQUAL";
1016
+ return KeyCode2;
1017
+ }(KeyCode || {});
1018
+ var MetaKeys = /* @__PURE__ */ function(MetaKeys2) {
1019
+ MetaKeys2[MetaKeys2["SHIFT"] = 1024] = "SHIFT";
1020
+ MetaKeys2[MetaKeys2["ALT"] = 2048] = "ALT";
1021
+ MetaKeys2[MetaKeys2["CTRL_COMMAND"] = 4096] = "CTRL_COMMAND";
1022
+ MetaKeys2[MetaKeys2["MAC_CTRL"] = 8192] = "MAC_CTRL";
1023
+ return MetaKeys2;
1024
+ }(MetaKeys || {});
1025
+ // src/services/shortcut/shortcut.service.ts
1026
+ var IShortcutService = (0, import_redi2.createIdentifier)("univer.shortcut");
1027
+ var DesktopShortcutService = /*#__PURE__*/ function(_import_core4_Disposable) {
1028
+ _inherits(DesktopShortcutService, _import_core4_Disposable);
1029
+ var _super = _create_super(DesktopShortcutService);
1030
+ function DesktopShortcutService(_commandService, _platformService, _contextService) {
1031
+ _class_call_check(this, DesktopShortcutService);
1032
+ var _this;
1033
+ _this = _super.call(this);
1034
+ _define_property(_assert_this_initialized(_this), "_shortCutMapping", /* @__PURE__ */ new Map());
1035
+ _define_property(_assert_this_initialized(_this), "_commandIDMapping", /* @__PURE__ */ new Map());
1036
+ _define_property(_assert_this_initialized(_this), "_shortcutChanged$", new import_rxjs2.Subject());
1037
+ _define_property(_assert_this_initialized(_this), "shortcutChanged$", _this._shortcutChanged$.asObservable());
1038
+ _define_property(_assert_this_initialized(_this), "_forceEscaped", false);
1039
+ _this._commandService = _commandService;
1040
+ _this._platformService = _platformService;
1041
+ _this._contextService = _contextService;
1042
+ _this.disposeWithMe(fromDocumentEvent("keydown", function(e) {
1043
+ _this._resolveKeyboardEvent(e);
1044
+ }));
1045
+ return _this;
1046
+ }
1047
+ _create_class(DesktopShortcutService, [
1048
+ {
1049
+ key: "getAllShortcuts",
1050
+ value: function getAllShortcuts() {
1051
+ return Array.from(this._shortCutMapping.values()).map(function(v) {
1052
+ return Array.from(v.values());
1053
+ }).flat();
1054
+ }
1055
+ },
1056
+ {
1057
+ key: "registerShortcut",
1058
+ value: function registerShortcut(shortcut) {
1059
+ var _this = this;
1060
+ var binding = this._getBindingFromItem(shortcut);
1061
+ var bindingSet = this._shortCutMapping.get(binding);
1062
+ if (bindingSet) {
1063
+ bindingSet.add(shortcut);
1064
+ } else {
1065
+ this._shortCutMapping.set(binding, /* @__PURE__ */ new Set([
1066
+ shortcut
1067
+ ]));
1068
+ }
1069
+ var commandID = shortcut.id;
1070
+ var commandIDSet = this._commandIDMapping.get(commandID);
1071
+ if (commandIDSet) {
1072
+ commandIDSet.add(shortcut);
1073
+ } else {
1074
+ this._commandIDMapping.set(commandID, /* @__PURE__ */ new Set([
1075
+ shortcut
1076
+ ]));
1077
+ }
1078
+ this._emitShortcutChanged();
1079
+ return (0, import_core4.toDisposable)(function() {
1080
+ var _this__shortCutMapping_get, _this__shortCutMapping_get1, _this__commandIDMapping_get, _this__commandIDMapping_get1;
1081
+ (_this__shortCutMapping_get = _this._shortCutMapping.get(binding)) === null || _this__shortCutMapping_get === void 0 ? void 0 : _this__shortCutMapping_get.delete(shortcut);
1082
+ if (((_this__shortCutMapping_get1 = _this._shortCutMapping.get(binding)) === null || _this__shortCutMapping_get1 === void 0 ? void 0 : _this__shortCutMapping_get1.size) === 0) {
1083
+ _this._shortCutMapping.delete(binding);
1084
+ }
1085
+ (_this__commandIDMapping_get = _this._commandIDMapping.get(commandID)) === null || _this__commandIDMapping_get === void 0 ? void 0 : _this__commandIDMapping_get.delete(shortcut);
1086
+ if (((_this__commandIDMapping_get1 = _this._commandIDMapping.get(commandID)) === null || _this__commandIDMapping_get1 === void 0 ? void 0 : _this__commandIDMapping_get1.size) === 0) {
1087
+ _this._commandIDMapping.delete(commandID);
1088
+ }
1089
+ _this._emitShortcutChanged();
1090
+ });
1091
+ }
1092
+ },
1093
+ {
1094
+ key: "getShortcutDisplayOfCommand",
1095
+ value: function getShortcutDisplayOfCommand(id) {
1096
+ var set = this._commandIDMapping.get(id);
1097
+ if (!set) {
1098
+ return null;
1099
+ }
1100
+ return this.getShortcutDisplay(set.values().next().value);
1101
+ }
1102
+ },
1103
+ {
1104
+ key: "getShortcutDisplay",
1105
+ value: function getShortcutDisplay(shortcut) {
1106
+ var binding = this._getBindingFromItem(shortcut);
1107
+ var ctrlKey = binding & 4096 /* CTRL_COMMAND */ ;
1108
+ var shiftKey = binding & 1024 /* SHIFT */ ;
1109
+ var altKey = binding & 2048 /* ALT */ ;
1110
+ var macCtrl = binding & 8192 /* MAC_CTRL */ ;
1111
+ var _KeyCodeToChar_;
1112
+ var body = (_KeyCodeToChar_ = KeyCodeToChar[binding & 255]) !== null && _KeyCodeToChar_ !== void 0 ? _KeyCodeToChar_ : "<->";
1113
+ if (this._platformService.isMac) {
1114
+ return "".concat(ctrlKey ? "⌘" : "").concat(shiftKey ? "⇧" : "").concat(altKey ? "⌥" : "").concat(macCtrl ? "⌃" : "").concat(body);
1115
+ }
1116
+ return "".concat(ctrlKey ? "Ctrl+" : "").concat(shiftKey ? "Shift+" : "").concat(altKey ? "Alt+" : "").concat(body);
1117
+ }
1118
+ },
1119
+ {
1120
+ key: "_emitShortcutChanged",
1121
+ value: function _emitShortcutChanged() {
1122
+ this._shortcutChanged$.next();
1123
+ }
1124
+ },
1125
+ {
1126
+ key: "forceEscape",
1127
+ value: function forceEscape() {
1128
+ var _this = this;
1129
+ this._forceEscaped = true;
1130
+ return (0, import_core4.toDisposable)(function() {
1131
+ return _this._forceEscaped = false;
1132
+ });
1133
+ }
1134
+ },
1135
+ {
1136
+ key: "_resolveKeyboardEvent",
1137
+ value: function _resolveKeyboardEvent(e) {
1138
+ if (this._forceEscaped) {
1139
+ return;
1140
+ }
1141
+ var shouldPreventDefault = this._dispatch(e);
1142
+ if (shouldPreventDefault) {
1143
+ e.preventDefault();
1144
+ }
1145
+ }
1146
+ },
1147
+ {
1148
+ key: "_dispatch",
1149
+ value: function _dispatch(e) {
1150
+ var _this = this;
1151
+ var binding = this._deriveBindingFromEvent(e);
1152
+ if (binding === null) {
1153
+ return false;
1154
+ }
1155
+ var shortcuts = this._shortCutMapping.get(binding);
1156
+ if (shortcuts === void 0) {
1157
+ return false;
1158
+ }
1159
+ var shouldTrigger = Array.from(shortcuts).sort(function(s1, s2) {
1160
+ var _s2_priority, _s1_priority;
1161
+ return ((_s2_priority = s2.priority) !== null && _s2_priority !== void 0 ? _s2_priority : 0) - ((_s1_priority = s1.priority) !== null && _s1_priority !== void 0 ? _s1_priority : 0);
1162
+ }).find(function(s) {
1163
+ var _s_preconditions;
1164
+ var _s_preconditions1;
1165
+ return (_s_preconditions1 = (_s_preconditions = s.preconditions) === null || _s_preconditions === void 0 ? void 0 : _s_preconditions.call(s, _this._contextService)) !== null && _s_preconditions1 !== void 0 ? _s_preconditions1 : true;
1166
+ });
1167
+ if (shouldTrigger) {
1168
+ this._commandService.executeCommand(shouldTrigger.id, shouldTrigger.staticParameters);
1169
+ return true;
1170
+ }
1171
+ return false;
1172
+ }
1173
+ },
1174
+ {
1175
+ key: "_getBindingFromItem",
1176
+ value: function _getBindingFromItem(item) {
1177
+ if (this._platformService.isMac && item.mac) {
1178
+ return item.mac;
1179
+ }
1180
+ if (this._platformService.isWindows && item.win) {
1181
+ return item.win;
1182
+ }
1183
+ if (this._platformService.isLinux && item.linux) {
1184
+ return item.linux;
1185
+ }
1186
+ return item.binding;
1187
+ }
1188
+ },
1189
+ {
1190
+ key: "_deriveBindingFromEvent",
1191
+ value: function _deriveBindingFromEvent(e) {
1192
+ var shiftKey = e.shiftKey, metaKey = e.metaKey, altKey = e.altKey, keyCode = e.keyCode;
1193
+ var binding = keyCode;
1194
+ if (shiftKey) {
1195
+ binding |= 1024 /* SHIFT */ ;
1196
+ }
1197
+ if (altKey) {
1198
+ binding |= 2048 /* ALT */ ;
1199
+ }
1200
+ var ctrlKey = this._platformService.isMac ? metaKey : e.ctrlKey;
1201
+ if (ctrlKey) {
1202
+ binding |= 4096 /* CTRL_COMMAND */ ;
1203
+ }
1204
+ if (this._platformService.isMac && e.ctrlKey) {
1205
+ binding |= 8192 /* MAC_CTRL */ ;
1206
+ }
1207
+ return binding;
1208
+ }
1209
+ }
1210
+ ]);
1211
+ return DesktopShortcutService;
1212
+ }(import_core4.Disposable);
1213
+ DesktopShortcutService = __decorateClass([
1214
+ __decorateParam(0, import_core4.ICommandService),
1215
+ __decorateParam(1, IPlatformService),
1216
+ __decorateParam(2, import_core4.IContextService)
1217
+ ], DesktopShortcutService);
1218
+ // src/services/menu/menu.service.ts
1219
+ var IMenuService = (0, import_redi3.createIdentifier)("univer.menu-service");
1220
+ var DesktopMenuService = /*#__PURE__*/ function(_import_core5_Disposable) {
1221
+ _inherits(DesktopMenuService, _import_core5_Disposable);
1222
+ var _super = _create_super(DesktopMenuService);
1223
+ function DesktopMenuService(_shortcutService) {
1224
+ _class_call_check(this, DesktopMenuService);
1225
+ var _this;
1226
+ _this = _super.call(this);
1227
+ _define_property(_assert_this_initialized(_this), "_menuItemMap", /* @__PURE__ */ new Map());
1228
+ _define_property(_assert_this_initialized(_this), "_menuByPositions", /* @__PURE__ */ new Map());
1229
+ _define_property(_assert_this_initialized(_this), "_menuChanged$", new import_rxjs3.BehaviorSubject(void 0));
1230
+ _define_property(_assert_this_initialized(_this), "menuChanged$", _this._menuChanged$.asObservable());
1231
+ _this._shortcutService = _shortcutService;
1232
+ return _this;
1233
+ }
1234
+ _create_class(DesktopMenuService, [
1235
+ {
1236
+ key: "dispose",
1237
+ value: function dispose() {
1238
+ this._menuItemMap.clear();
1239
+ this._menuChanged$.complete();
1240
+ }
1241
+ },
1242
+ {
1243
+ key: "addMenuItem",
1244
+ value: function addMenuItem(item) {
1245
+ var _this = this;
1246
+ if (this._menuItemMap.has(item.id)) {
1247
+ throw new Error("Menu item with the same id ".concat(item.id, " has already been added!"));
1248
+ }
1249
+ this._menuItemMap.set(item.id, item);
1250
+ if (Array.isArray(item.positions)) {
1251
+ item.positions.forEach(function(menu) {
1252
+ return _this.appendMenuToPosition(item, menu);
1253
+ });
1254
+ } else {
1255
+ this.appendMenuToPosition(item, item.positions);
1256
+ }
1257
+ this._menuChanged$.next();
1258
+ return (0, import_core5.toDisposable)(function() {
1259
+ _this._menuItemMap.delete(item.id);
1260
+ if (Array.isArray(item.positions)) {
1261
+ item.positions.forEach(function(menu) {
1262
+ var menus = _this._menuByPositions.get(menu);
1263
+ if (!menus) {
1264
+ return;
1265
+ }
1266
+ var index = menus.findIndex(function(m) {
1267
+ return m[0] === item.id;
1268
+ });
1269
+ if (index > -1) {
1270
+ menus.splice(index, 1);
1271
+ }
1272
+ });
1273
+ } else {
1274
+ var menus = _this._menuByPositions.get(item.positions);
1275
+ if (!menus) {
1276
+ return;
1277
+ }
1278
+ var index = menus.findIndex(function(m) {
1279
+ return m[0] === item.id;
1280
+ });
1281
+ if (index > -1) {
1282
+ menus.splice(index, 1);
1283
+ }
1284
+ }
1285
+ _this._menuChanged$.next();
1286
+ });
1287
+ }
1288
+ },
1289
+ {
1290
+ key: "getMenuItems",
1291
+ value: function getMenuItems(positions2) {
1292
+ var _this = this;
1293
+ if (this._menuByPositions.has(positions2)) {
1294
+ var menuItems = this._menuByPositions.get(positions2);
1295
+ if (menuItems) {
1296
+ return _to_consumable_array(menuItems.values()).map(function(menu) {
1297
+ return _this.getDisplayMenuItems(menu[1]);
1298
+ });
1299
+ }
1300
+ }
1301
+ return [];
1302
+ }
1303
+ },
1304
+ {
1305
+ key: "getMenuItem",
1306
+ value: function getMenuItem(id) {
1307
+ if (this._menuItemMap.has(id)) {
1308
+ return this._menuItemMap.get(id);
1309
+ }
1310
+ return null;
1311
+ }
1312
+ },
1313
+ {
1314
+ key: "getDisplayMenuItems",
1315
+ value: function getDisplayMenuItems(menuItem) {
1316
+ var shortcut = this._shortcutService.getShortcutDisplayOfCommand(menuItem.id);
1317
+ if (!shortcut) {
1318
+ return menuItem;
1319
+ }
1320
+ return _object_spread_props(_object_spread({}, menuItem), {
1321
+ shortcut: shortcut
1322
+ });
1323
+ }
1324
+ },
1325
+ {
1326
+ key: "appendMenuToPosition",
1327
+ value: function appendMenuToPosition(menu, position) {
1328
+ if (!this._menuByPositions.has(position)) {
1329
+ this._menuByPositions.set(position, []);
1330
+ }
1331
+ var menuList = this._menuByPositions.get(position);
1332
+ if (menuList.findIndex(function(m) {
1333
+ return m[0] === menu.id;
1334
+ }) > -1) {
1335
+ throw new Error("Menu item with the same id ".concat(menu.id, " has already been added!"));
1336
+ }
1337
+ menuList.push([
1338
+ menu.id,
1339
+ menu
1340
+ ]);
1341
+ }
1342
+ }
1343
+ ]);
1344
+ return DesktopMenuService;
1345
+ }(import_core5.Disposable);
1346
+ DesktopMenuService = __decorateClass([
1347
+ __decorateParam(0, IShortcutService)
1348
+ ], DesktopMenuService);
1349
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/ui/src/components/menu/index.module.less
1350
+ var index_module_default = {
1351
+ "menuItemNoHover": "univer-menu-item-no-hover",
1352
+ "menuItemContent": "univer-menu-item-content",
1353
+ "menuItemSelectable": "univer-menu-item-selectable",
1354
+ "menuItemSelectableIcon": "univer-menu-item-selectable-icon",
1355
+ "menuItemMoreIcon": "univer-menu-item-more-icon"
1356
+ };
1357
+ // src/components/menu/Menu.tsx
1358
+ function MenuWrapper(props) {
1359
+ var menuType = props.menuType, onOptionSelect = props.onOptionSelect;
1360
+ var menuService = (0, import_react_bindings2.useDependency)(IMenuService);
1361
+ if (!menuType) return;
1362
+ if (Array.isArray(menuType)) {
1363
+ var menuTypes = menuType.map(function(type) {
1364
+ return menuService.getMenuItems(type);
1365
+ });
1366
+ var group = menuTypes.map(function(menuItems2) {
1367
+ return menuItems2.reduce(function(acc, item) {
1368
+ if (item.group) {
1369
+ var _acc_item_group;
1370
+ acc[item.group] = (_acc_item_group = acc[item.group]) !== null && _acc_item_group !== void 0 ? _acc_item_group : [];
1371
+ acc[item.group].push(item);
1372
+ } else {
1373
+ var _acc_;
1374
+ acc[10 /* CONTEXT_MENU_OTHERS */ ] = (_acc_ = acc[10 /* CONTEXT_MENU_OTHERS */ ]) !== null && _acc_ !== void 0 ? _acc_ : [];
1375
+ acc[10 /* CONTEXT_MENU_OTHERS */ ].push(item);
1376
+ }
1377
+ return acc;
1378
+ }, {});
1379
+ });
1380
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, group.map(function(groupItem) {
1381
+ return Object.keys(groupItem).map(function(groupKey) {
1382
+ return /* @__PURE__ */ import_react3.default.createElement(import_design.MenuItemGroup, {
1383
+ key: groupKey,
1384
+ eventKey: groupKey
1385
+ }, groupItem[groupKey].map(function(item) {
1386
+ return /* @__PURE__ */ import_react3.default.createElement(MenuItem, {
1387
+ key: item.id,
1388
+ menuItem: item,
1389
+ onClick: function(object) {
1390
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(_object_spread({
1391
+ value: "",
1392
+ label: item.id
1393
+ }, object));
1394
+ }
1395
+ });
1396
+ }));
1397
+ });
1398
+ }));
1399
+ }
1400
+ var menuItems = menuService.getMenuItems(menuType);
1401
+ return menuItems.map(function(item) {
1402
+ return /* @__PURE__ */ import_react3.default.createElement(MenuItem, {
1403
+ key: item.id,
1404
+ menuItem: item,
1405
+ onClick: function(object) {
1406
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(_object_spread({
1407
+ value: "",
1408
+ label: item.id
1409
+ }, object));
1410
+ }
1411
+ });
1412
+ });
1413
+ }
1414
+ function MenuOptionsWrapper(props) {
1415
+ var options = props.options, value = props.value, onOptionSelect = props.onOptionSelect, parentKey = props.parentKey;
1416
+ var _options_map;
1417
+ return (_options_map = options === null || options === void 0 ? void 0 : options.map(function(option, index) {
1418
+ var _option_label, _option_label1;
1419
+ var _option_label2;
1420
+ var key = "".concat(parentKey, "-").concat((_option_label2 = option.label) !== null && _option_label2 !== void 0 ? _option_label2 : option.id, "-").concat(index);
1421
+ var onChange = function(v) {
1422
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect({
1423
+ value: v,
1424
+ label: option === null || option === void 0 ? void 0 : option.label
1425
+ });
1426
+ };
1427
+ var handleClick = function() {
1428
+ if (typeof option.value === "undefined") return;
1429
+ onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(_object_spread({}, option));
1430
+ };
1431
+ var _className = (0, import_clsx.default)(_define_property({}, index_module_default.menuItemNoHover, typeof option.label !== "string" && !((_option_label = option.label) === null || _option_label === void 0 ? void 0 : _option_label.hoverable)));
1432
+ return /* @__PURE__ */ import_react3.default.createElement(import_design.MenuItem, {
1433
+ key: key,
1434
+ eventKey: key,
1435
+ className: _className,
1436
+ onClick: handleClick
1437
+ }, /* @__PURE__ */ import_react3.default.createElement("span", {
1438
+ className: (0, import_clsx.default)(index_module_default.menuItemContent, _define_property({}, index_module_default.menuItemSelectable, !(typeof option.label !== "string" && !((_option_label1 = option.label) === null || _option_label1 === void 0 ? void 0 : _option_label1.hoverable))))
1439
+ }, typeof value !== "undefined" && String(value) === String(option.value) && /* @__PURE__ */ import_react3.default.createElement("span", {
1440
+ className: index_module_default.menuItemSelectableIcon
1441
+ }, /* @__PURE__ */ import_react3.default.createElement(import_icons2.CheckMarkSingle, {
1442
+ style: {
1443
+ color: "rgb(var(--success-color))"
1444
+ }
1445
+ })), /* @__PURE__ */ import_react3.default.createElement(CustomLabel, {
1446
+ value$: option.value$,
1447
+ value: option.value,
1448
+ label: option.label,
1449
+ icon: option.icon,
1450
+ onChange: onChange
1451
+ })));
1452
+ })) !== null && _options_map !== void 0 ? _options_map : /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null);
1453
+ }
1454
+ var Menu = function(props) {
1455
+ return /* @__PURE__ */ import_react3.default.createElement(import_design.Menu, {
1456
+ selectable: false
1457
+ }, /* @__PURE__ */ import_react3.default.createElement(MenuOptionsWrapper, _object_spread({}, props)), /* @__PURE__ */ import_react3.default.createElement(MenuWrapper, _object_spread({}, props)));
1458
+ };
1459
+ function MenuItem(param) {
1460
+ var menuItem = param.menuItem, onClick = param.onClick;
1461
+ var menuService = (0, import_react_bindings2.useDependency)(IMenuService);
1462
+ var menuItems = menuItem.id ? menuService.getMenuItems(menuItem.id) : [];
1463
+ var disabled = useObservable(menuItem.disabled$ || (0, import_rxjs4.of)(false), false, true);
1464
+ var hidden = useObservable(menuItem.hidden$ || (0, import_rxjs4.of)(false), false, true);
1465
+ var value = useObservable(menuItem.value$ || (0, import_rxjs4.of)(void 0), void 0, true);
1466
+ var _ref = _sliced_to_array((0, import_react3.useState)(value), 2), inputValue = _ref[0], setInputValue = _ref[1];
1467
+ var onChange = function(v) {
1468
+ var newValue = (0, import_core6.isRealNum)(v) && typeof v === "string" ? parseInt(v) : v;
1469
+ setInputValue(newValue);
1470
+ };
1471
+ var renderButtonType = function() {
1472
+ var item = menuItem;
1473
+ var title = item.title, label = item.label;
1474
+ return /* @__PURE__ */ import_react3.default.createElement(import_design.MenuItem, {
1475
+ key: item.id,
1476
+ eventKey: item.id,
1477
+ disabled: disabled,
1478
+ onClick: function() {
1479
+ onClick({
1480
+ value: inputValue,
1481
+ id: item.id
1482
+ });
1483
+ }
1484
+ }, /* @__PURE__ */ import_react3.default.createElement("span", {
1485
+ className: index_module_default.menuItemContent
1486
+ }, /* @__PURE__ */ import_react3.default.createElement(CustomLabel, {
1487
+ value: value,
1488
+ title: title,
1489
+ label: label,
1490
+ icon: item.icon,
1491
+ onChange: onChange
1492
+ })));
1493
+ };
1494
+ var renderSelectorType = function() {
1495
+ var item = menuItem;
1496
+ var selections;
1497
+ if ((0, import_rxjs4.isObservable)(item.selections)) {
1498
+ selections = useObservable(item.selections || (0, import_rxjs4.of)([]), [], true);
1499
+ } else {
1500
+ selections = item.selections || [];
1501
+ }
1502
+ if (selections.length > 0) {
1503
+ return /* @__PURE__ */ import_react3.default.createElement(import_design.SubMenu, {
1504
+ key: item.id,
1505
+ eventKey: item.id,
1506
+ popupOffset: [
1507
+ 18,
1508
+ 0
1509
+ ],
1510
+ title: /* @__PURE__ */ import_react3.default.createElement("span", {
1511
+ className: index_module_default.menuItemContent
1512
+ }, /* @__PURE__ */ import_react3.default.createElement(CustomLabel, {
1513
+ title: item.title,
1514
+ value: inputValue,
1515
+ onChange: onChange,
1516
+ icon: item.icon,
1517
+ label: item.label
1518
+ }), item.shortcut && " (".concat(item.shortcut, ")")),
1519
+ expandIcon: /* @__PURE__ */ import_react3.default.createElement(import_icons2.MoreSingle, {
1520
+ className: index_module_default.menuItemMoreIcon
1521
+ })
1522
+ }, selections.length > 0 && /* @__PURE__ */ import_react3.default.createElement(MenuOptionsWrapper, {
1523
+ parentKey: item.id,
1524
+ menuType: item.id,
1525
+ options: selections,
1526
+ onOptionSelect: function(v) {
1527
+ onClick({
1528
+ value: v.value,
1529
+ id: item.id
1530
+ });
1531
+ }
1532
+ }));
1533
+ }
1534
+ return /* @__PURE__ */ import_react3.default.createElement(import_design.MenuItem, {
1535
+ key: item.id,
1536
+ eventKey: item.id
1537
+ }, /* @__PURE__ */ import_react3.default.createElement("span", {
1538
+ className: index_module_default.menuItemContent
1539
+ }, /* @__PURE__ */ import_react3.default.createElement(CustomLabel, {
1540
+ title: item.title,
1541
+ value: inputValue,
1542
+ icon: item.icon,
1543
+ label: item.label,
1544
+ onChange: onChange
1545
+ }), item.shortcut && " (".concat(item.shortcut, ")")));
1546
+ };
1547
+ var renderSubItemsType = function() {
1548
+ var item = menuItem;
1549
+ return /* @__PURE__ */ import_react3.default.createElement(import_design.SubMenu, {
1550
+ key: item.id,
1551
+ eventKey: item.id,
1552
+ popupOffset: [
1553
+ 18,
1554
+ 0
1555
+ ],
1556
+ title: /* @__PURE__ */ import_react3.default.createElement("span", {
1557
+ className: index_module_default.menuItemContent
1558
+ }, /* @__PURE__ */ import_react3.default.createElement(CustomLabel, {
1559
+ title: item.title,
1560
+ icon: item.icon,
1561
+ label: item.label,
1562
+ onChange: onChange
1563
+ })),
1564
+ expandIcon: /* @__PURE__ */ import_react3.default.createElement(import_icons2.MoreSingle, {
1565
+ className: index_module_default.menuItemMoreIcon
1566
+ })
1567
+ }, menuItems.length && /* @__PURE__ */ import_react3.default.createElement(MenuWrapper, {
1568
+ menuType: item.id,
1569
+ parentKey: item.id,
1570
+ onOptionSelect: onClick
1571
+ }));
1572
+ };
1573
+ if (hidden) {
1574
+ return null;
1575
+ }
1576
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, menuItem.type === 1 /* SELECTOR */ && renderSelectorType(), menuItem.type === 3 /* SUBITEMS */ && renderSubItemsType(), menuItem.type === 0 /* BUTTON */ && renderButtonType());
1577
+ }
1578
+ // src/controllers/shared-shortcut.controller.ts
1579
+ var import_core9 = require("@univerjs/core");
1580
+ var import_redi4 = require("@wendellhu/redi");
1581
+ // src/services/clipboard/clipboard.command.ts
1582
+ var import_core7 = require("@univerjs/core");
1583
+ var CopyCommandName = "univer.command.copy";
1584
+ var CopyCommand = {
1585
+ id: CopyCommandName,
1586
+ name: CopyCommandName,
1587
+ multi: true,
1588
+ priority: 0,
1589
+ type: import_core7.CommandType.COMMAND,
1590
+ preconditions: function() {
1591
+ return false;
1592
+ },
1593
+ handler: /*#__PURE__*/ _async_to_generator(function() {
1594
+ return _ts_generator(this, function(_state) {
1595
+ return [
1596
+ 2,
1597
+ true
1598
+ ];
1599
+ });
1600
+ })
1601
+ };
1602
+ var CutCommandName = "univer.command.cut";
1603
+ var CutCommand = {
1604
+ id: CutCommandName,
1605
+ name: CutCommandName,
1606
+ multi: true,
1607
+ priority: 0,
1608
+ type: import_core7.CommandType.COMMAND,
1609
+ preconditions: function() {
1610
+ return false;
1611
+ },
1612
+ handler: /*#__PURE__*/ _async_to_generator(function() {
1613
+ return _ts_generator(this, function(_state) {
1614
+ return [
1615
+ 2,
1616
+ true
1617
+ ];
1618
+ });
1619
+ })
1620
+ };
1621
+ var PasteCommandName = "univer.command.paste";
1622
+ var PasteCommand = {
1623
+ id: PasteCommandName,
1624
+ name: PasteCommandName,
1625
+ multi: true,
1626
+ priority: 0,
1627
+ type: import_core7.CommandType.COMMAND,
1628
+ preconditions: function() {
1629
+ return false;
1630
+ },
1631
+ handler: /*#__PURE__*/ _async_to_generator(function() {
1632
+ return _ts_generator(this, function(_state) {
1633
+ return [
1634
+ 2,
1635
+ true
1636
+ ];
1637
+ });
1638
+ })
1639
+ };
1640
+ // src/controllers/menus/menus.ts
1641
+ var import_core8 = require("@univerjs/core");
1642
+ var import_operators = require("rxjs/operators");
1643
+ function UndoMenuItemFactory(accessor) {
1644
+ var undoRedoService = accessor.get(import_core8.IUndoRedoService);
1645
+ return {
1646
+ id: import_core8.UndoCommand.id,
1647
+ group: 0 /* TOOLBAR_HISTORY */ ,
1648
+ type: 0 /* BUTTON */ ,
1649
+ icon: "UndoSingle",
1650
+ title: "Undo",
1651
+ tooltip: "toolbar.undo",
1652
+ positions: [
1653
+ "uiToolbar.start" /* TOOLBAR_START */
1654
+ ],
1655
+ disabled$: undoRedoService.undoRedoStatus$.pipe((0, import_operators.map)(function(v) {
1656
+ return v.undos <= 0;
1657
+ }))
1658
+ };
1659
+ }
1660
+ function RedoMenuItemFactory(accessor) {
1661
+ var undoRedoService = accessor.get(import_core8.IUndoRedoService);
1662
+ return {
1663
+ id: import_core8.RedoCommand.id,
1664
+ group: 0 /* TOOLBAR_HISTORY */ ,
1665
+ type: 0 /* BUTTON */ ,
1666
+ icon: "RedoSingle",
1667
+ title: "Redo",
1668
+ tooltip: "toolbar.redo",
1669
+ positions: [
1670
+ "uiToolbar.start" /* TOOLBAR_START */
1671
+ ],
1672
+ disabled$: undoRedoService.undoRedoStatus$.pipe((0, import_operators.map)(function(v) {
1673
+ return v.redos <= 0;
1674
+ }))
1675
+ };
1676
+ }
1677
+ // src/controllers/shared-shortcut.controller.ts
1678
+ var CopyShortcutItem = {
1679
+ id: CopyCommand.id,
1680
+ description: "shortcut.copy",
1681
+ group: "1_common-edit",
1682
+ binding: 67 /* C */ | 4096 /* CTRL_COMMAND */
1683
+ };
1684
+ var CutShortcutItem = {
1685
+ id: CutCommand.id,
1686
+ description: "shortcut.cut",
1687
+ group: "1_common-edit",
1688
+ binding: 88 /* X */ | 4096 /* CTRL_COMMAND */
1689
+ };
1690
+ var PasteShortcutItem = {
1691
+ id: PasteCommand.id,
1692
+ description: "shortcut.paste",
1693
+ group: "1_common-edit",
1694
+ binding: 86 /* V */ | 4096 /* CTRL_COMMAND */
1695
+ };
1696
+ var UndoShortcutItem = {
1697
+ id: import_core9.UndoCommand.id,
1698
+ description: "shortcut.undo",
1699
+ group: "1_common-edit",
1700
+ binding: 90 /* Z */ | 4096 /* CTRL_COMMAND */
1701
+ };
1702
+ var RedoShortcutItem = {
1703
+ id: import_core9.RedoCommand.id,
1704
+ description: "shortcut.redo",
1705
+ group: "1_common-edit",
1706
+ binding: 89 /* Y */ | 4096 /* CTRL_COMMAND */
1707
+ };
1708
+ var SharedController = /*#__PURE__*/ function(_import_core9_Disposable) {
1709
+ _inherits(SharedController, _import_core9_Disposable);
1710
+ var _super = _create_super(SharedController);
1711
+ function SharedController(_injector, _menuService, _shortcutService, _commandService) {
1712
+ _class_call_check(this, SharedController);
1713
+ var _this;
1714
+ _this = _super.call(this);
1715
+ _this._injector = _injector;
1716
+ _this._menuService = _menuService;
1717
+ _this._shortcutService = _shortcutService;
1718
+ _this._commandService = _commandService;
1719
+ _this.initialize();
1720
+ return _this;
1721
+ }
1722
+ _create_class(SharedController, [
1723
+ {
1724
+ key: "initialize",
1725
+ value: function initialize() {
1726
+ this._registerCommands();
1727
+ this._registerShortcuts();
1728
+ this._registerMenus();
1729
+ }
1730
+ },
1731
+ {
1732
+ key: "_registerMenus",
1733
+ value: function _registerMenus() {
1734
+ var _this = this;
1735
+ [
1736
+ UndoMenuItemFactory,
1737
+ RedoMenuItemFactory
1738
+ ].forEach(function(factory) {
1739
+ _this.disposeWithMe(_this._menuService.addMenuItem(_this._injector.invoke(factory)));
1740
+ });
1741
+ }
1742
+ },
1743
+ {
1744
+ key: "_registerCommands",
1745
+ value: function _registerCommands() {
1746
+ var _this = this;
1747
+ [
1748
+ CutCommand,
1749
+ CopyCommand,
1750
+ PasteCommand
1751
+ ].forEach(function(command) {
1752
+ return _this.disposeWithMe(_this._commandService.registerAsMultipleCommand(command));
1753
+ });
1754
+ }
1755
+ },
1756
+ {
1757
+ key: "_registerShortcuts",
1758
+ value: function _registerShortcuts() {
1759
+ var _this = this;
1760
+ [
1761
+ UndoShortcutItem,
1762
+ RedoShortcutItem,
1763
+ CutShortcutItem,
1764
+ CopyShortcutItem,
1765
+ PasteShortcutItem
1766
+ ].forEach(function(shortcut) {
1767
+ return _this.disposeWithMe(_this._shortcutService.registerShortcut(shortcut));
1768
+ });
1769
+ }
1770
+ }
1771
+ ]);
1772
+ return SharedController;
1773
+ }(import_core9.Disposable);
1774
+ SharedController = __decorateClass([
1775
+ (0, import_core9.OnLifecycle)(import_core9.LifecycleStages.Ready, SharedController),
1776
+ __decorateParam(0, (0, import_redi4.Inject)(import_redi4.Injector)),
1777
+ __decorateParam(1, IMenuService),
1778
+ __decorateParam(2, IShortcutService),
1779
+ __decorateParam(3, import_core9.ICommandService)
1780
+ ], SharedController);
1781
+ // src/controllers/ui/ui.controller.ts
1782
+ var import_redi5 = require("@wendellhu/redi");
1783
+ var IUIController = (0, import_redi5.createIdentifier)("univer.ui-controller");
1784
+ // src/controllers/ui/ui-desktop.controller.tsx
1785
+ var import_core16 = require("@univerjs/core");
1786
+ var import_engine_render = require("@univerjs/engine-render");
1787
+ var import_redi12 = require("@wendellhu/redi");
1788
+ var import_react_bindings11 = require("@wendellhu/redi/react-bindings");
1789
+ var import_render = require("rc-util/lib/React/render");
1790
+ var import_react15 = __toESM(require("react"));
1791
+ var import_rxjs9 = require("rxjs");
1792
+ // src/services/focus/focus.service.ts
1793
+ var import_core10 = require("@univerjs/core");
1794
+ var import_redi6 = require("@wendellhu/redi");
1795
+ var import_rxjs5 = require("rxjs");
1796
+ var IFocusService = (0, import_redi6.createIdentifier)("univer.focus-service");
1797
+ var FOCUSING_UNIVER = "FOCUSING_UNIVER";
1798
+ var DesktopFocusService = /*#__PURE__*/ function(_import_core10_Disposable) {
1799
+ _inherits(DesktopFocusService, _import_core10_Disposable);
1800
+ var _super = _create_super(DesktopFocusService);
1801
+ function DesktopFocusService(_contextService) {
1802
+ _class_call_check(this, DesktopFocusService);
1803
+ var _this;
1804
+ _this = _super.call(this);
1805
+ _define_property(_assert_this_initialized(_this), "_containerElement", null);
1806
+ _define_property(_assert_this_initialized(_this), "_isUniverFocused", true);
1807
+ _this._contextService = _contextService;
1808
+ _this._initFocusListener();
1809
+ return _this;
1810
+ }
1811
+ _create_class(DesktopFocusService, [
1812
+ {
1813
+ key: "isFocused",
1814
+ get: function get() {
1815
+ return this._isUniverFocused;
1816
+ }
1817
+ },
1818
+ {
1819
+ key: "dispose",
1820
+ value: function dispose() {
1821
+ _get(_get_prototype_of(DesktopFocusService.prototype), "dispose", this).call(this);
1822
+ this._containerElement = null;
1823
+ }
1824
+ },
1825
+ {
1826
+ key: "setContainerElement",
1827
+ value: function setContainerElement(container) {
1828
+ this._containerElement = container;
1829
+ }
1830
+ },
1831
+ {
1832
+ key: "_initFocusListener",
1833
+ value: function _initFocusListener() {
1834
+ var _this = this;
1835
+ this.disposeWithMe((0, import_core10.toDisposable)((0, import_rxjs5.fromEvent)(window, "focusin").subscribe(function(event) {
1836
+ var _this__containerElement;
1837
+ if (event.target && ((_this__containerElement = _this._containerElement) === null || _this__containerElement === void 0 ? void 0 : _this__containerElement.contains(event.target))) {
1838
+ _this._isUniverFocused = true;
1839
+ } else {
1840
+ _this._isUniverFocused = false;
1841
+ }
1842
+ _this._contextService.setContextValue(FOCUSING_UNIVER, _this._isUniverFocused);
1843
+ })));
1844
+ }
1845
+ }
1846
+ ]);
1847
+ return DesktopFocusService;
1848
+ }(import_core10.Disposable);
1849
+ DesktopFocusService = __decorateClass([
1850
+ (0, import_core10.OnLifecycle)(import_core10.LifecycleStages.Ready, IFocusService),
1851
+ __decorateParam(0, import_core10.IContextService)
1852
+ ], DesktopFocusService);
1853
+ // src/views/App.tsx
1854
+ var import_core15 = require("@univerjs/core");
1855
+ var import_design7 = require("@univerjs/design");
1856
+ var import_react_bindings10 = require("@wendellhu/redi/react-bindings");
1857
+ var import_react14 = __toESM(require("react"));
1858
+ // src/services/message/message.service.ts
1859
+ var import_redi7 = require("@wendellhu/redi");
1860
+ var IMessageService = (0, import_redi7.createIdentifier)("univer.message-service");
1861
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/ui/src/views/app.module.less
1862
+ var app_module_default = {
1863
+ "appLayout": "univer-app-layout",
1864
+ "appContainer": "univer-app-container",
1865
+ "appContainerHeader": "univer-app-container-header",
1866
+ "appContainerWrapper": "univer-app-container-wrapper",
1867
+ "appContainerContent": "univer-app-container-content",
1868
+ "appContainerCanvas": "univer-app-container-canvas",
1869
+ "appContainerSidebar": "univer-app-container-sidebar"
1870
+ };
1871
+ // src/views/components/ComponentContainer.tsx
1872
+ var import_react4 = __toESM(require("react"));
1873
+ function ComponentContainer(props) {
1874
+ var components = props.components;
1875
+ if (!components) return null;
1876
+ return Array.from(components.values()).map(function(component, index) {
1877
+ return import_react4.default.createElement(component(), {
1878
+ key: "".concat(index)
1879
+ });
1880
+ });
1881
+ }
1882
+ // src/views/components/doc-bars/MenuBar.tsx
1883
+ var import_core11 = require("@univerjs/core");
1884
+ var import_react_bindings3 = require("@wendellhu/redi/react-bindings");
1885
+ var import_clsx2 = __toESM(require("clsx"));
1886
+ var import_react5 = __toESM(require("react"));
1887
+ // src/views/components/doc-bars/hooks/menu.ts
1888
+ var import_rxjs6 = require("rxjs");
1889
+ var positions = [
1890
+ "uiToolbar.start" /* TOOLBAR_START */ ,
1891
+ "uiToolbar.insert" /* TOOLBAR_INSERT */ ,
1892
+ "uiToolbar.formulas" /* TOOLBAR_FORMULAS */ ,
1893
+ "uiToolbar.data" /* TOOLBAR_DATA */ ,
1894
+ "uiToolbar.view" /* TOOLBAR_VIEW */ ,
1895
+ "uiToolbar.others" /* TOOLBAR_OTHERS */
1896
+ ];
1897
+ var positionSubject = new import_rxjs6.BehaviorSubject("uiToolbar.start" /* TOOLBAR_START */ );
1898
+ var position$ = positionSubject.asObservable();
1899
+ function setPosition(position) {
1900
+ positionSubject.next(position);
1901
+ }
1902
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/ui/src/views/components/doc-bars/index.module.less
1903
+ var index_module_default2 = {
1904
+ "headerbar": "univer-headerbar",
1905
+ "headerMenu": "univer-header-menu",
1906
+ "menubar": "univer-menubar",
1907
+ "menubarItem": "univer-menubar-item",
1908
+ "menubarItemActive": "univer-menubar-item-active",
1909
+ "toolbar": "univer-toolbar",
1910
+ "toolbarContainer": "univer-toolbar-container",
1911
+ "toolbarGroup": "univer-toolbar-group",
1912
+ "toolbarItemSelectButton": "univer-toolbar-item-select-button",
1913
+ "toolbarItemSelectButtonLabel": "univer-toolbar-item-select-button-label",
1914
+ "toolbarItemSelectButtonArrow": "univer-toolbar-item-select-button-arrow",
1915
+ "toolbarItemSelect": "univer-toolbar-item-select",
1916
+ "toolbarItemSelectArrow": "univer-toolbar-item-select-arrow"
1917
+ };
1918
+ // src/views/components/doc-bars/MenuBar.tsx
1919
+ function MenuBar(props) {
1920
+ var headerMenuComponents = props.headerMenuComponents;
1921
+ var localeService = (0, import_react_bindings3.useDependency)(import_core11.LocaleService);
1922
+ var menuService = (0, import_react_bindings3.useDependency)(IMenuService);
1923
+ var _ref = _sliced_to_array((0, import_react5.useState)([]), 2), group = _ref[0], setGroup = _ref[1];
1924
+ (0, import_react5.useEffect)(function() {
1925
+ var listener = menuService.menuChanged$.subscribe(function() {
1926
+ var group2 = [];
1927
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1928
+ try {
1929
+ for(var _iterator = positions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1930
+ var position2 = _step.value;
1931
+ var menuItems = menuService.getMenuItems(position2);
1932
+ if (menuItems.length) {
1933
+ group2.push({
1934
+ name: position2,
1935
+ menuItems: menuItems
1936
+ });
1937
+ }
1938
+ }
1939
+ } catch (err) {
1940
+ _didIteratorError = true;
1941
+ _iteratorError = err;
1942
+ } finally{
1943
+ try {
1944
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1945
+ _iterator.return();
1946
+ }
1947
+ } finally{
1948
+ if (_didIteratorError) {
1949
+ throw _iteratorError;
1950
+ }
1951
+ }
1952
+ }
1953
+ setGroup(group2);
1954
+ });
1955
+ return function() {
1956
+ listener.unsubscribe();
1957
+ };
1958
+ }, []);
1959
+ var position = useObservable(position$, "uiToolbar.start" /* TOOLBAR_START */ , true);
1960
+ return /* @__PURE__ */ import_react5.default.createElement("header", {
1961
+ className: index_module_default2.headerbar
1962
+ }, /* @__PURE__ */ import_react5.default.createElement("div", {
1963
+ className: index_module_default2.menubar
1964
+ }, group.length > 1 && group.map(function(item, index) {
1965
+ return /* @__PURE__ */ import_react5.default.createElement("a", {
1966
+ key: index,
1967
+ className: (0, import_clsx2.default)(index_module_default2.menubarItem, _define_property({}, index_module_default2.menubarItemActive, item.name === position)),
1968
+ onClick: function() {
1969
+ return setPosition(item.name);
1970
+ }
1971
+ }, localeService.t(item.name));
1972
+ })), /* @__PURE__ */ import_react5.default.createElement("div", {
1973
+ className: index_module_default2.headerMenu
1974
+ }, /* @__PURE__ */ import_react5.default.createElement(ComponentContainer, {
1975
+ components: headerMenuComponents
1976
+ })));
1977
+ }
1978
+ // src/views/components/doc-bars/Toolbar.tsx
1979
+ var import_react_bindings5 = require("@wendellhu/redi/react-bindings");
1980
+ var import_react8 = __toESM(require("react"));
1981
+ // src/views/components/doc-bars/ToolbarItem.tsx
1982
+ var import_core12 = require("@univerjs/core");
1983
+ var import_design2 = require("@univerjs/design");
1984
+ var import_icons3 = require("@univerjs/icons");
1985
+ var import_react_bindings4 = require("@wendellhu/redi/react-bindings");
1986
+ var import_react7 = __toESM(require("react"));
1987
+ var import_rxjs7 = require("rxjs");
1988
+ // src/views/components/doc-bars/Button/ToolbarButton.tsx
1989
+ var import_clsx3 = __toESM(require("clsx"));
1990
+ var import_react6 = __toESM(require("react"));
1991
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/ui/src/views/components/doc-bars/Button/index.module.less
1992
+ var index_module_default3 = {
1993
+ "toolbarBtn": "univer-toolbar-btn",
1994
+ "toolbarBtnActive": "univer-toolbar-btn-active"
1995
+ };
1996
+ // src/views/components/doc-bars/Button/ToolbarButton.tsx
1997
+ function ToolbarButton(props) {
1998
+ var children = props.children, className = props.className, style = props.style, _props_disabled = props.disabled, disabled = _props_disabled === void 0 ? false : _props_disabled, _props_active = props.active, active = _props_active === void 0 ? false : _props_active, onClick = props.onClick, onDoubleClick = props.onDoubleClick, restProps = _object_without_properties(props, [
1999
+ "children",
2000
+ "className",
2001
+ "style",
2002
+ "disabled",
2003
+ "active",
2004
+ "onClick",
2005
+ "onDoubleClick"
2006
+ ]);
2007
+ var handleClick = function(e) {
2008
+ if (disabled) {
2009
+ e.preventDefault();
2010
+ return;
2011
+ }
2012
+ onClick && onClick(e);
2013
+ };
2014
+ var handleDoubleClick = function(e) {
2015
+ if (disabled) {
2016
+ e.preventDefault();
2017
+ return;
2018
+ }
2019
+ onDoubleClick && onDoubleClick(e);
2020
+ };
2021
+ var _className = (0, import_clsx3.default)(index_module_default3.toolbarBtn, _define_property({}, "".concat(index_module_default3.toolbarBtn, "-active"), active), className);
2022
+ return /* @__PURE__ */ import_react6.default.createElement("button", _object_spread({
2023
+ className: _className,
2024
+ style: style,
2025
+ disabled: disabled,
2026
+ onClick: handleClick,
2027
+ onDoubleClick: handleDoubleClick
2028
+ }, restProps), children);
2029
+ }
2030
+ // src/views/components/doc-bars/ToolbarItem.tsx
2031
+ function ToolbarItem(props) {
2032
+ var localeService = (0, import_react_bindings4.useDependency)(import_core12.LocaleService);
2033
+ var commandService = (0, import_react_bindings4.useDependency)(import_core12.ICommandService);
2034
+ var _ref = _sliced_to_array((0, import_react7.useState)(), 2), value = _ref[0], setValue = _ref[1];
2035
+ var _ref1 = _sliced_to_array((0, import_react7.useState)(false), 2), disabled = _ref1[0], setDisabled = _ref1[1];
2036
+ var _ref2 = _sliced_to_array((0, import_react7.useState)(false), 2), activated = _ref2[0], setActivated = _ref2[1];
2037
+ (0, import_react7.useEffect)(function() {
2038
+ var subscriptions = [];
2039
+ props.disabled$ && subscriptions.push(props.disabled$.subscribe(function(disabled2) {
2040
+ setDisabled(disabled2);
2041
+ }));
2042
+ if (props.type === 0 /* BUTTON */ ) {
2043
+ props.activated$ && subscriptions.push(props.activated$.subscribe(function(activated2) {
2044
+ setActivated(activated2);
2045
+ }));
2046
+ }
2047
+ props.value$ && subscriptions.push(props.value$.subscribe(function(value2) {
2048
+ setValue(value2);
2049
+ }));
2050
+ return function() {
2051
+ subscriptions.forEach(function(subscription) {
2052
+ subscription.unsubscribe();
2053
+ });
2054
+ };
2055
+ }, []);
2056
+ var tooltip = props.tooltip, shortcut = props.shortcut, icon = props.icon, title = props.title, label = props.label, id = props.id;
2057
+ var tooltipTitle = localeService.t(tooltip !== null && tooltip !== void 0 ? tooltip : "") + (shortcut ? " (".concat(shortcut, ")") : "");
2058
+ function renderSelectorType(menuType) {
2059
+ var selections = props.selections;
2060
+ var options = selections;
2061
+ var iconToDisplay = icon;
2062
+ if ((0, import_rxjs7.isObservable)(icon)) {
2063
+ iconToDisplay = useObservable(icon, void 0, true);
2064
+ } else {
2065
+ var _options_find;
2066
+ var _options_find_icon;
2067
+ iconToDisplay = (_options_find_icon = options === null || options === void 0 ? void 0 : (_options_find = options.find(function(o) {
2068
+ return o.value === value;
2069
+ })) === null || _options_find === void 0 ? void 0 : _options_find.icon) !== null && _options_find_icon !== void 0 ? _options_find_icon : icon;
2070
+ }
2071
+ function handleSelect(option) {
2072
+ var commandId = id;
2073
+ var value2 = option;
2074
+ if (option.id) {
2075
+ commandId = option.id;
2076
+ }
2077
+ commandService.executeCommand(commandId, value2);
2078
+ }
2079
+ function handleChange(value2) {
2080
+ var commandId = id;
2081
+ commandService.executeCommand(commandId, {
2082
+ value: value2
2083
+ });
2084
+ }
2085
+ function handleClick() {
2086
+ if (menuType === 2 /* BUTTON_SELECTOR */ ) {
2087
+ var commandId = id;
2088
+ commandService.executeCommand(commandId, {
2089
+ value: value
2090
+ });
2091
+ }
2092
+ }
2093
+ return menuType === 2 /* BUTTON_SELECTOR */ ? /* @__PURE__ */ import_react7.default.createElement("div", {
2094
+ className: index_module_default2.toolbarItemSelectButton
2095
+ }, /* @__PURE__ */ import_react7.default.createElement("div", {
2096
+ className: index_module_default2.toolbarItemSelectButtonLabel,
2097
+ onClick: handleClick
2098
+ }, /* @__PURE__ */ import_react7.default.createElement(CustomLabel, {
2099
+ icon: iconToDisplay,
2100
+ title: title,
2101
+ value: value,
2102
+ label: label,
2103
+ onChange: handleChange
2104
+ })), /* @__PURE__ */ import_react7.default.createElement(import_design2.Dropdown, {
2105
+ overlay: /* @__PURE__ */ import_react7.default.createElement(Menu, {
2106
+ menuType: id,
2107
+ options: options,
2108
+ onOptionSelect: handleSelect,
2109
+ value: value
2110
+ })
2111
+ }, /* @__PURE__ */ import_react7.default.createElement("div", {
2112
+ className: index_module_default2.toolbarItemSelectButtonArrow
2113
+ }, /* @__PURE__ */ import_react7.default.createElement(import_icons3.MoreDownSingle, null)))) : /* @__PURE__ */ import_react7.default.createElement(import_design2.Dropdown, {
2114
+ overlay: /* @__PURE__ */ import_react7.default.createElement(Menu, {
2115
+ menuType: id,
2116
+ options: options,
2117
+ onOptionSelect: handleSelect,
2118
+ value: value
2119
+ })
2120
+ }, /* @__PURE__ */ import_react7.default.createElement("div", {
2121
+ className: index_module_default2.toolbarItemSelect
2122
+ }, /* @__PURE__ */ import_react7.default.createElement(CustomLabel, {
2123
+ icon: iconToDisplay,
2124
+ title: title,
2125
+ value: value,
2126
+ label: label,
2127
+ onChange: handleChange
2128
+ }), /* @__PURE__ */ import_react7.default.createElement("div", {
2129
+ className: index_module_default2.toolbarItemSelectArrow
2130
+ }, /* @__PURE__ */ import_react7.default.createElement(import_icons3.MoreDownSingle, null))));
2131
+ }
2132
+ function renderButtonType() {
2133
+ var componentManager = (0, import_react_bindings4.useDependency)(ComponentManager);
2134
+ var _label_name;
2135
+ var isCustomComponent = componentManager.get(typeof label === "string" ? label : (_label_name = label === null || label === void 0 ? void 0 : label.name) !== null && _label_name !== void 0 ? _label_name : "");
2136
+ return /* @__PURE__ */ import_react7.default.createElement(ToolbarButton, {
2137
+ className: index_module_default2.toolbarItemTextButton,
2138
+ active: activated,
2139
+ disabled: disabled,
2140
+ onClick: function() {
2141
+ return commandService.executeCommand(props.id);
2142
+ },
2143
+ onDoubleClick: function() {
2144
+ return props.subId && commandService.executeCommand(props.subId);
2145
+ }
2146
+ }, isCustomComponent ? /* @__PURE__ */ import_react7.default.createElement(CustomLabel, {
2147
+ title: title,
2148
+ value: value,
2149
+ label: label
2150
+ }) : /* @__PURE__ */ import_react7.default.createElement(CustomLabel, {
2151
+ icon: icon
2152
+ }));
2153
+ }
2154
+ function renderItem() {
2155
+ switch(props.type){
2156
+ case 2 /* BUTTON_SELECTOR */ :
2157
+ case 1 /* SELECTOR */ :
2158
+ case 3 /* SUBITEMS */ :
2159
+ return renderSelectorType(props.type);
2160
+ case 0 /* BUTTON */ :
2161
+ default:
2162
+ return renderButtonType();
2163
+ }
2164
+ }
2165
+ return /* @__PURE__ */ import_react7.default.createElement(import_design2.Tooltip, {
2166
+ title: tooltipTitle,
2167
+ placement: "bottom"
2168
+ }, renderItem());
2169
+ }
2170
+ // src/views/components/doc-bars/Toolbar.tsx
2171
+ function Toolbar() {
2172
+ var menuService = (0, import_react_bindings5.useDependency)(IMenuService);
2173
+ var _ref = _sliced_to_array((0, import_react8.useState)([]), 2), group = _ref[0], setGroup = _ref[1];
2174
+ var position = useObservable(position$, "uiToolbar.start" /* TOOLBAR_START */ , true);
2175
+ (0, import_react8.useEffect)(function() {
2176
+ var listener = menuService.menuChanged$.subscribe(function() {
2177
+ var group2 = [];
2178
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2179
+ try {
2180
+ for(var _iterator = positions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2181
+ var position2 = _step.value;
2182
+ var menuItems = menuService.getMenuItems(position2);
2183
+ if (menuItems.length) {
2184
+ group2.push({
2185
+ name: position2,
2186
+ menuItems: menuItems
2187
+ });
2188
+ }
2189
+ }
2190
+ } catch (err) {
2191
+ _didIteratorError = true;
2192
+ _iteratorError = err;
2193
+ } finally{
2194
+ try {
2195
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2196
+ _iterator.return();
2197
+ }
2198
+ } finally{
2199
+ if (_didIteratorError) {
2200
+ throw _iteratorError;
2201
+ }
2202
+ }
2203
+ }
2204
+ setGroup(group2);
2205
+ });
2206
+ return function() {
2207
+ listener.unsubscribe();
2208
+ };
2209
+ }, []);
2210
+ var activeMenuGroup = group.find(function(g) {
2211
+ return g.name === position;
2212
+ });
2213
+ var _activeMenuGroup_menuItems_reduce;
2214
+ var toolbarGroups = (_activeMenuGroup_menuItems_reduce = activeMenuGroup === null || activeMenuGroup === void 0 ? void 0 : activeMenuGroup.menuItems.reduce(function(acc, item) {
2215
+ var _item_group;
2216
+ var key = (_item_group = item.group) !== null && _item_group !== void 0 ? _item_group : 6 /* TOOLBAR_OTHERS */ ;
2217
+ if (!acc[key]) {
2218
+ acc[key] = [];
2219
+ }
2220
+ acc[key].push(item);
2221
+ return acc;
2222
+ }, {})) !== null && _activeMenuGroup_menuItems_reduce !== void 0 ? _activeMenuGroup_menuItems_reduce : {};
2223
+ return /* @__PURE__ */ import_react8.default.createElement("div", {
2224
+ className: index_module_default2.toolbar
2225
+ }, /* @__PURE__ */ import_react8.default.createElement("div", {
2226
+ className: index_module_default2.toolbarContainer
2227
+ }, Object.entries(toolbarGroups).map(function(param) {
2228
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
2229
+ return /* @__PURE__ */ import_react8.default.createElement("div", {
2230
+ key: key,
2231
+ className: index_module_default2.toolbarGroup
2232
+ }, item.map(function(subItem) {
2233
+ return /* @__PURE__ */ import_react8.default.createElement(ToolbarItem, _object_spread({
2234
+ key: subItem.id
2235
+ }, subItem));
2236
+ }));
2237
+ })));
2238
+ }
2239
+ // src/views/components/sidebar/Sidebar.tsx
2240
+ var import_icons4 = require("@univerjs/icons");
2241
+ var import_react_bindings6 = require("@wendellhu/redi/react-bindings");
2242
+ var import_clsx4 = __toESM(require("clsx"));
2243
+ var import_react9 = __toESM(require("react"));
2244
+ // src/services/sidebar/sidebar.service.ts
2245
+ var import_redi8 = require("@wendellhu/redi");
2246
+ var ISidebarService = (0, import_redi8.createIdentifier)("univer.sidebar-service");
2247
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/ui/src/views/components/sidebar/index.module.less
2248
+ var index_module_default4 = {
2249
+ "sidebar": "univer-sidebar",
2250
+ "sidebarOpen": "univer-sidebar-open",
2251
+ "sidebarContainer": "univer-sidebar-container",
2252
+ "sidebarHeader": "univer-sidebar-header",
2253
+ "sidebarHeaderClose": "univer-sidebar-header-close",
2254
+ "sidebarBody": "univer-sidebar-body",
2255
+ "sidebarFooter": "univer-sidebar-footer"
2256
+ };
2257
+ // src/views/components/sidebar/Sidebar.tsx
2258
+ function Sidebar() {
2259
+ var sidebarService = (0, import_react_bindings6.useDependency)(ISidebarService);
2260
+ var _ref = _sliced_to_array((0, import_react9.useState)({}), 2), sidebarOptions = _ref[0], setSidebarOptions = _ref[1];
2261
+ (0, import_react9.useEffect)(function() {
2262
+ var sidebar$ = sidebarService.getObservableSidebar();
2263
+ var subscribtion = sidebar$.subscribe(function(options2) {
2264
+ setSidebarOptions(options2);
2265
+ });
2266
+ return function() {
2267
+ subscribtion.unsubscribe();
2268
+ };
2269
+ }, []);
2270
+ var options = sidebarOptions;
2271
+ for(var _i = 0, _iter = [
2272
+ "children",
2273
+ "header",
2274
+ "footer"
2275
+ ]; _i < _iter.length; _i++){
2276
+ var key = _iter[_i];
2277
+ var k = key;
2278
+ if (sidebarOptions[k]) {
2279
+ var props = sidebarOptions[k];
2280
+ if (props) {
2281
+ options[k] = /* @__PURE__ */ import_react9.default.createElement(CustomLabel, _object_spread({}, props));
2282
+ }
2283
+ }
2284
+ }
2285
+ var _className = (0, import_clsx4.default)(index_module_default4.sidebar, _define_property({}, index_module_default4.sidebarOpen, options.visible));
2286
+ var width = (0, import_react9.useMemo)(function() {
2287
+ if (!options.visible) return 0;
2288
+ if (typeof options.width === "number") {
2289
+ return "".concat(options.width, "px");
2290
+ }
2291
+ return options.width;
2292
+ }, [
2293
+ options
2294
+ ]);
2295
+ function handleClose() {
2296
+ var _options2_onClose;
2297
+ var options2 = _object_spread_props(_object_spread({}, sidebarOptions), {
2298
+ visible: false
2299
+ });
2300
+ setSidebarOptions(options2);
2301
+ var sidebar$ = sidebarService.getObservableSidebar();
2302
+ sidebar$.next(options2);
2303
+ options2 === null || options2 === void 0 ? void 0 : (_options2_onClose = options2.onClose) === null || _options2_onClose === void 0 ? void 0 : _options2_onClose.call(options2);
2304
+ }
2305
+ return /* @__PURE__ */ import_react9.default.createElement("section", {
2306
+ className: _className,
2307
+ style: {
2308
+ width: width
2309
+ }
2310
+ }, /* @__PURE__ */ import_react9.default.createElement("section", {
2311
+ className: index_module_default4.sidebarContainer
2312
+ }, /* @__PURE__ */ import_react9.default.createElement("header", {
2313
+ className: index_module_default4.sidebarHeader
2314
+ }, options === null || options === void 0 ? void 0 : options.header, /* @__PURE__ */ import_react9.default.createElement("a", {
2315
+ className: index_module_default4.sidebarHeaderClose,
2316
+ onClick: handleClose
2317
+ }, /* @__PURE__ */ import_react9.default.createElement(import_icons4.CloseSingle, null))), /* @__PURE__ */ import_react9.default.createElement("section", {
2318
+ className: index_module_default4.sidebarBody
2319
+ }, options === null || options === void 0 ? void 0 : options.children), (options === null || options === void 0 ? void 0 : options.footer) && /* @__PURE__ */ import_react9.default.createElement("footer", {
2320
+ className: index_module_default4.sidebarFooter
2321
+ }, options.footer)));
2322
+ }
2323
+ // src/components/notification/Notification.tsx
2324
+ var import_design3 = require("@univerjs/design");
2325
+ var import_icons5 = require("@univerjs/icons");
2326
+ var import_clsx5 = __toESM(require("clsx"));
2327
+ var import_rc_notification = require("rc-notification");
2328
+ var import_react10 = __toESM(require("react"));
2329
+ var import_rxjs8 = require("rxjs");
2330
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/ui/src/components/notification/index.module.less
2331
+ var index_module_default5 = {
2332
+ "notification": "univer-notification",
2333
+ "notificationNotice": "univer-notification-notice",
2334
+ "notificationNoticeWrapper": "univer-notification-notice-wrapper",
2335
+ "notificationNoticeContent": "univer-notification-notice-content",
2336
+ "notificationNoticeClose": "univer-notification-notice-close",
2337
+ "notificationIcon": "univer-notification-icon",
2338
+ "notificationIconSuccess": "univer-notification-icon-success",
2339
+ "notificationIconInfo": "univer-notification-icon-info",
2340
+ "notificationIconWarning": "univer-notification-icon-warning",
2341
+ "notificationIconError": "univer-notification-icon-error",
2342
+ "notificationContentContainer": "univer-notification-content-container",
2343
+ "notificationTitle": "univer-notification-title",
2344
+ "notificationContent": "univer-notification-content",
2345
+ "notificationContentEllipsis": "univer-notification-content-ellipsis",
2346
+ "notificationTop": "univer-notification-top",
2347
+ "notificationTopLeft": "univer-notification-topLeft",
2348
+ "notificationTopRight": "univer-notification-topRight",
2349
+ "notificationBottom": "univer-notification-bottom",
2350
+ "notificationBottomRight": "univer-notification-bottomRight",
2351
+ "notificationBottomLeft": "univer-notification-bottomLeft",
2352
+ "notificationFade": "univer-notification-fade",
2353
+ "notificationFadeAppearPrepare": "univer-notification-fade-appear-prepare",
2354
+ "notificationFadeAppearStart": "univer-notification-fade-appear-start",
2355
+ "notificationFadeAppearActive": "univer-notification-fade-appear-active",
2356
+ "notificationFadeAppear": "univer-notification-fade-appear",
2357
+ "notificationFadeEnter": "univer-notification-fade-enter",
2358
+ "notificationFadeLeave": "univer-notification-fade-leave",
2359
+ "notificationFadeEnterActive": "univer-notification-fade-enter-active",
2360
+ "notificationFadeIn": "univer-notification-fade-in",
2361
+ "notificationFadeLeaveActive": "univer-notification-fade-leave-active",
2362
+ "notificationFadeOut": "univer-notification-fade-out"
2363
+ };
2364
+ // src/components/notification/Notification.tsx
2365
+ var iconMap = {
2366
+ success: /* @__PURE__ */ import_react10.default.createElement(import_icons5.SuccessSingle, {
2367
+ className: index_module_default5.notificationIconSuccess
2368
+ }),
2369
+ info: /* @__PURE__ */ import_react10.default.createElement(import_icons5.WarningSingle, {
2370
+ className: index_module_default5.notificationIconInfo
2371
+ }),
2372
+ warning: /* @__PURE__ */ import_react10.default.createElement(import_icons5.WarningSingle, {
2373
+ className: index_module_default5.notificationIconWarning
2374
+ }),
2375
+ error: /* @__PURE__ */ import_react10.default.createElement(import_icons5.ErrorSingle, {
2376
+ className: index_module_default5.notificationIconError
2377
+ })
2378
+ };
2379
+ var notificationObserver = new import_rxjs8.Subject();
2380
+ var PureContent = function(props) {
2381
+ var type = props.type, content = props.content, title = props.title, _props_lines = props.lines, lines = _props_lines === void 0 ? 0 : _props_lines;
2382
+ var contentClassName = (0, import_clsx5.default)(index_module_default5.notificationContent, _define_property({}, index_module_default5.notificationContentEllipsis, lines !== 0));
2383
+ return /* @__PURE__ */ import_react10.default.createElement(import_react10.default.Fragment, null, /* @__PURE__ */ import_react10.default.createElement("span", {
2384
+ className: index_module_default5.notificationIcon
2385
+ }, iconMap[type]), /* @__PURE__ */ import_react10.default.createElement("div", {
2386
+ className: index_module_default5.notificationContentContainer
2387
+ }, /* @__PURE__ */ import_react10.default.createElement("span", {
2388
+ className: index_module_default5.notificationTitle
2389
+ }, title), /* @__PURE__ */ import_react10.default.createElement("span", {
2390
+ className: contentClassName,
2391
+ style: {
2392
+ WebkitLineClamp: lines
2393
+ }
2394
+ }, content)));
2395
+ };
2396
+ function Notification() {
2397
+ var mountContainer = (0, import_react10.useContext)(import_design3.ConfigContext).mountContainer;
2398
+ var _ref = _sliced_to_array((0, import_rc_notification.useNotification)({
2399
+ prefixCls: index_module_default5.notification,
2400
+ maxCount: 3,
2401
+ closeIcon: /* @__PURE__ */ import_react10.default.createElement(import_icons5.CloseSingle, null),
2402
+ getContainer: function() {
2403
+ return mountContainer;
2404
+ },
2405
+ motion: {
2406
+ motionName: index_module_default5.notificationFade,
2407
+ motionAppear: true,
2408
+ motionEnter: true,
2409
+ motionLeave: true
2410
+ }
2411
+ }), 2), api = _ref[0], contextHolder = _ref[1];
2412
+ var observerRef = (0, import_react10.useRef)(notificationObserver);
2413
+ (0, import_react10.useEffect)(function() {
2414
+ var subscription = observerRef.current.subscribe(function(options) {
2415
+ var _options_placement, _options_duration, _options_closable;
2416
+ api.open({
2417
+ content: /* @__PURE__ */ import_react10.default.createElement(PureContent, {
2418
+ content: options.content,
2419
+ type: options.type,
2420
+ title: options.title,
2421
+ lines: options.lines
2422
+ }),
2423
+ placement: (_options_placement = options.placement) !== null && _options_placement !== void 0 ? _options_placement : "topRight",
2424
+ duration: (_options_duration = options.duration) !== null && _options_duration !== void 0 ? _options_duration : 4.5,
2425
+ closable: (_options_closable = options.closable) !== null && _options_closable !== void 0 ? _options_closable : true
2426
+ });
2427
+ });
2428
+ return function() {
2429
+ subscription.unsubscribe();
2430
+ };
2431
+ }, []);
2432
+ return /* @__PURE__ */ import_react10.default.createElement(import_react10.default.Fragment, null, contextHolder);
2433
+ }
2434
+ var notification = {
2435
+ show: function(options) {
2436
+ notificationObserver.next(options);
2437
+ }
2438
+ };
2439
+ // src/views/components/confirm-part/ConfirmPart.tsx
2440
+ var import_design4 = require("@univerjs/design");
2441
+ var import_react_bindings7 = require("@wendellhu/redi/react-bindings");
2442
+ var import_react11 = __toESM(require("react"));
2443
+ // src/services/confirm/confirm.service.ts
2444
+ var import_redi9 = require("@wendellhu/redi");
2445
+ var IConfirmService = (0, import_redi9.createIdentifier)("univer.confirm-service");
2446
+ // src/views/components/confirm-part/ConfirmPart.tsx
2447
+ function ConfirmPart() {
2448
+ var confirmService = (0, import_react_bindings7.useDependency)(IConfirmService);
2449
+ var _ref = _sliced_to_array((0, import_react11.useState)([]), 2), confirmOptions = _ref[0], setConfirmOptions = _ref[1];
2450
+ (0, import_react11.useEffect)(function() {
2451
+ var confirm$ = confirmService.getObservableConfirm();
2452
+ var subscribtion = confirm$.subscribe(function(options) {
2453
+ setConfirmOptions(options);
2454
+ });
2455
+ return function() {
2456
+ subscribtion.unsubscribe();
2457
+ };
2458
+ }, []);
2459
+ var props = confirmOptions.map(function(options) {
2460
+ var children = options.children, title = options.title, restProps = _object_without_properties(options, [
2461
+ "children",
2462
+ "title"
2463
+ ]);
2464
+ var confirmProps = restProps;
2465
+ for(var _i = 0, _iter = [
2466
+ "children",
2467
+ "title"
2468
+ ]; _i < _iter.length; _i++){
2469
+ var key = _iter[_i];
2470
+ var k = key;
2471
+ var props2 = options[k];
2472
+ if (props2) {
2473
+ confirmProps[k] = /* @__PURE__ */ import_react11.default.createElement(CustomLabel, _object_spread({}, props2));
2474
+ }
2475
+ }
2476
+ return confirmProps;
2477
+ });
2478
+ return props === null || props === void 0 ? void 0 : props.map(function(options, index) {
2479
+ return /* @__PURE__ */ import_react11.default.createElement(import_design4.Confirm, _object_spread({
2480
+ key: index
2481
+ }, options));
2482
+ });
2483
+ }
2484
+ // src/views/components/context-menu/ContextMenu.tsx
2485
+ var import_core14 = require("@univerjs/core");
2486
+ var import_design5 = require("@univerjs/design");
2487
+ var import_react_bindings8 = require("@wendellhu/redi/react-bindings");
2488
+ var import_react12 = __toESM(require("react"));
2489
+ // src/services/contextmenu/contextmenu.service.ts
2490
+ var import_core13 = require("@univerjs/core");
2491
+ var import_redi10 = require("@wendellhu/redi");
2492
+ var IContextMenuService = (0, import_redi10.createIdentifier)("univer.context-menu-service");
2493
+ var DesktopContextMenuService = /*#__PURE__*/ function(_import_core13_Disposable) {
2494
+ _inherits(DesktopContextMenuService, _import_core13_Disposable);
2495
+ var _super = _create_super(DesktopContextMenuService);
2496
+ function DesktopContextMenuService() {
2497
+ _class_call_check(this, DesktopContextMenuService);
2498
+ var _this;
2499
+ _this = _super.apply(this, arguments);
2500
+ _define_property(_assert_this_initialized(_this), "_currentHandler", null);
2501
+ return _this;
2502
+ }
2503
+ _create_class(DesktopContextMenuService, [
2504
+ {
2505
+ key: "triggerContextMenu",
2506
+ value: function triggerContextMenu(event, menuType) {
2507
+ var _this__currentHandler;
2508
+ event.stopPropagation();
2509
+ (_this__currentHandler = this._currentHandler) === null || _this__currentHandler === void 0 ? void 0 : _this__currentHandler.handleContextMenu(event, menuType);
2510
+ }
2511
+ },
2512
+ {
2513
+ key: "registerContextMenuHandler",
2514
+ value: function registerContextMenuHandler(handler) {
2515
+ var _this = this;
2516
+ if (this._currentHandler) {
2517
+ throw new Error("There is already a context menu handler!");
2518
+ }
2519
+ this._currentHandler = handler;
2520
+ return (0, import_core13.toDisposable)(function() {
2521
+ _this._currentHandler = null;
2522
+ });
2523
+ }
2524
+ }
2525
+ ]);
2526
+ return DesktopContextMenuService;
2527
+ }(import_core13.Disposable);
2528
+ // src/views/components/context-menu/ContextMenu.tsx
2529
+ function ContextMenu() {
2530
+ var _ref = _sliced_to_array((0, import_react12.useState)(false), 2), visible = _ref[0], setVisible = _ref[1];
2531
+ var _ref1 = _sliced_to_array((0, import_react12.useState)(""), 2), menuType = _ref1[0], setMenuType = _ref1[1];
2532
+ var _ref2 = _sliced_to_array((0, import_react12.useState)([
2533
+ 0,
2534
+ 0
2535
+ ]), 2), offset = _ref2[0], setOffset = _ref2[1];
2536
+ var contextMenuService = (0, import_react_bindings8.useDependency)(IContextMenuService);
2537
+ var commandService = (0, import_react_bindings8.useDependency)(import_core14.ICommandService);
2538
+ (0, import_react12.useEffect)(function() {
2539
+ var disposables = contextMenuService.registerContextMenuHandler({
2540
+ handleContextMenu: handleContextMenu
2541
+ });
2542
+ document.addEventListener("pointerdown", handleClose);
2543
+ document.addEventListener("wheel", handleClose);
2544
+ return function() {
2545
+ document.removeEventListener("pointerdown", handleClose);
2546
+ document.removeEventListener("wheel", handleClose);
2547
+ disposables.dispose();
2548
+ };
2549
+ }, []);
2550
+ function handleContextMenu(event, menuType2) {
2551
+ setMenuType(menuType2);
2552
+ setOffset([
2553
+ event.clientX,
2554
+ event.clientY
2555
+ ]);
2556
+ setVisible(true);
2557
+ }
2558
+ function handleClose() {
2559
+ setVisible(false);
2560
+ }
2561
+ return /* @__PURE__ */ import_react12.default.createElement(import_design5.Popup, {
2562
+ visible: visible,
2563
+ offset: offset
2564
+ }, /* @__PURE__ */ import_react12.default.createElement("section", {
2565
+ onPointerDown: function(e) {
2566
+ return e.stopPropagation();
2567
+ }
2568
+ }, /* @__PURE__ */ import_react12.default.createElement(Menu, {
2569
+ menuType: [
2570
+ menuType
2571
+ ],
2572
+ onOptionSelect: function(params) {
2573
+ var commandId = params.label, value = params.value;
2574
+ commandService && commandService.executeCommand(commandId, {
2575
+ value: value
2576
+ });
2577
+ setVisible(false);
2578
+ }
2579
+ })));
2580
+ }
2581
+ // src/views/components/dialog-part/DialogPart.tsx
2582
+ var import_design6 = require("@univerjs/design");
2583
+ var import_react_bindings9 = require("@wendellhu/redi/react-bindings");
2584
+ var import_react13 = __toESM(require("react"));
2585
+ // src/services/dialog/dialog.service.ts
2586
+ var import_redi11 = require("@wendellhu/redi");
2587
+ var IDialogService = (0, import_redi11.createIdentifier)("univer.dialog-service");
2588
+ // src/views/components/dialog-part/DialogPart.tsx
2589
+ function DialogPart() {
2590
+ var dialogService = (0, import_react_bindings9.useDependency)(IDialogService);
2591
+ var _ref = _sliced_to_array((0, import_react13.useState)([]), 2), dialogOptions = _ref[0], setDialogOptions = _ref[1];
2592
+ (0, import_react13.useEffect)(function() {
2593
+ var dialog$ = dialogService.getObservableDialog();
2594
+ var subscribtion = dialog$.subscribe(function(options) {
2595
+ setDialogOptions(options);
2596
+ });
2597
+ return function() {
2598
+ subscribtion.unsubscribe();
2599
+ };
2600
+ }, []);
2601
+ var props = dialogOptions.map(function(options) {
2602
+ var children = options.children, title = options.title, closeIcon = options.closeIcon, footer = options.footer, restProps = _object_without_properties(options, [
2603
+ "children",
2604
+ "title",
2605
+ "closeIcon",
2606
+ "footer"
2607
+ ]);
2608
+ var dialogProps = restProps;
2609
+ for(var _i = 0, _iter = [
2610
+ "children",
2611
+ "title",
2612
+ "closeIcon",
2613
+ "footer"
2614
+ ]; _i < _iter.length; _i++){
2615
+ var key = _iter[_i];
2616
+ var k = key;
2617
+ var props2 = options[k];
2618
+ if (props2) {
2619
+ dialogProps[k] = /* @__PURE__ */ import_react13.default.createElement(CustomLabel, _object_spread({}, props2));
2620
+ }
2621
+ }
2622
+ return dialogProps;
2623
+ });
2624
+ return /* @__PURE__ */ import_react13.default.createElement(import_react13.default.Fragment, null, props === null || props === void 0 ? void 0 : props.map(function(options) {
2625
+ return /* @__PURE__ */ import_react13.default.createElement(import_design6.Dialog, _object_spread({
2626
+ key: options.id
2627
+ }, options));
2628
+ }));
2629
+ }
2630
+ // src/views/parts.ts
2631
+ var globalComponents = /* @__PURE__ */ new Set([
2632
+ function() {
2633
+ return DialogPart;
2634
+ },
2635
+ function() {
2636
+ return ConfirmPart;
2637
+ },
2638
+ function() {
2639
+ return Notification;
2640
+ },
2641
+ function() {
2642
+ return ContextMenu;
2643
+ }
2644
+ ]);
2645
+ // src/views/App.tsx
2646
+ function App(props) {
2647
+ var localeService = (0, import_react_bindings10.useDependency)(import_core15.LocaleService);
2648
+ var themeService = (0, import_react_bindings10.useDependency)(import_core15.ThemeService);
2649
+ var messageService = (0, import_react_bindings10.useDependency)(IMessageService);
2650
+ var contentRef = (0, import_react14.useRef)(null);
2651
+ var mountContainer = props.mountContainer, headerComponents = props.headerComponents, headerMenuComponents = props.headerMenuComponents, contentComponents = props.contentComponents, footerComponents = props.footerComponents, // sidebarComponents,
2652
+ onRendered = props.onRendered;
2653
+ (0, import_react14.useEffect)(function() {
2654
+ if (!themeService.getCurrentTheme()) {
2655
+ themeService.setTheme(import_design7.defaultTheme);
2656
+ }
2657
+ }, []);
2658
+ (0, import_react14.useEffect)(function() {
2659
+ if (contentRef.current) {
2660
+ onRendered === null || onRendered === void 0 ? void 0 : onRendered(contentRef.current);
2661
+ }
2662
+ }, [
2663
+ onRendered
2664
+ ]);
2665
+ var _ref = _sliced_to_array((0, import_react14.useState)(localeService.getLocales()), 2), locale = _ref[0], setLocale = _ref[1];
2666
+ var portalContainer = (0, import_react14.useMemo)(function() {
2667
+ return document.createElement("div");
2668
+ }, []);
2669
+ (0, import_react14.useEffect)(function() {
2670
+ document.body.appendChild(portalContainer);
2671
+ messageService.setContainer(portalContainer);
2672
+ var subscriptions = [
2673
+ localeService.localeChanged$.subscribe(function() {
2674
+ setLocale(localeService.getLocales());
2675
+ }),
2676
+ themeService.currentTheme$.subscribe(function(theme) {
2677
+ import_design7.themeInstance.setTheme(mountContainer, theme);
2678
+ portalContainer && import_design7.themeInstance.setTheme(portalContainer, theme);
2679
+ })
2680
+ ];
2681
+ return function() {
2682
+ subscriptions.forEach(function(subscription) {
2683
+ return subscription.unsubscribe();
2684
+ });
2685
+ };
2686
+ }, [
2687
+ portalContainer
2688
+ ]);
2689
+ return /* @__PURE__ */ import_react14.default.createElement(import_design7.ConfigProvider, {
2690
+ locale: locale,
2691
+ mountContainer: portalContainer
2692
+ }, /* @__PURE__ */ import_react14.default.createElement("section", {
2693
+ className: app_module_default.appLayout
2694
+ }, props.toolbar && /* @__PURE__ */ import_react14.default.createElement(MenuBar, {
2695
+ headerMenuComponents: headerMenuComponents
2696
+ }), /* @__PURE__ */ import_react14.default.createElement("section", {
2697
+ className: app_module_default.appContainer
2698
+ }, /* @__PURE__ */ import_react14.default.createElement("header", {
2699
+ className: app_module_default.appContainerHeader
2700
+ }, props.toolbar && /* @__PURE__ */ import_react14.default.createElement(Toolbar, null)), /* @__PURE__ */ import_react14.default.createElement("section", {
2701
+ className: app_module_default.appContainerWrapper
2702
+ }, /* @__PURE__ */ import_react14.default.createElement("section", {
2703
+ className: app_module_default.appContainerContent
2704
+ }, /* @__PURE__ */ import_react14.default.createElement("header", null, /* @__PURE__ */ import_react14.default.createElement(ComponentContainer, {
2705
+ components: headerComponents
2706
+ })), /* @__PURE__ */ import_react14.default.createElement("section", {
2707
+ className: app_module_default.appContainerCanvas,
2708
+ ref: contentRef,
2709
+ "data-range-selector": true,
2710
+ onContextMenu: function(e) {
2711
+ return e.preventDefault();
2712
+ }
2713
+ }, /* @__PURE__ */ import_react14.default.createElement(ComponentContainer, {
2714
+ components: contentComponents
2715
+ }))), /* @__PURE__ */ import_react14.default.createElement("aside", {
2716
+ className: app_module_default.appContainerSidebar
2717
+ }, /* @__PURE__ */ import_react14.default.createElement(Sidebar, null)))), /* @__PURE__ */ import_react14.default.createElement("footer", {
2718
+ className: app_module_default.appFooter
2719
+ }, /* @__PURE__ */ import_react14.default.createElement(ComponentContainer, {
2720
+ components: footerComponents
2721
+ }))), /* @__PURE__ */ import_react14.default.createElement(ComponentContainer, {
2722
+ components: globalComponents
2723
+ }));
2724
+ }
2725
+ // src/controllers/ui/ui-desktop.controller.tsx
2726
+ var DesktopUIPart = /* @__PURE__ */ function(DesktopUIPart2) {
2727
+ DesktopUIPart2["HEADER"] = "header";
2728
+ DesktopUIPart2["HEADER_MENU"] = "header-menu";
2729
+ DesktopUIPart2["CONTENT"] = "content";
2730
+ DesktopUIPart2["FOOTER"] = "footer";
2731
+ return DesktopUIPart2;
2732
+ }(DesktopUIPart || {});
2733
+ var STEADY_TIMEOUT = 3e3;
2734
+ var DesktopUIController = /*#__PURE__*/ function(_import_core16_Disposable) {
2735
+ _inherits(DesktopUIController, _import_core16_Disposable);
2736
+ var _super = _create_super(DesktopUIController);
2737
+ function DesktopUIController(_injector, _lifecycleService, _renderManagerService, _focusService) {
2738
+ _class_call_check(this, DesktopUIController);
2739
+ var _this;
2740
+ _this = _super.call(this);
2741
+ _define_property(_assert_this_initialized(_this), "_headerComponents", /* @__PURE__ */ new Set());
2742
+ _define_property(_assert_this_initialized(_this), "_headerMenuComponents", /* @__PURE__ */ new Set());
2743
+ _define_property(_assert_this_initialized(_this), "_contentComponents", /* @__PURE__ */ new Set());
2744
+ _define_property(_assert_this_initialized(_this), "_footerComponents", /* @__PURE__ */ new Set());
2745
+ // private _sidebarComponents: Set<() => ComponentType> = new Set();
2746
+ _define_property(_assert_this_initialized(_this), "_componentRegistered$", new import_rxjs9.Subject());
2747
+ _define_property(_assert_this_initialized(_this), "componentRegistered$", _this._componentRegistered$.asObservable());
2748
+ _this._injector = _injector;
2749
+ _this._lifecycleService = _lifecycleService;
2750
+ _this._renderManagerService = _renderManagerService;
2751
+ _this._focusService = _focusService;
2752
+ return _this;
2753
+ }
2754
+ _create_class(DesktopUIController, [
2755
+ {
2756
+ key: "bootstrapWorkbench",
2757
+ value: function bootstrapWorkbench(options) {
2758
+ var _this = this;
2759
+ this.disposeWithMe(bootStrap(this._injector, options, function(canvasElement, containerElement) {
2760
+ _this._initializeEngine(canvasElement);
2761
+ _this._lifecycleService.stage = import_core16.LifecycleStages.Rendered;
2762
+ _this._focusService.setContainerElement(containerElement);
2763
+ setTimeout(function() {
2764
+ return _this._lifecycleService.stage = import_core16.LifecycleStages.Steady;
2765
+ }, STEADY_TIMEOUT);
2766
+ }));
2767
+ }
2768
+ },
2769
+ {
2770
+ key: "_initializeEngine",
2771
+ value: function _initializeEngine(element) {
2772
+ var engine = this._renderManagerService.getCurrent().engine;
2773
+ engine.setContainer(element);
2774
+ }
2775
+ },
2776
+ {
2777
+ key: "registerComponent",
2778
+ value: function registerComponent(part, component) {
2779
+ switch(part){
2780
+ case "header" /* HEADER */ :
2781
+ return this.registerHeaderComponent(component);
2782
+ case "content" /* CONTENT */ :
2783
+ return this.registerContentComponent(component);
2784
+ case "footer" /* FOOTER */ :
2785
+ return this.registerFooterComponent(component);
2786
+ case "header-menu" /* HEADER_MENU */ :
2787
+ return this.registerHeaderMenuComponent(component);
2788
+ default:
2789
+ throw new Error("[DesktopUIController] Unknown part type: ".concat(part, "."));
2790
+ }
2791
+ }
2792
+ },
2793
+ {
2794
+ key: "registerHeaderMenuComponent",
2795
+ value: function registerHeaderMenuComponent(component) {
2796
+ var _this = this;
2797
+ this._headerMenuComponents.add(component);
2798
+ this._componentRegistered$.next();
2799
+ return (0, import_core16.toDisposable)(function() {
2800
+ return _this._headerMenuComponents.delete(component);
2801
+ });
2802
+ }
2803
+ },
2804
+ {
2805
+ key: "getHeaderMenuComponents",
2806
+ value: function getHeaderMenuComponents() {
2807
+ return /* @__PURE__ */ new Set(_to_consumable_array(this._headerMenuComponents));
2808
+ }
2809
+ },
2810
+ {
2811
+ key: "registerHeaderComponent",
2812
+ value: function registerHeaderComponent(component) {
2813
+ var _this = this;
2814
+ this._headerComponents.add(component);
2815
+ this._componentRegistered$.next();
2816
+ return (0, import_core16.toDisposable)(function() {
2817
+ return _this._headerComponents.delete(component);
2818
+ });
2819
+ }
2820
+ },
2821
+ {
2822
+ key: "getHeaderComponents",
2823
+ value: function getHeaderComponents() {
2824
+ return /* @__PURE__ */ new Set(_to_consumable_array(this._headerComponents));
2825
+ }
2826
+ },
2827
+ {
2828
+ key: "registerContentComponent",
2829
+ value: function registerContentComponent(component) {
2830
+ var _this = this;
2831
+ this._contentComponents.add(component);
2832
+ this._componentRegistered$.next();
2833
+ return (0, import_core16.toDisposable)(function() {
2834
+ return _this._contentComponents.delete(component);
2835
+ });
2836
+ }
2837
+ },
2838
+ {
2839
+ key: "getContentComponents",
2840
+ value: function getContentComponents() {
2841
+ return /* @__PURE__ */ new Set(_to_consumable_array(this._contentComponents));
2842
+ }
2843
+ },
2844
+ {
2845
+ key: "registerFooterComponent",
2846
+ value: function registerFooterComponent(component) {
2847
+ var _this = this;
2848
+ this._footerComponents.add(component);
2849
+ this._componentRegistered$.next();
2850
+ return (0, import_core16.toDisposable)(function() {
2851
+ return _this._footerComponents.delete(component);
2852
+ });
2853
+ }
2854
+ },
2855
+ {
2856
+ key: "getFooterComponents",
2857
+ value: function getFooterComponents() {
2858
+ return /* @__PURE__ */ new Set(_to_consumable_array(this._footerComponents));
2859
+ }
2860
+ }
2861
+ ]);
2862
+ return DesktopUIController;
2863
+ }(import_core16.Disposable);
2864
+ DesktopUIController = __decorateClass([
2865
+ __decorateParam(0, (0, import_redi12.Inject)(import_redi12.Injector)),
2866
+ __decorateParam(1, (0, import_redi12.Inject)(import_core16.LifecycleService)),
2867
+ __decorateParam(2, import_engine_render.IRenderManagerService),
2868
+ __decorateParam(3, IFocusService)
2869
+ ], DesktopUIController);
2870
+ function bootStrap(injector, options, callback) {
2871
+ var mountContainer;
2872
+ var container = options.container;
2873
+ if (typeof container === "string") {
2874
+ var containerElement = document.getElementById(container);
2875
+ if (!containerElement) {
2876
+ mountContainer = createContainer(container);
2877
+ } else {
2878
+ mountContainer = containerElement;
2879
+ }
2880
+ } else if (_instanceof(container, HTMLElement)) {
2881
+ mountContainer = container;
2882
+ } else {
2883
+ mountContainer = createContainer("univer");
2884
+ }
2885
+ var ConnectedApp = (0, import_react_bindings11.connectInjector)(App, injector);
2886
+ var desktopUIController = injector.get(IUIController);
2887
+ var onRendered = function(canvasElement) {
2888
+ return callback(canvasElement, mountContainer);
2889
+ };
2890
+ function render() {
2891
+ var headerComponents = desktopUIController.getHeaderComponents();
2892
+ var contentComponents = desktopUIController.getContentComponents();
2893
+ var footerComponents = desktopUIController.getFooterComponents();
2894
+ var headerMenuComponents = desktopUIController.getHeaderMenuComponents();
2895
+ (0, import_render.render)(/* @__PURE__ */ import_react15.default.createElement(ConnectedApp, _object_spread_props(_object_spread({}, options), {
2896
+ mountContainer: mountContainer,
2897
+ headerComponents: headerComponents,
2898
+ headerMenuComponents: headerMenuComponents,
2899
+ contentComponents: contentComponents,
2900
+ onRendered: onRendered,
2901
+ footerComponents: footerComponents
2902
+ })), mountContainer);
2903
+ }
2904
+ var updateSubscription = desktopUIController.componentRegistered$.subscribe(render);
2905
+ render();
2906
+ return (0, import_core16.toDisposable)(function() {
2907
+ (0, import_render.unmount)(mountContainer);
2908
+ updateSubscription.unsubscribe();
2909
+ });
2910
+ }
2911
+ function createContainer(id) {
2912
+ var element = document.createElement("div");
2913
+ element.id = id;
2914
+ return element;
2915
+ }
2916
+ // src/services/before-close/before-close.service.ts
2917
+ var import_redi14 = require("@wendellhu/redi");
2918
+ // src/services/notification/notification.service.ts
2919
+ var import_redi13 = require("@wendellhu/redi");
2920
+ var INotificationService = (0, import_redi13.createIdentifier)("univer.notification-service");
2921
+ // src/services/before-close/before-close.service.ts
2922
+ var IBeforeCloseService = (0, import_redi14.createIdentifier)("univer.ui.before-close-service");
2923
+ var DesktopBeforeCloseService = /*#__PURE__*/ function() {
2924
+ function DesktopBeforeCloseService(_notificationService) {
2925
+ _class_call_check(this, DesktopBeforeCloseService);
2926
+ _define_property(this, "_callbacks", []);
2927
+ this._notificationService = _notificationService;
2928
+ this._init();
2929
+ }
2930
+ _create_class(DesktopBeforeCloseService, [
2931
+ {
2932
+ key: "registerBeforeClose",
2933
+ value: function registerBeforeClose(callback) {
2934
+ var _this = this;
2935
+ this._callbacks.push(callback);
2936
+ return {
2937
+ dispose: function() {
2938
+ _this._callbacks = _this._callbacks.filter(function(cb) {
2939
+ return cb !== callback;
2940
+ });
2941
+ }
2942
+ };
2943
+ }
2944
+ },
2945
+ {
2946
+ key: "_init",
2947
+ value: function _init() {
2948
+ var _this = this;
2949
+ window.onbeforeunload = function(event) {
2950
+ var message = _this._callbacks.map(function(callback) {
2951
+ return callback();
2952
+ }).filter(function(m) {
2953
+ return !!m;
2954
+ }).join("\n");
2955
+ if (message) {
2956
+ _this._notificationService.show({
2957
+ type: "error",
2958
+ title: "Some changes are not saved",
2959
+ content: message
2960
+ });
2961
+ if (typeof event === "undefined") {
2962
+ event = window.event;
2963
+ }
2964
+ event.returnValue = message;
2965
+ return message;
2966
+ }
2967
+ };
2968
+ }
2969
+ }
2970
+ ]);
2971
+ return DesktopBeforeCloseService;
2972
+ }();
2973
+ DesktopBeforeCloseService = __decorateClass([
2974
+ __decorateParam(0, INotificationService)
2975
+ ], DesktopBeforeCloseService);
2976
+ // src/services/clipboard/clipboard-interface.service.ts
2977
+ var import_core17 = require("@univerjs/core");
2978
+ var import_redi15 = require("@wendellhu/redi");
2979
+ var PLAIN_TEXT_CLIPBOARD_MIME_TYPE = "text/plain";
2980
+ var HTML_CLIPBOARD_MIME_TYPE = "text/html";
2981
+ var IClipboardInterfaceService = (0, import_redi15.createIdentifier)("univer.clipboard-interface-service");
2982
+ var BrowserClipboardService = /*#__PURE__*/ function(_import_core17_Disposable) {
2983
+ _inherits(BrowserClipboardService, _import_core17_Disposable);
2984
+ var _super = _create_super(BrowserClipboardService);
2985
+ function BrowserClipboardService() {
2986
+ _class_call_check(this, BrowserClipboardService);
2987
+ return _super.apply(this, arguments);
2988
+ }
2989
+ _create_class(BrowserClipboardService, [
2990
+ {
2991
+ key: "write",
2992
+ value: function write(text, html) {
2993
+ return _async_to_generator(function() {
2994
+ var _obj, error;
2995
+ return _ts_generator(this, function(_state) {
2996
+ switch(_state.label){
2997
+ case 0:
2998
+ _state.trys.push([
2999
+ 0,
3000
+ 2,
3001
+ ,
3002
+ 3
3003
+ ]);
3004
+ return [
3005
+ 4,
3006
+ navigator.clipboard.write([
3007
+ new ClipboardItem((_obj = {}, _define_property(_obj, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, new Blob([
3008
+ text
3009
+ ], {
3010
+ type: PLAIN_TEXT_CLIPBOARD_MIME_TYPE
3011
+ })), _define_property(_obj, HTML_CLIPBOARD_MIME_TYPE, new Blob([
3012
+ html
3013
+ ], {
3014
+ type: HTML_CLIPBOARD_MIME_TYPE
3015
+ })), _obj))
3016
+ ])
3017
+ ];
3018
+ case 1:
3019
+ return [
3020
+ 2,
3021
+ _state.sent()
3022
+ ];
3023
+ case 2:
3024
+ error = _state.sent();
3025
+ console.error(error);
3026
+ return [
3027
+ 3,
3028
+ 3
3029
+ ];
3030
+ case 3:
3031
+ return [
3032
+ 2
3033
+ ];
3034
+ }
3035
+ });
3036
+ })();
3037
+ }
3038
+ },
3039
+ {
3040
+ key: "writeText",
3041
+ value: function writeText(text) {
3042
+ return _async_to_generator(function() {
3043
+ var error, activeElement, container;
3044
+ return _ts_generator(this, function(_state) {
3045
+ switch(_state.label){
3046
+ case 0:
3047
+ _state.trys.push([
3048
+ 0,
3049
+ 2,
3050
+ ,
3051
+ 3
3052
+ ]);
3053
+ return [
3054
+ 4,
3055
+ navigator.clipboard.writeText(text)
3056
+ ];
3057
+ case 1:
3058
+ return [
3059
+ 2,
3060
+ _state.sent()
3061
+ ];
3062
+ case 2:
3063
+ error = _state.sent();
3064
+ console.error(error);
3065
+ return [
3066
+ 3,
3067
+ 3
3068
+ ];
3069
+ case 3:
3070
+ activeElement = document.activeElement;
3071
+ container = createCopyPasteContainer();
3072
+ container.value = text;
3073
+ container.focus();
3074
+ container.select();
3075
+ document.body.appendChild(container);
3076
+ document.execCommand("copy");
3077
+ if (_instanceof(activeElement, HTMLElement)) {
3078
+ activeElement.focus();
3079
+ }
3080
+ document.removeChild(container);
3081
+ return [
3082
+ 2
3083
+ ];
3084
+ }
3085
+ });
3086
+ })();
3087
+ }
3088
+ },
3089
+ {
3090
+ key: "read",
3091
+ value: function read() {
3092
+ return _async_to_generator(function() {
3093
+ return _ts_generator(this, function(_state) {
3094
+ return [
3095
+ 2,
3096
+ navigator.clipboard.read()
3097
+ ];
3098
+ });
3099
+ })();
3100
+ }
3101
+ },
3102
+ {
3103
+ key: "readText",
3104
+ value: function readText() {
3105
+ return _async_to_generator(function() {
3106
+ var e;
3107
+ return _ts_generator(this, function(_state) {
3108
+ switch(_state.label){
3109
+ case 0:
3110
+ _state.trys.push([
3111
+ 0,
3112
+ 2,
3113
+ ,
3114
+ 3
3115
+ ]);
3116
+ return [
3117
+ 4,
3118
+ navigator.clipboard.readText()
3119
+ ];
3120
+ case 1:
3121
+ return [
3122
+ 2,
3123
+ _state.sent()
3124
+ ];
3125
+ case 2:
3126
+ e = _state.sent();
3127
+ console.error(e);
3128
+ return [
3129
+ 2,
3130
+ ""
3131
+ ];
3132
+ case 3:
3133
+ return [
3134
+ 2
3135
+ ];
3136
+ }
3137
+ });
3138
+ })();
3139
+ }
3140
+ }
3141
+ ]);
3142
+ return BrowserClipboardService;
3143
+ }(import_core17.Disposable);
3144
+ function createCopyPasteContainer() {
3145
+ var textArea = document.createElement("textarea");
3146
+ textArea.style.position = "absolute";
3147
+ textArea.style.height = "1px";
3148
+ textArea.style.width = "1px";
3149
+ return textArea;
3150
+ }
3151
+ // src/services/confirm/desktop-confirm.service.ts
3152
+ var import_core18 = require("@univerjs/core");
3153
+ var import_rxjs10 = require("rxjs");
3154
+ var DesktopConfirmService = /*#__PURE__*/ function() {
3155
+ function DesktopConfirmService() {
3156
+ _class_call_check(this, DesktopConfirmService);
3157
+ _define_property(this, "confirmOptions", []);
3158
+ _define_property(this, "confirmOptions$", new import_rxjs10.Subject());
3159
+ }
3160
+ _create_class(DesktopConfirmService, [
3161
+ {
3162
+ key: "open",
3163
+ value: function open(option) {
3164
+ var _this = this;
3165
+ if (this.confirmOptions.find(function(item) {
3166
+ return item.id === option.id;
3167
+ })) {
3168
+ this.confirmOptions = this.confirmOptions.map(function(item) {
3169
+ return _object_spread_props(_object_spread({}, item.id === option.id ? option : item), {
3170
+ visible: true
3171
+ });
3172
+ });
3173
+ } else {
3174
+ this.confirmOptions.push(_object_spread_props(_object_spread({}, option), {
3175
+ visible: true
3176
+ }));
3177
+ }
3178
+ this.confirmOptions$.next(this.confirmOptions);
3179
+ return (0, import_core18.toDisposable)(function() {
3180
+ _this.confirmOptions = [];
3181
+ _this.confirmOptions$.next([]);
3182
+ });
3183
+ }
3184
+ },
3185
+ {
3186
+ key: "close",
3187
+ value: function close(id) {
3188
+ this.confirmOptions = this.confirmOptions.map(function(item) {
3189
+ return _object_spread_props(_object_spread({}, item), {
3190
+ visible: item.id === id ? false : item.visible
3191
+ });
3192
+ });
3193
+ this.confirmOptions$.next(_to_consumable_array(this.confirmOptions));
3194
+ }
3195
+ },
3196
+ {
3197
+ key: "getObservableConfirm",
3198
+ value: function getObservableConfirm() {
3199
+ return this.confirmOptions$;
3200
+ }
3201
+ }
3202
+ ]);
3203
+ return DesktopConfirmService;
3204
+ }();
3205
+ // src/services/dialog/desktop-dialog.service.ts
3206
+ var import_core19 = require("@univerjs/core");
3207
+ var import_rxjs11 = require("rxjs");
3208
+ var DesktopDialogService = /*#__PURE__*/ function() {
3209
+ function DesktopDialogService() {
3210
+ _class_call_check(this, DesktopDialogService);
3211
+ _define_property(this, "dialogOptions", []);
3212
+ _define_property(this, "dialogOptions$", new import_rxjs11.Subject());
3213
+ }
3214
+ _create_class(DesktopDialogService, [
3215
+ {
3216
+ key: "open",
3217
+ value: function open(option) {
3218
+ var _this = this;
3219
+ if (this.dialogOptions.find(function(item) {
3220
+ return item.id === option.id;
3221
+ })) {
3222
+ this.dialogOptions = this.dialogOptions.map(function(item) {
3223
+ return _object_spread_props(_object_spread({}, item.id === option.id ? option : item), {
3224
+ visible: true
3225
+ });
3226
+ });
3227
+ } else {
3228
+ this.dialogOptions.push(_object_spread_props(_object_spread({}, option), {
3229
+ visible: true
3230
+ }));
3231
+ }
3232
+ this.dialogOptions$.next(this.dialogOptions);
3233
+ return (0, import_core19.toDisposable)(function() {
3234
+ _this.dialogOptions = [];
3235
+ _this.dialogOptions$.next([]);
3236
+ });
3237
+ }
3238
+ },
3239
+ {
3240
+ key: "close",
3241
+ value: function close(id) {
3242
+ this.dialogOptions = this.dialogOptions.map(function(item) {
3243
+ return _object_spread_props(_object_spread({}, item), {
3244
+ visible: item.id === id ? false : item.visible
3245
+ });
3246
+ });
3247
+ this.dialogOptions$.next(_to_consumable_array(this.dialogOptions));
3248
+ }
3249
+ },
3250
+ {
3251
+ key: "getObservableDialog",
3252
+ value: function getObservableDialog() {
3253
+ return this.dialogOptions$;
3254
+ }
3255
+ }
3256
+ ]);
3257
+ return DesktopDialogService;
3258
+ }();
3259
+ // src/services/message/desktop-message.service.ts
3260
+ var import_core20 = require("@univerjs/core");
3261
+ var import_design8 = require("@univerjs/design");
3262
+ var DesktopMessageService = /*#__PURE__*/ function() {
3263
+ function DesktopMessageService() {
3264
+ _class_call_check(this, DesktopMessageService);
3265
+ _define_property(this, "portalContainer", document.body);
3266
+ _define_property(this, "message", void 0);
3267
+ }
3268
+ _create_class(DesktopMessageService, [
3269
+ {
3270
+ key: "setContainer",
3271
+ value: function setContainer(container) {
3272
+ this.portalContainer = container;
3273
+ this.message = new import_design8.Message(container);
3274
+ }
3275
+ },
3276
+ {
3277
+ key: "show",
3278
+ value: function show(options) {
3279
+ var type = options.type, rest = _object_without_properties(options, [
3280
+ "type"
3281
+ ]);
3282
+ this.message && this.message[type](rest);
3283
+ return (0, import_core20.toDisposable)(function() {});
3284
+ }
3285
+ }
3286
+ ]);
3287
+ return DesktopMessageService;
3288
+ }();
3289
+ // src/services/notification/desktop-notification.service.ts
3290
+ var import_core21 = require("@univerjs/core");
3291
+ var DesktopNotificationService = /*#__PURE__*/ function() {
3292
+ function DesktopNotificationService() {
3293
+ _class_call_check(this, DesktopNotificationService);
3294
+ }
3295
+ _create_class(DesktopNotificationService, [
3296
+ {
3297
+ key: "show",
3298
+ value: function show(params) {
3299
+ notification.show(params);
3300
+ return (0, import_core21.toDisposable)(function() {});
3301
+ }
3302
+ }
3303
+ ]);
3304
+ return DesktopNotificationService;
3305
+ }();
3306
+ // src/services/shortcut/shortcut-experience.service.ts
3307
+ var import_core22 = require("@univerjs/core");
3308
+ var import_redi16 = require("@wendellhu/redi");
3309
+ var ShortcutExperienceService = /*#__PURE__*/ function() {
3310
+ function ShortcutExperienceService(_currentUniverService, _localeService) {
3311
+ _class_call_check(this, ShortcutExperienceService);
3312
+ _define_property(this, "_current", null);
3313
+ _define_property(this, "_shortcutParam", []);
3314
+ this._currentUniverService = _currentUniverService;
3315
+ this._localeService = _localeService;
3316
+ }
3317
+ _create_class(ShortcutExperienceService, [
3318
+ {
3319
+ key: "dispose",
3320
+ value: function dispose() {
3321
+ this._shortcutParam = [];
3322
+ }
3323
+ },
3324
+ {
3325
+ key: "getCurrentBySearch",
3326
+ value: function getCurrentBySearch(searchParm) {
3327
+ return this._getCurrentBySearch(searchParm);
3328
+ }
3329
+ },
3330
+ {
3331
+ key: "getCurrent",
3332
+ value: function getCurrent() {
3333
+ return this._getCurrentBySearch(this._current);
3334
+ }
3335
+ },
3336
+ {
3337
+ key: "addOrUpdate",
3338
+ value: function addOrUpdate(insertParam) {
3339
+ var param = this._getCurrentBySearch({
3340
+ unitId: insertParam.unitId,
3341
+ sheetId: insertParam.sheetId,
3342
+ keycode: insertParam.keycode
3343
+ });
3344
+ if (param != null) {
3345
+ var index = this._shortcutParam.indexOf(param);
3346
+ this._shortcutParam.splice(index, 1);
3347
+ }
3348
+ this._shortcutParam.push(insertParam);
3349
+ return param;
3350
+ }
3351
+ },
3352
+ {
3353
+ key: "remove",
3354
+ value: function remove(searchParm) {
3355
+ if (searchParm == null) {
3356
+ return;
3357
+ }
3358
+ var param = this._getCurrentBySearch(searchParm);
3359
+ if (param == null) {
3360
+ return;
3361
+ }
3362
+ var index = this._shortcutParam.indexOf(param);
3363
+ return this._shortcutParam.splice(index, 1)[0];
3364
+ }
3365
+ },
3366
+ {
3367
+ key: "_getCurrentBySearch",
3368
+ value: function _getCurrentBySearch(searchParm) {
3369
+ if (searchParm == null) {
3370
+ return;
3371
+ }
3372
+ var item = this._shortcutParam.find(function(param) {
3373
+ return param.unitId === searchParm.unitId && param.sheetId === searchParm.sheetId && param.keycode === searchParm.keycode;
3374
+ });
3375
+ return item;
3376
+ }
3377
+ }
3378
+ ]);
3379
+ return ShortcutExperienceService;
3380
+ }();
3381
+ ShortcutExperienceService = __decorateClass([
3382
+ __decorateParam(0, import_core22.IUniverInstanceService),
3383
+ __decorateParam(1, (0, import_redi16.Inject)(import_core22.LocaleService))
3384
+ ], ShortcutExperienceService);
3385
+ // src/services/sidebar/desktop-sidebar.service.ts
3386
+ var import_core23 = require("@univerjs/core");
3387
+ var import_rxjs12 = require("rxjs");
3388
+ var DesktopSidebarService = /*#__PURE__*/ function() {
3389
+ function DesktopSidebarService() {
3390
+ _class_call_check(this, DesktopSidebarService);
3391
+ _define_property(this, "sidebarOptions", {});
3392
+ _define_property(this, "sidebarOptions$", new import_rxjs12.Subject());
3393
+ }
3394
+ _create_class(DesktopSidebarService, [
3395
+ {
3396
+ key: "open",
3397
+ value: function open(option) {
3398
+ var _this = this;
3399
+ this.sidebarOptions = _object_spread_props(_object_spread({}, option), {
3400
+ visible: true
3401
+ });
3402
+ this.sidebarOptions$.next(this.sidebarOptions);
3403
+ return (0, import_core23.toDisposable)(function() {
3404
+ _this.sidebarOptions$.next({});
3405
+ });
3406
+ }
3407
+ },
3408
+ {
3409
+ key: "close",
3410
+ value: function close() {
3411
+ this.sidebarOptions = _object_spread_props(_object_spread({}, this.sidebarOptions), {
3412
+ visible: false
3413
+ });
3414
+ this.sidebarOptions$.next(this.sidebarOptions);
3415
+ this.sidebarOptions.onClose && this.sidebarOptions.onClose();
3416
+ }
3417
+ },
3418
+ {
3419
+ key: "getObservableSidebar",
3420
+ value: function getObservableSidebar() {
3421
+ return this.sidebarOptions$;
3422
+ }
3423
+ }
3424
+ ]);
3425
+ return DesktopSidebarService;
3426
+ }();
3427
+ // src/ui-plugin.ts
3428
+ var import_core29 = require("@univerjs/core");
3429
+ var import_redi19 = require("@wendellhu/redi");
3430
+ // src/controllers/error/error.controller.ts
3431
+ var import_core24 = require("@univerjs/core");
3432
+ var import_design9 = require("@univerjs/design");
3433
+ var import_redi17 = require("@wendellhu/redi");
3434
+ var ErrorController = /*#__PURE__*/ function(_import_core24_Disposable) {
3435
+ _inherits(ErrorController, _import_core24_Disposable);
3436
+ var _super = _create_super(ErrorController);
3437
+ function ErrorController(_errorService, _messageService) {
3438
+ _class_call_check(this, ErrorController);
3439
+ var _this;
3440
+ _this = _super.call(this);
3441
+ _this._errorService = _errorService;
3442
+ _this._messageService = _messageService;
3443
+ _this.disposeWithMe((0, import_core24.toDisposable)(_this._errorService.error$.subscribe(function(error) {
3444
+ _this._messageService.show({
3445
+ content: error.errorKey,
3446
+ type: import_design9.MessageType.Error
3447
+ });
3448
+ })));
3449
+ return _this;
3450
+ }
3451
+ return ErrorController;
3452
+ }(import_core24.Disposable);
3453
+ ErrorController = __decorateClass([
3454
+ (0, import_core24.OnLifecycle)(import_core24.LifecycleStages.Starting, ErrorController),
3455
+ __decorateParam(0, (0, import_redi17.Inject)(import_core24.ErrorService)),
3456
+ __decorateParam(1, IMessageService)
3457
+ ], ErrorController);
3458
+ // src/controllers/shortcut-display/shortcut-panel.controller.ts
3459
+ var import_core28 = require("@univerjs/core");
3460
+ var import_redi18 = require("@wendellhu/redi");
3461
+ // src/commands/operations/toggle-shortcut-panel.operation.ts
3462
+ var import_core26 = require("@univerjs/core");
3463
+ // src/services/shortcut/shortcut-panel.service.ts
3464
+ var import_core25 = require("@univerjs/core");
3465
+ var import_rxjs13 = require("rxjs");
3466
+ var ShortcutPanelService = /*#__PURE__*/ function(_import_core25_Disposable) {
3467
+ _inherits(ShortcutPanelService, _import_core25_Disposable);
3468
+ var _super = _create_super(ShortcutPanelService);
3469
+ function ShortcutPanelService() {
3470
+ _class_call_check(this, ShortcutPanelService);
3471
+ var _this;
3472
+ _this = _super.apply(this, arguments);
3473
+ _define_property(_assert_this_initialized(_this), "_open$", new import_rxjs13.BehaviorSubject(false));
3474
+ _define_property(_assert_this_initialized(_this), "open$", _this._open$.pipe((0, import_rxjs13.distinctUntilChanged)()));
3475
+ return _this;
3476
+ }
3477
+ _create_class(ShortcutPanelService, [
3478
+ {
3479
+ key: "isOpen",
3480
+ get: function get() {
3481
+ return this._open$.getValue();
3482
+ }
3483
+ },
3484
+ {
3485
+ key: "dispose",
3486
+ value: function dispose() {
3487
+ this._open$.next(false);
3488
+ this._open$.complete();
3489
+ }
3490
+ },
3491
+ {
3492
+ key: "open",
3493
+ value: function open() {
3494
+ this._open$.next(true);
3495
+ }
3496
+ },
3497
+ {
3498
+ key: "close",
3499
+ value: function close() {
3500
+ this._open$.next(false);
3501
+ }
3502
+ }
3503
+ ]);
3504
+ return ShortcutPanelService;
3505
+ }(import_core25.Disposable);
3506
+ // src/commands/operations/toggle-shortcut-panel.operation.ts
3507
+ var ShortcutPanelComponentName = "ShortcutPanel";
3508
+ var ToggleShortcutPanelOperation = {
3509
+ id: "base-ui.operation.toggle-shortcut-panel",
3510
+ type: import_core26.CommandType.OPERATION,
3511
+ handler: function(accessor) {
3512
+ var shortcutPanelService = accessor.get(ShortcutPanelService);
3513
+ var sidebarService = accessor.get(ISidebarService);
3514
+ var isOpen = shortcutPanelService.isOpen;
3515
+ if (isOpen) {
3516
+ shortcutPanelService.close();
3517
+ sidebarService.close();
3518
+ } else {
3519
+ shortcutPanelService.open();
3520
+ sidebarService.open({
3521
+ header: {
3522
+ title: "shortcut-panel.title"
3523
+ },
3524
+ children: {
3525
+ label: ShortcutPanelComponentName
3526
+ }
3527
+ });
3528
+ }
3529
+ return true;
3530
+ }
3531
+ };
3532
+ // src/views/components/shortcut-panel/ShortcutPanel.tsx
3533
+ var import_core27 = require("@univerjs/core");
3534
+ var import_react_bindings12 = require("@wendellhu/redi/react-bindings");
3535
+ var import_react16 = __toESM(require("react"));
3536
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/ui/src/views/components/shortcut-panel/index.module.less
3537
+ var index_module_default6 = {
3538
+ "shortcutPanelGroupTitle": "univer-shortcut-panel-group-title",
3539
+ "shortcutPanelItem": "univer-shortcut-panel-item",
3540
+ "shortcutPanelItemTitle": "univer-shortcut-panel-item-title",
3541
+ "shortcutPanelItemShortcut": "univer-shortcut-panel-item-shortcut"
3542
+ };
3543
+ // src/views/components/shortcut-panel/ShortcutPanel.tsx
3544
+ function ShortcutPanel() {
3545
+ var shortcutService = (0, import_react_bindings12.useDependency)(IShortcutService);
3546
+ var localeService = (0, import_react_bindings12.useDependency)(import_core27.LocaleService);
3547
+ var _import_react16_default_useState = _sliced_to_array(import_react16.default.useState([]), 2), shortcutItems = _import_react16_default_useState[0], setShortcutItems = _import_react16_default_useState[1];
3548
+ var updateShortcuts = (0, import_react16.useCallback)(function() {
3549
+ var shortcutGroups = /* @__PURE__ */ new Map();
3550
+ var shortcuts = shortcutService.getAllShortcuts().filter(function(item) {
3551
+ return !!item.group;
3552
+ });
3553
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3554
+ try {
3555
+ for(var _iterator = shortcuts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3556
+ var shortcut = _step.value;
3557
+ var group = shortcut.group;
3558
+ var _shortcut_description;
3559
+ var shortcutItem = {
3560
+ title: localeService.t((_shortcut_description = shortcut.description) !== null && _shortcut_description !== void 0 ? _shortcut_description : shortcut.id),
3561
+ shortcut: shortcutService.getShortcutDisplay(shortcut)
3562
+ };
3563
+ if (!/\d+_[a-zA-Z0-9]/.test(group)) {
3564
+ throw new Error("[ShortcutPanel]: Invalid shortcut group: ".concat(group, "!"));
3565
+ }
3566
+ if (!shortcutGroups.has(group)) {
3567
+ shortcutGroups.set(group, []);
3568
+ }
3569
+ shortcutGroups.get(group).push(shortcutItem);
3570
+ }
3571
+ } catch (err) {
3572
+ _didIteratorError = true;
3573
+ _iteratorError = err;
3574
+ } finally{
3575
+ try {
3576
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3577
+ _iterator.return();
3578
+ }
3579
+ } finally{
3580
+ if (_didIteratorError) {
3581
+ throw _iteratorError;
3582
+ }
3583
+ }
3584
+ }
3585
+ var toRender = Array.from(shortcutGroups.entries()).map(function(param) {
3586
+ var _param = _sliced_to_array(param, 2), name = _param[0], items = _param[1];
3587
+ var groupSequence = name.split("_")[0];
3588
+ var groupName = name.slice(groupSequence.length + 1);
3589
+ return {
3590
+ sequence: +groupSequence,
3591
+ name: localeService.t(groupName),
3592
+ items: items
3593
+ };
3594
+ }).sort(function(a, b) {
3595
+ return a.sequence - b.sequence;
3596
+ });
3597
+ setShortcutItems(toRender);
3598
+ }, [
3599
+ shortcutService,
3600
+ localeService
3601
+ ]);
3602
+ (0, import_react16.useEffect)(function() {
3603
+ updateShortcuts();
3604
+ var subscription = shortcutService.shortcutChanged$.subscribe(function() {
3605
+ return updateShortcuts();
3606
+ });
3607
+ return function() {
3608
+ return subscription.unsubscribe();
3609
+ };
3610
+ }, [
3611
+ shortcutService
3612
+ ]);
3613
+ return /* @__PURE__ */ import_react16.default.createElement("div", {
3614
+ className: index_module_default6.shortcutPanel
3615
+ }, shortcutItems.map(function(group) {
3616
+ return /* @__PURE__ */ import_react16.default.createElement("div", {
3617
+ className: index_module_default6.shortcutPanelGroup,
3618
+ key: group.name
3619
+ }, /* @__PURE__ */ import_react16.default.createElement("div", {
3620
+ className: index_module_default6.shortcutPanelGroupTitle
3621
+ }, group.name), group.items.map(function(item, index) {
3622
+ return /* @__PURE__ */ import_react16.default.createElement("div", {
3623
+ className: index_module_default6.shortcutPanelItem,
3624
+ key: index
3625
+ }, /* @__PURE__ */ import_react16.default.createElement("span", {
3626
+ className: index_module_default6.shortcutPanelItemTitle
3627
+ }, item.title), /* @__PURE__ */ import_react16.default.createElement("span", {
3628
+ className: index_module_default6.shortcutPanelItemShortcut
3629
+ }, item.shortcut));
3630
+ }));
3631
+ }));
3632
+ }
3633
+ // src/controllers/shortcut-display/menu.ts
3634
+ function ShortcutPanelMenuItemFactory() {
3635
+ return {
3636
+ id: ToggleShortcutPanelOperation.id,
3637
+ title: "toggle-shortcut-panel",
3638
+ tooltip: "toggle-shortcut-panel",
3639
+ icon: "KeyboardSingle",
3640
+ type: 0 /* BUTTON */ ,
3641
+ positions: [
3642
+ "uiToolbar.others" /* TOOLBAR_OTHERS */
3643
+ ]
3644
+ };
3645
+ }
3646
+ // src/controllers/shortcut-display/shortcut-panel.controller.ts
3647
+ var ShortcutPanelController = /*#__PURE__*/ function(_import_core28_Disposable) {
3648
+ _inherits(ShortcutPanelController, _import_core28_Disposable);
3649
+ var _super = _create_super(ShortcutPanelController);
3650
+ function ShortcutPanelController(menuService, commandService, componentManager) {
3651
+ _class_call_check(this, ShortcutPanelController);
3652
+ var _this;
3653
+ _this = _super.call(this);
3654
+ _this.disposeWithMe(menuService.addMenuItem(ShortcutPanelMenuItemFactory()));
3655
+ _this.disposeWithMe(componentManager.register(ShortcutPanelComponentName, ShortcutPanel));
3656
+ _this.disposeWithMe(commandService.registerCommand(ToggleShortcutPanelOperation));
3657
+ return _this;
3658
+ }
3659
+ return ShortcutPanelController;
3660
+ }(import_core28.Disposable);
3661
+ ShortcutPanelController = __decorateClass([
3662
+ (0, import_core28.OnLifecycle)(import_core28.LifecycleStages.Steady, ShortcutPanelController),
3663
+ __decorateParam(0, IMenuService),
3664
+ __decorateParam(1, import_core28.ICommandService),
3665
+ __decorateParam(2, (0, import_redi18.Inject)(ComponentManager))
3666
+ ], ShortcutPanelController);
3667
+ // src/locale/en-US.ts
3668
+ var en_US_default = {
3669
+ uiToolbar: {
3670
+ start: "Start",
3671
+ insert: "Insert",
3672
+ formulas: "Formulas",
3673
+ data: "Data",
3674
+ view: "View",
3675
+ others: "Others"
3676
+ },
3677
+ "shortcut-panel": {
3678
+ title: "Shortcuts"
3679
+ },
3680
+ shortcut: {
3681
+ undo: "Undo",
3682
+ redo: "Redo",
3683
+ cut: "Cut",
3684
+ copy: "Copy",
3685
+ paste: "Paste"
3686
+ },
3687
+ "common-edit": "Common Editing Shortcuts"
3688
+ };
3689
+ // src/services/local-storage/local-storage.service.ts
3690
+ var import_localforage = __toESM(require("localforage"));
3691
+ var DesktopLocalStorageService = /*#__PURE__*/ function() {
3692
+ function DesktopLocalStorageService() {
3693
+ _class_call_check(this, DesktopLocalStorageService);
3694
+ }
3695
+ _create_class(DesktopLocalStorageService, [
3696
+ {
3697
+ key: "getItem",
3698
+ value: function getItem(key) {
3699
+ return import_localforage.default.getItem(key);
3700
+ }
3701
+ },
3702
+ {
3703
+ key: "setItem",
3704
+ value: function setItem(key, value) {
3705
+ return import_localforage.default.setItem(key, value);
3706
+ }
3707
+ },
3708
+ {
3709
+ key: "removeItem",
3710
+ value: function removeItem(key) {
3711
+ return import_localforage.default.removeItem(key);
3712
+ }
3713
+ },
3714
+ {
3715
+ key: "clear",
3716
+ value: function clear() {
3717
+ return import_localforage.default.clear();
3718
+ }
3719
+ },
3720
+ {
3721
+ key: "key",
3722
+ value: function key(index) {
3723
+ return import_localforage.default.key(index);
3724
+ }
3725
+ },
3726
+ {
3727
+ key: "keys",
3728
+ value: function keys() {
3729
+ return import_localforage.default.keys();
3730
+ }
3731
+ },
3732
+ {
3733
+ key: "iterate",
3734
+ value: function iterate(iteratee) {
3735
+ return import_localforage.default.iterate(iteratee);
3736
+ }
3737
+ }
3738
+ ]);
3739
+ return DesktopLocalStorageService;
3740
+ }();
3741
+ // src/ui-plugin.ts
3742
+ var PLUGIN_NAME = "ui";
3743
+ var DEFAULT_SLIDE_PLUGIN_DATA = {};
3744
+ var UIPlugin = (_class = /*#__PURE__*/ function(_superClass) {
3745
+ _inherits(_class, _superClass);
3746
+ var _super = _create_super(_class);
3747
+ function _class() {
3748
+ var config = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _injector = arguments.length > 1 ? arguments[1] : void 0, _localeService = arguments.length > 2 ? arguments[2] : void 0;
3749
+ _class_call_check(this, _class);
3750
+ var _this;
3751
+ _this = _super.call(this, PLUGIN_NAME);
3752
+ _define_property(_assert_this_initialized(_this), "_config", void 0);
3753
+ _this._injector = _injector;
3754
+ _this._localeService = _localeService;
3755
+ _this._config = Object.assign(DEFAULT_SLIDE_PLUGIN_DATA, config);
3756
+ _this._localeService.load({
3757
+ enUS: en_US_default
3758
+ });
3759
+ return _this;
3760
+ }
3761
+ _create_class(_class, [
3762
+ {
3763
+ key: "onStarting",
3764
+ value: function onStarting(_injector) {
3765
+ this._initDependencies(_injector);
3766
+ }
3767
+ },
3768
+ {
3769
+ key: "onReady",
3770
+ value: function onReady() {
3771
+ this._initUI();
3772
+ }
3773
+ },
3774
+ {
3775
+ key: "_initDependencies",
3776
+ value: function _initDependencies(injector) {
3777
+ var dependencies = [
3778
+ // legacy managers - deprecated
3779
+ [
3780
+ ComponentManager
3781
+ ],
3782
+ [
3783
+ ZIndexManager
3784
+ ],
3785
+ // services
3786
+ [
3787
+ ShortcutExperienceService
3788
+ ],
3789
+ [
3790
+ ShortcutPanelService
3791
+ ],
3792
+ [
3793
+ IShortcutService,
3794
+ {
3795
+ useClass: DesktopShortcutService
3796
+ }
3797
+ ],
3798
+ [
3799
+ IPlatformService,
3800
+ {
3801
+ useClass: DesktopPlatformService
3802
+ }
3803
+ ],
3804
+ [
3805
+ IMenuService,
3806
+ {
3807
+ useClass: DesktopMenuService
3808
+ }
3809
+ ],
3810
+ [
3811
+ IContextMenuService,
3812
+ {
3813
+ useClass: DesktopContextMenuService
3814
+ }
3815
+ ],
3816
+ [
3817
+ IClipboardInterfaceService,
3818
+ {
3819
+ useClass: BrowserClipboardService,
3820
+ lazy: true
3821
+ }
3822
+ ],
3823
+ [
3824
+ INotificationService,
3825
+ {
3826
+ useClass: DesktopNotificationService,
3827
+ lazy: true
3828
+ }
3829
+ ],
3830
+ [
3831
+ IDialogService,
3832
+ {
3833
+ useClass: DesktopDialogService,
3834
+ lazy: true
3835
+ }
3836
+ ],
3837
+ [
3838
+ IConfirmService,
3839
+ {
3840
+ useClass: DesktopConfirmService,
3841
+ lazy: true
3842
+ }
3843
+ ],
3844
+ [
3845
+ ISidebarService,
3846
+ {
3847
+ useClass: DesktopSidebarService,
3848
+ lazy: true
3849
+ }
3850
+ ],
3851
+ [
3852
+ IMessageService,
3853
+ {
3854
+ useClass: DesktopMessageService,
3855
+ lazy: true
3856
+ }
3857
+ ],
3858
+ [
3859
+ import_core29.ILocalStorageService,
3860
+ {
3861
+ useClass: DesktopLocalStorageService,
3862
+ lazy: true
3863
+ }
3864
+ ],
3865
+ [
3866
+ IBeforeCloseService,
3867
+ {
3868
+ useClass: DesktopBeforeCloseService
3869
+ }
3870
+ ],
3871
+ // controllers
3872
+ [
3873
+ IFocusService,
3874
+ {
3875
+ useClass: DesktopFocusService
3876
+ }
3877
+ ],
3878
+ [
3879
+ IUIController,
3880
+ {
3881
+ useClass: DesktopUIController
3882
+ }
3883
+ ],
3884
+ [
3885
+ SharedController
3886
+ ],
3887
+ [
3888
+ ErrorController
3889
+ ],
3890
+ [
3891
+ ShortcutPanelController
3892
+ ]
3893
+ ];
3894
+ dependencies.forEach(function(dependency) {
3895
+ return injector.add(dependency);
3896
+ });
3897
+ }
3898
+ },
3899
+ {
3900
+ key: "_initUI",
3901
+ value: function _initUI() {
3902
+ var _this = this;
3903
+ Promise.resolve().then(function() {
3904
+ return _this._injector.get(IUIController).bootstrapWorkbench(_this._config);
3905
+ });
3906
+ }
3907
+ }
3908
+ ]);
3909
+ return _class;
3910
+ }(_import_core29_Plugin = import_core29.Plugin), _define_property(_class, "type", import_core29.PluginType.Univer), _class);
3911
+ UIPlugin = __decorateClass([
3912
+ __decorateParam(1, (0, import_redi19.Inject)(import_redi19.Injector)),
3913
+ __decorateParam(2, (0, import_redi19.Inject)(import_core29.LocaleService))
3914
+ ], UIPlugin);
3915
+ // src/utils/cell.ts
3916
+ var import_core30 = require("@univerjs/core");
3917
+ var import_engine_render2 = require("@univerjs/engine-render");
3918
+ // src/utils/util.ts
3919
+ function textTrim(x) {
3920
+ if (x.length === 0) {
3921
+ return x;
3922
+ }
3923
+ return x.replace(/^\s+|\s+$/gm, "");
3924
+ }
3925
+ // src/utils/cell.ts
3926
+ function handleDomToJson($dom) {
3927
+ var _loop = function(i) {
3928
+ var span = nodeList["".concat(i)];
3929
+ var str = void 0;
3930
+ if (span.nodeName === "#text") {
3931
+ var _span_textContent;
3932
+ str = (_span_textContent = span.textContent) !== null && _span_textContent !== void 0 ? _span_textContent : "";
3933
+ span = span.parentElement;
3934
+ } else {
3935
+ str = span.innerText;
3936
+ }
3937
+ var textStyle = handleStringToStyle(span);
3938
+ var spanTexts = splitSpanText(str);
3939
+ spanTexts.forEach(function(item) {
3940
+ var length = item.length;
3941
+ ed += length;
3942
+ st = ed - length;
3943
+ var sId = import_core30.Tools.generateRandomId(6);
3944
+ textRuns.push({
3945
+ sId: sId,
3946
+ st: st,
3947
+ ed: ed - 1,
3948
+ ts: textStyle
3949
+ });
3950
+ });
3951
+ };
3952
+ var nodeList = $dom.childNodes;
3953
+ if (nodeList.length === 0) {
3954
+ return $dom.textContent;
3955
+ }
3956
+ if (nodeList[0].nodeName === "DIV") {
3957
+ nodeList = nodeList[0].childNodes;
3958
+ }
3959
+ if (nodeList.length === 1 && nodeList[0].nodeName === "#text") {
3960
+ return nodeList[0].textContent;
3961
+ }
3962
+ var textRuns = [];
3963
+ var st = 0;
3964
+ var ed = 0;
3965
+ var dataStream = $dom.textContent || "";
3966
+ dataStream += "\r\n";
3967
+ for(var i = 0; i < nodeList.length; i++)_loop(i);
3968
+ var blockId = import_core30.Tools.generateRandomId(6);
3969
+ var p = {
3970
+ id: import_core30.Tools.generateRandomId(6),
3971
+ body: {
3972
+ dataStream: dataStream,
3973
+ textRuns: textRuns
3974
+ },
3975
+ documentStyle: {}
3976
+ };
3977
+ return p;
3978
+ }
3979
+ function handleStringToStyle($dom) {
3980
+ var cssStyle = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
3981
+ var _$dom_style;
3982
+ var _$dom_style_cssText;
3983
+ var cssText = (_$dom_style_cssText = $dom === null || $dom === void 0 ? void 0 : (_$dom_style = $dom.style) === null || _$dom_style === void 0 ? void 0 : _$dom_style.cssText) !== null && _$dom_style_cssText !== void 0 ? _$dom_style_cssText : "";
3984
+ cssText += cssStyle;
3985
+ if (cssText.length === 0) {
3986
+ return {};
3987
+ }
3988
+ var cssTextArray = cssText.split(";");
3989
+ var styleList = {};
3990
+ var borderInfo = {
3991
+ t: "",
3992
+ r: "",
3993
+ b: "",
3994
+ l: ""
3995
+ };
3996
+ cssTextArray.forEach(function(s) {
3997
+ s = s.toLowerCase();
3998
+ var key = textTrim(s.substr(0, s.indexOf(":")));
3999
+ var value = textTrim(s.substr(s.indexOf(":") + 1));
4000
+ if (key === "font-weight") {
4001
+ if (value === "bold") {
4002
+ styleList.bl = 1;
4003
+ } else {
4004
+ styleList.bl = 0;
4005
+ }
4006
+ } else if (key === "font-style") {
4007
+ if (value === "italic") {
4008
+ styleList.it = 1;
4009
+ } else {
4010
+ styleList.it = 0;
4011
+ }
4012
+ } else if (key === "font-family") {
4013
+ styleList.ff = value;
4014
+ } else if (key === "font-size") {
4015
+ var fs = parseInt(value);
4016
+ if (cssText.indexOf("vertical-align") > -1 && (cssText.indexOf("sub") > -1 || cssText.indexOf("sup") > -1)) {
4017
+ fs *= 2;
4018
+ }
4019
+ if (value.indexOf("px") !== -1) {
4020
+ fs = (0, import_engine_render2.pxToPt)(parseInt(value));
4021
+ }
4022
+ styleList.fs = fs;
4023
+ } else if (key === "color") {
4024
+ styleList.cl = {
4025
+ rgb: value
4026
+ };
4027
+ } else if (key === "background" || key === "background-color") {
4028
+ styleList.bg = {
4029
+ rgb: value
4030
+ };
4031
+ } else if (key === "text-decoration-line") {
4032
+ if (value === "underline") {
4033
+ if (!styleList.ul) {
4034
+ styleList.ul = {
4035
+ s: 1
4036
+ };
4037
+ }
4038
+ styleList.ul.s = 1;
4039
+ } else if (value === "line-through") {
4040
+ if (!styleList.st) {
4041
+ styleList.st = {
4042
+ s: 1
4043
+ };
4044
+ }
4045
+ styleList.st.s = 1;
4046
+ } else if (value === "overline") {
4047
+ if (!styleList.ol) {
4048
+ styleList.ol = {
4049
+ s: 1
4050
+ };
4051
+ }
4052
+ styleList.ol.s = 1;
4053
+ }
4054
+ } else if (key === "text-decoration-color") {
4055
+ if (styleList.hasOwnProperty("ul")) {
4056
+ if (!styleList.ul) {
4057
+ styleList.ul = {
4058
+ s: 1,
4059
+ cl: {
4060
+ rgb: value
4061
+ }
4062
+ };
4063
+ }
4064
+ styleList.ul.cl = {
4065
+ rgb: value
4066
+ };
4067
+ }
4068
+ if (styleList.hasOwnProperty("st")) {
4069
+ if (!styleList.st) {
4070
+ styleList.st = {
4071
+ s: 1,
4072
+ cl: {
4073
+ rgb: value
4074
+ }
4075
+ };
4076
+ }
4077
+ styleList.st.cl = {
4078
+ rgb: value
4079
+ };
4080
+ }
4081
+ if (styleList.hasOwnProperty("ol")) {
4082
+ if (!styleList.ol) {
4083
+ styleList.ol = {
4084
+ s: 1,
4085
+ cl: {
4086
+ rgb: value
4087
+ }
4088
+ };
4089
+ }
4090
+ styleList.ol.cl = {
4091
+ rgb: value
4092
+ };
4093
+ }
4094
+ } else if (key === "text-decoration-style") {
4095
+ if (styleList.hasOwnProperty("ul")) {
4096
+ if (!styleList.ul) {
4097
+ styleList.ul = {
4098
+ s: 1,
4099
+ t: Number(value)
4100
+ };
4101
+ }
4102
+ styleList.ul.t = Number(value);
4103
+ }
4104
+ if (styleList.hasOwnProperty("st")) {
4105
+ if (!styleList.st) {
4106
+ styleList.st = {
4107
+ s: 1,
4108
+ t: Number(value)
4109
+ };
4110
+ }
4111
+ styleList.st.t = Number(value);
4112
+ }
4113
+ if (styleList.hasOwnProperty("ol")) {
4114
+ if (!styleList.ol) {
4115
+ styleList.ol = {
4116
+ s: 1,
4117
+ t: Number(value)
4118
+ };
4119
+ }
4120
+ styleList.ol.t = Number(value);
4121
+ }
4122
+ } else if (key === "text-decoration" || key === "univer-strike") {
4123
+ styleList.st = {
4124
+ s: 1
4125
+ };
4126
+ }
4127
+ if (key === "univer-underline") {
4128
+ styleList.ul = {
4129
+ s: 1
4130
+ };
4131
+ }
4132
+ if (key === "vertical-align") {
4133
+ if (value === "sub") {
4134
+ styleList.va = 1;
4135
+ } else if (value === "super") {
4136
+ styleList.va = 2;
4137
+ } else if (value === "top") {
4138
+ styleList.vt = 1;
4139
+ } else if (value === "middle") {
4140
+ styleList.vt = 2;
4141
+ } else if (value === "bottom") {
4142
+ styleList.vt = 3;
4143
+ } else {
4144
+ styleList.va = 0;
4145
+ }
4146
+ }
4147
+ if (key === "transform") {
4148
+ var values = value.split(")");
4149
+ var index = values.findIndex(function(item) {
4150
+ return item.includes("rotate");
4151
+ });
4152
+ if (index > -1) {
4153
+ var match = values[index].match(/\d+/g);
4154
+ var angle = 0;
4155
+ var ver = 0;
4156
+ if (match === null || match === void 0 ? void 0 : match.length) {
4157
+ angle = +match[0];
4158
+ }
4159
+ if ($dom === null || $dom === void 0 ? void 0 : $dom.dataset.vertical) {
4160
+ ver = +$dom.dataset.vertical;
4161
+ }
4162
+ styleList.tr = {
4163
+ a: angle,
4164
+ v: ver
4165
+ };
4166
+ }
4167
+ }
4168
+ if (key === "text-align") {
4169
+ if (value === "left") {
4170
+ styleList.ht = 1;
4171
+ } else if (value === "center") {
4172
+ styleList.ht = 2;
4173
+ } else if (value === "right") {
4174
+ styleList.ht = 3;
4175
+ } else if (value === "justify") {
4176
+ styleList.ht = 4;
4177
+ } else {
4178
+ styleList.ht = 0;
4179
+ }
4180
+ }
4181
+ if (key === "overflow-wrap" || key === "word-wrap") {
4182
+ if (value === "break-word") {
4183
+ styleList.tb = 3;
4184
+ }
4185
+ } else if (key === "text-overflow") {
4186
+ if (value === "clip") {
4187
+ styleList.tb = 2;
4188
+ }
4189
+ } else if (key === "text-break") {
4190
+ if (value === "overflow") {
4191
+ styleList.tb = 1;
4192
+ }
4193
+ }
4194
+ if (key === "border-color") {
4195
+ var colors = handleBorder(value, ")");
4196
+ if (!styleList.bd) {
4197
+ styleList.bd = {
4198
+ b: {
4199
+ cl: {
4200
+ rgb: "#000"
4201
+ },
4202
+ s: 0
4203
+ },
4204
+ t: {
4205
+ cl: {
4206
+ rgb: "#000"
4207
+ },
4208
+ s: 0
4209
+ },
4210
+ l: {
4211
+ cl: {
4212
+ rgb: "#000"
4213
+ },
4214
+ s: 0
4215
+ },
4216
+ r: {
4217
+ cl: {
4218
+ rgb: "#000"
4219
+ },
4220
+ s: 0
4221
+ }
4222
+ };
4223
+ for(var k in colors){
4224
+ styleList.bd[k].cl.rgb = colors[k];
4225
+ }
4226
+ } else {
4227
+ for(var k1 in colors){
4228
+ styleList.bd[k1].cl.rgb = colors[k1];
4229
+ }
4230
+ }
4231
+ }
4232
+ if (key === "border-width" || key === "border-style") {
4233
+ var width = handleBorder(value, " ");
4234
+ for(var k2 in width){
4235
+ borderInfo[k2] += " ".concat(width[k2]);
4236
+ }
4237
+ if (!styleList.bd) {
4238
+ styleList.bd = {
4239
+ b: {
4240
+ cl: {
4241
+ rgb: "#000"
4242
+ },
4243
+ s: (0, import_core30.getBorderStyleType)(borderInfo.b)
4244
+ },
4245
+ t: {
4246
+ cl: {
4247
+ rgb: "#000"
4248
+ },
4249
+ s: (0, import_core30.getBorderStyleType)(borderInfo.t)
4250
+ },
4251
+ l: {
4252
+ cl: {
4253
+ rgb: "#000"
4254
+ },
4255
+ s: (0, import_core30.getBorderStyleType)(borderInfo.l)
4256
+ },
4257
+ r: {
4258
+ cl: {
4259
+ rgb: "#000"
4260
+ },
4261
+ s: (0, import_core30.getBorderStyleType)(borderInfo.r)
4262
+ }
4263
+ };
4264
+ } else {
4265
+ styleList.bd.b.s = (0, import_core30.getBorderStyleType)(borderInfo.b);
4266
+ styleList.bd.t.s = (0, import_core30.getBorderStyleType)(borderInfo.t);
4267
+ styleList.bd.l.s = (0, import_core30.getBorderStyleType)(borderInfo.l);
4268
+ styleList.bd.r.s = (0, import_core30.getBorderStyleType)(borderInfo.r);
4269
+ }
4270
+ }
4271
+ if (key === "border-bottom" || key === "border-top" || key === "border-left" || key === "border-right" || key === "border") {
4272
+ if (!styleList.bd) {
4273
+ styleList.bd = {};
4274
+ }
4275
+ var arr = value.split(" ");
4276
+ var type = "".concat(arr[0], " ").concat(arr[1]);
4277
+ arr.splice(0, 2);
4278
+ var color = arr.join("");
4279
+ var obj = {
4280
+ cl: {
4281
+ rgb: color
4282
+ },
4283
+ s: (0, import_core30.getBorderStyleType)(type)
4284
+ };
4285
+ if (key === "border-bottom") {
4286
+ styleList.bd.b = value === "none" ? null : obj;
4287
+ } else if (key === "border-top") {
4288
+ styleList.bd.t = value === "none" ? null : obj;
4289
+ } else if (key === "border-left") {
4290
+ styleList.bd.l = value === "none" ? null : obj;
4291
+ } else if (key === "border-right") {
4292
+ styleList.bd.r = value === "none" ? null : obj;
4293
+ } else if (key === "border") {
4294
+ styleList.bd = {
4295
+ r: value === "none" ? null : obj,
4296
+ t: value === "none" ? null : obj,
4297
+ b: value === "none" ? null : obj,
4298
+ l: value === "none" ? null : obj
4299
+ };
4300
+ }
4301
+ }
4302
+ });
4303
+ return styleList;
4304
+ }
4305
+ function handleBorder(border, param) {
4306
+ var arr;
4307
+ if (param === " ") {
4308
+ arr = border.trim().split(param);
4309
+ } else {
4310
+ arr = border.trim().split(param).slice(0, -1);
4311
+ }
4312
+ arr.forEach(function(item) {
4313
+ return "".concat(item.trim(), ")");
4314
+ });
4315
+ var obj = {};
4316
+ if (arr.length === 1) {
4317
+ obj = {
4318
+ t: arr[0],
4319
+ r: arr[0],
4320
+ b: arr[0],
4321
+ l: arr[0]
4322
+ };
4323
+ } else if (arr.length === 2) {
4324
+ obj = {
4325
+ t: arr[0],
4326
+ r: arr[1],
4327
+ b: arr[0],
4328
+ l: arr[1]
4329
+ };
4330
+ } else if (arr.length === 3) {
4331
+ obj = {
4332
+ t: arr[0],
4333
+ r: arr[1],
4334
+ b: arr[2],
4335
+ l: arr[1]
4336
+ };
4337
+ } else if (arr.length === 4) {
4338
+ obj = {
4339
+ t: arr[0],
4340
+ r: arr[1],
4341
+ b: arr[2],
4342
+ l: arr[3]
4343
+ };
4344
+ }
4345
+ return obj;
4346
+ }
4347
+ function splitSpanText(text) {
4348
+ if (text === "") return [
4349
+ text
4350
+ ];
4351
+ var regex = /(?:(\n+.+)|(.+))/g;
4352
+ var arr = text.match(regex);
4353
+ var arr1 = arr.map(function(item) {
4354
+ return item.replace(/\n/g, "\r\n");
4355
+ });
4356
+ return arr1;
4357
+ }
4358
+ function handleTableColgroup(table) {
4359
+ var content = document.createElement("DIV");
4360
+ var data = [];
4361
+ content.innerHTML = table;
4362
+ var colgroup = content.querySelectorAll("table col");
4363
+ if (!colgroup.length) return [];
4364
+ for(var i = 0; i < colgroup.length; i++){
4365
+ var col = colgroup[i];
4366
+ var colSpan = col.getAttribute("span");
4367
+ if (colSpan && +colSpan > 1) {
4368
+ for(var j = 0; j < +colSpan; j++){
4369
+ var width = getTdHeight(col.getAttribute("width"), 72);
4370
+ data.push(width);
4371
+ }
4372
+ } else {
4373
+ var width1 = getTdHeight(col.getAttribute("width"), 72);
4374
+ data.push(width1);
4375
+ }
4376
+ }
4377
+ return data;
4378
+ }
4379
+ function getTdHeight(height, defaultHeight) {
4380
+ if (!height) return defaultHeight;
4381
+ var firstHeight;
4382
+ if (height.includes("pt")) {
4383
+ firstHeight = (0, import_engine_render2.ptToPx)(parseFloat(height));
4384
+ } else if (height.includes("px")) {
4385
+ firstHeight = parseFloat(height);
4386
+ } else {
4387
+ firstHeight = parseFloat(height) * 72 / 96;
4388
+ }
4389
+ return firstHeight;
4390
+ }
4391
+ function handleTableRowGroup(table) {
4392
+ var content = document.createElement("DIV");
4393
+ var data = [];
4394
+ content.innerHTML = table;
4395
+ var rowGroup = content.querySelectorAll("table tr");
4396
+ if (!rowGroup.length) return [];
4397
+ for(var i = 0; i < rowGroup.length; i++){
4398
+ var row = rowGroup[i];
4399
+ var tds = row.querySelectorAll("td");
4400
+ var firstHeight = getTdHeight(tds[0].style.height, 19);
4401
+ for(var k = 0; k < tds.length; k++){
4402
+ var rowSpan = tds[k].getAttribute("rowSpan");
4403
+ if (rowSpan && +rowSpan > 1) {
4404
+ continue;
4405
+ }
4406
+ firstHeight = getTdHeight(tds[k].style.height, 19);
4407
+ break;
4408
+ }
4409
+ data.push(firstHeight);
4410
+ }
4411
+ return data;
4412
+ }
4413
+ function handelTableToJson(table) {
4414
+ var data = [];
4415
+ var content = document.createElement("DIV");
4416
+ content.innerHTML = table;
4417
+ data = new Array(content.querySelectorAll("table tr").length);
4418
+ if (!data.length) return [];
4419
+ var colLen = 0;
4420
+ var trs = content.querySelectorAll("table tr");
4421
+ var firstTds = trs[0].querySelectorAll("td");
4422
+ firstTds.forEach(function(item) {
4423
+ var colSpan = 0;
4424
+ var attr = item.getAttribute("colSpan");
4425
+ if (attr !== null) {
4426
+ colSpan = +attr;
4427
+ } else {
4428
+ colSpan = 1;
4429
+ }
4430
+ colLen += colSpan;
4431
+ });
4432
+ for(var i = 0; i < data.length; i++){
4433
+ data[i] = new Array(colLen);
4434
+ }
4435
+ var r = 0;
4436
+ trs.forEach(function(item) {
4437
+ var c = 0;
4438
+ item.querySelectorAll("td").forEach(function(td) {
4439
+ var cell = {};
4440
+ if (td.querySelectorAll("span").length || td.querySelectorAll("font").length) {
4441
+ var spanStyle = handleDomToJson(td);
4442
+ if (typeof spanStyle !== "string") {
4443
+ cell.p = spanStyle;
4444
+ }
4445
+ }
4446
+ var txt = td.innerText;
4447
+ if (txt.trim().length === 0) {
4448
+ cell.v = "";
4449
+ cell.m = "";
4450
+ } else {
4451
+ cell.v = txt;
4452
+ cell.m = txt;
4453
+ }
4454
+ var style = handleStringToStyle(td);
4455
+ if (import_core30.Tools.isPlainObject(style)) {
4456
+ cell.s = style;
4457
+ }
4458
+ while(c < colLen && data[r][c] != null){
4459
+ c++;
4460
+ }
4461
+ if (c === colLen) {
4462
+ return;
4463
+ }
4464
+ if (data[r][c] == null) {
4465
+ data[r][c] = cell;
4466
+ var _Number;
4467
+ var rowSpan = (_Number = Number(td.getAttribute("rowSpan"))) !== null && _Number !== void 0 ? _Number : 1;
4468
+ var _Number1;
4469
+ var colSpan = (_Number1 = Number(td.getAttribute("colSpan"))) !== null && _Number1 !== void 0 ? _Number1 : 1;
4470
+ if (rowSpan > 1 || colSpan > 1) {
4471
+ var first = {
4472
+ rs: +rowSpan - 1,
4473
+ cs: +colSpan - 1,
4474
+ r: r,
4475
+ c: c
4476
+ };
4477
+ data[r][c].mc = first;
4478
+ for(var rp = 0; rp < rowSpan; rp++){
4479
+ for(var cp = 0; cp < colSpan; cp++){
4480
+ if (rp === 0 && cp === 0) {
4481
+ continue;
4482
+ }
4483
+ data[r + rp][c + cp] = {
4484
+ mc: null
4485
+ };
4486
+ }
4487
+ }
4488
+ }
4489
+ }
4490
+ c++;
4491
+ });
4492
+ r++;
4493
+ });
4494
+ return data;
4495
+ }
4496
+ function handlePlainToJson(plain) {
4497
+ var data = [];
4498
+ var content = document.createElement("DIV");
4499
+ content.innerHTML = plain;
4500
+ var dataChe = plain.replace(/\r/g, "");
4501
+ var che = dataChe.split("\n");
4502
+ var colCheLen = che[0].split(" ").length;
4503
+ for(var i = 0; i < che.length; i++){
4504
+ if (che[i].split(" ").length < colCheLen) {
4505
+ continue;
4506
+ }
4507
+ data.push(che[i].split(" "));
4508
+ }
4509
+ for(var i1 = 0; i1 < data.length; i1++){
4510
+ for(var j = 0; j < data[i1].length; j++){
4511
+ if (data[i1][j].length) {
4512
+ data[i1][j] = {
4513
+ v: data[i1][j] || "",
4514
+ m: data[i1][j] || ""
4515
+ };
4516
+ } else {
4517
+ data[i1][j] = null;
4518
+ }
4519
+ }
4520
+ }
4521
+ return data;
4522
+ }
4523
+ function handleTableMergeData(data, selection) {
4524
+ var copyH = data.length;
4525
+ var copyC = data[0].length;
4526
+ var minH = 0;
4527
+ var maxH = minH + copyH - 1;
4528
+ var minC = 0;
4529
+ var maxC = minC + copyC - 1;
4530
+ if (selection) {
4531
+ minH = selection.startRow;
4532
+ maxH = minH + copyH - 1;
4533
+ minC = selection.startColumn;
4534
+ maxC = minC + copyC - 1;
4535
+ }
4536
+ var mergeData = [];
4537
+ for(var i = 0; i < data.length; i++){
4538
+ for(var j = 0; j < data[i].length; j++){
4539
+ if (data[i][j] && typeof data[i][j] === "object" && "mc" in data[i][j]) {
4540
+ if (data[i][j].mc) {
4541
+ var mc = data[i][j].mc;
4542
+ var startRow = mc.r + minH;
4543
+ var endRow = startRow + mc.rs;
4544
+ var startColumn = mc.c + minC;
4545
+ var endColumn = startColumn + mc.cs;
4546
+ mergeData.push({
4547
+ startRow: startRow,
4548
+ endRow: endRow,
4549
+ startColumn: startColumn,
4550
+ endColumn: endColumn
4551
+ });
4552
+ delete data[i][j].mc;
4553
+ } else {
4554
+ data[i][j] = null;
4555
+ }
4556
+ }
4557
+ }
4558
+ }
4559
+ return {
4560
+ data: data,
4561
+ mergeData: mergeData
4562
+ };
4563
+ }
4564
+ function handelExcelToJson(html) {
4565
+ var _content_querySelector;
4566
+ var data = [];
4567
+ var content = document.createElement("html");
4568
+ content.innerHTML = html;
4569
+ var styleText = (_content_querySelector = content.querySelector("style")) === null || _content_querySelector === void 0 ? void 0 : _content_querySelector.innerText;
4570
+ if (!styleText) return;
4571
+ var excelStyle = getStyles(styleText);
4572
+ data = new Array(content.querySelectorAll("table tr").length);
4573
+ if (!data.length) return [];
4574
+ var colLen = 0;
4575
+ var trs = content.querySelectorAll("table tr");
4576
+ var firstTds = trs[0].querySelectorAll("td");
4577
+ firstTds.forEach(function(item) {
4578
+ var colSpan = 0;
4579
+ var attr = item.getAttribute("colSpan");
4580
+ if (attr !== null) {
4581
+ colSpan = +attr;
4582
+ } else {
4583
+ colSpan = 1;
4584
+ }
4585
+ colLen += colSpan;
4586
+ });
4587
+ for(var i = 0; i < data.length; i++){
4588
+ data[i] = new Array(colLen);
4589
+ }
4590
+ var r = 0;
4591
+ trs.forEach(function(item) {
4592
+ var c = 0;
4593
+ item.querySelectorAll("td").forEach(function(td) {
4594
+ var cell = {};
4595
+ if (td.querySelectorAll("span").length || td.querySelectorAll("font").length) {
4596
+ var spanStyle = handleDomToJson(td);
4597
+ if (typeof spanStyle !== "string") {
4598
+ cell.p = spanStyle;
4599
+ }
4600
+ }
4601
+ var txt = td.innerText;
4602
+ if (txt.trim().length === 0) {
4603
+ cell.v = "";
4604
+ cell.m = "";
4605
+ } else {
4606
+ cell.v = txt;
4607
+ cell.m = txt;
4608
+ }
4609
+ var cssText = "";
4610
+ for(var attr in excelStyle){
4611
+ if (td.classList.contains(attr)) {
4612
+ cssText += excelStyle[attr];
4613
+ }
4614
+ }
4615
+ var style = handleStringToStyle(td, cssText);
4616
+ if (import_core30.Tools.isPlainObject(style)) {
4617
+ cell.s = style;
4618
+ }
4619
+ while(c < colLen && data[r][c] != null){
4620
+ c++;
4621
+ }
4622
+ if (c === colLen) {
4623
+ return;
4624
+ }
4625
+ if (data[r][c] == null) {
4626
+ data[r][c] = cell;
4627
+ var _Number;
4628
+ var rowSpan = (_Number = Number(td.getAttribute("rowSpan"))) !== null && _Number !== void 0 ? _Number : 1;
4629
+ var _Number1;
4630
+ var colSpan = (_Number1 = Number(td.getAttribute("colSpan"))) !== null && _Number1 !== void 0 ? _Number1 : 1;
4631
+ if (rowSpan > 1 || colSpan > 1) {
4632
+ var first = {
4633
+ rs: +rowSpan - 1,
4634
+ cs: +colSpan - 1,
4635
+ r: r,
4636
+ c: c
4637
+ };
4638
+ data[r][c].mc = first;
4639
+ for(var rp = 0; rp < rowSpan; rp++){
4640
+ for(var cp = 0; cp < colSpan; cp++){
4641
+ if (rp === 0 && cp === 0) {
4642
+ continue;
4643
+ }
4644
+ data[r + rp][c + cp] = {
4645
+ mc: null
4646
+ };
4647
+ }
4648
+ }
4649
+ }
4650
+ }
4651
+ c++;
4652
+ });
4653
+ r++;
4654
+ });
4655
+ return data;
4656
+ }
4657
+ function getStyles(styleText) {
4658
+ var output = {};
4659
+ var string = styleText.replaceAll("<!--", "").replaceAll("-->", "").trim();
4660
+ var style = string === null || string === void 0 ? void 0 : string.replaceAll(" ", "").replaceAll("\n", "").split("}");
4661
+ for(var i = 0; i < style.length; i++){
4662
+ if (!style[i]) continue;
4663
+ var attr = style[i].split("{")[0].trim();
4664
+ if (attr.includes(".")) {
4665
+ attr = attr.slice(1);
4666
+ }
4667
+ var value = style[i].split("{")[1].trim();
4668
+ output[attr] = value;
4669
+ }
4670
+ return output;
4671
+ }