@univerjs/docs-ui 0.1.0-beta.4 → 0.1.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -1,13 +1,14 @@
1
- var K = Object.defineProperty;
2
- var G = (e, n, t) => n in e ? K(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var h = (e, n, t) => (G(e, typeof n != "symbol" ? n + "" : n, t), t);
4
- import { LocaleService as U, ICommandService as O, BooleanNumber as M, UniverInstanceType as a, BaselineOffset as j, ThemeService as V, IUniverInstanceService as w, Disposable as X, OnLifecycle as q, LifecycleStages as J, Plugin as Q, Tools as k, PluginType as ee, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as te, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as ne, ILogService as oe } from "@univerjs/core";
5
- import { Inject as f, Injector as F } from "@wendellhu/redi";
6
- import { MenuGroup as d, MenuItemType as u, MenuPosition as _, getMenuHiddenObservable as p, FONT_FAMILY_LIST as E, FONT_SIZE_LIST as ie, FontFamily as re, FontFamilyItem as se, FontSize as ce, ComponentManager as le, IShortcutService as ae, IMenuService as de, IUIController as ue } from "@univerjs/ui";
7
- import { SetInlineFormatBoldCommand as _e, SetTextSelectionsOperation as C, SetInlineFormatCommand as v, SetInlineFormatItalicCommand as pe, SetInlineFormatUnderlineCommand as Oe, SetInlineFormatStrikethroughCommand as me, SetInlineFormatSubscriptCommand as Te, SetInlineFormatSuperscriptCommand as fe, SetInlineFormatFontFamilyCommand as B, SetInlineFormatFontSizeCommand as N, SetInlineFormatTextColorCommand as P, OrderListCommand as Ce, BulletListCommand as Se, TextSelectionManagerService as he } from "@univerjs/docs";
8
- import { Observable as T } from "rxjs";
9
- import { ColorPicker as ge } from "@univerjs/design";
10
- const ve = {
1
+ var Le = Object.defineProperty;
2
+ var Ne = (e, t, n) => t in e ? Le(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var h = (e, t, n) => (Ne(e, typeof t != "symbol" ? t + "" : t, n), n);
4
+ import { FOCUSING_DOC as m, Direction as b, EDITOR_ACTIVATED as ge, LocaleService as ee, RxDisposable as Ce, ICommandService as _, BooleanNumber as u, UniverInstanceType as S, BaselineOffset as E, ThemeService as Ue, IUniverInstanceService as te, OnLifecycle as Se, LifecycleStages as Oe, Disposable as Te, Tools as ve, LRUMap as Fe, ColorKit as se, ILogService as Re, toDisposable as $e, CommandType as ne, IContextService as we, Plugin as Be, PluginType as je, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as He, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Ve } from "@univerjs/core";
5
+ import { Inject as y, Injector as Y, Optional as We, createIdentifier as ze } from "@wendellhu/redi";
6
+ import { KeyCode as g, MetaKeys as w, LayoutService as Ye, MenuGroup as O, MenuItemType as T, MenuPosition as v, getMenuHiddenObservable as R, FONT_FAMILY_LIST as ae, FONT_SIZE_LIST as ke, ComponentManager as Ge, FontFamily as Ke, FontFamilyItem as Ze, FontSize as Xe, IShortcutService as ye, IMenuService as qe, IUIController as Je, IClipboardInterfaceService as oe, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as Qe, HTML_CLIPBOARD_MIME_TYPE as et, CopyCommand as tt, CutCommand as nt, PasteCommand as ot } from "@univerjs/ui";
7
+ import { MoveCursorOperation as k, MoveSelectionOperation as G, SelectAllOperation as rt, SetInlineFormatBoldCommand as it, SetTextSelectionsOperation as x, SetInlineFormatCommand as A, SetInlineFormatItalicCommand as st, SetInlineFormatUnderlineCommand as at, SetInlineFormatStrikethroughCommand as ct, SetInlineFormatSubscriptCommand as lt, SetInlineFormatSuperscriptCommand as dt, SetInlineFormatFontFamilyCommand as ce, SetInlineFormatFontSizeCommand as le, SetInlineFormatTextColorCommand as de, OrderListCommand as ut, BulletListCommand as pt, TextSelectionManagerService as Ie, BreakLineCommand as ht, DeleteLeftCommand as ft, DeleteRightCommand as mt, CutContentCommand as be, InnerPasteCommand as xe } from "@univerjs/docs";
8
+ import { ITextSelectionRenderManager as De } from "@univerjs/engine-render";
9
+ import { ColorPicker as _t } from "@univerjs/design";
10
+ import { Observable as I, takeUntil as gt } from "rxjs";
11
+ const Ct = {
11
12
  undo: !0,
12
13
  redo: !0,
13
14
  // Undo redo
@@ -35,7 +36,7 @@ const ve = {
35
36
  // 'Wrap mode'
36
37
  textRotateMode: !0
37
38
  // 'Text Rotation Mode'
38
- }, Re = {
39
+ }, St = {
39
40
  outerLeft: !1,
40
41
  outerRight: !1,
41
42
  header: !0,
@@ -48,19 +49,79 @@ const ve = {
48
49
  frozenContent: !1,
49
50
  infoBar: !0,
50
51
  toolbar: !0
51
- }, Ie = {
52
+ }, Ot = {
52
53
  layout: {
53
- docContainerConfig: Re,
54
- toolbarConfig: ve
55
- }
56
- }, Me = "DocUI";
57
- var Fe = Object.defineProperty, Ae = Object.getOwnPropertyDescriptor, Le = (e, n, t, i) => {
58
- for (var o = i > 1 ? void 0 : i ? Ae(n, t) : n, s = e.length - 1, r; s >= 0; s--)
59
- (r = e[s]) && (o = (i ? r(n, t, o) : r(o)) || o);
60
- return i && o && Fe(n, t, o), o;
61
- }, b = (e, n) => (t, i) => n(t, i, e);
62
- let D = class {
63
- constructor(e, n, t) {
54
+ docContainerConfig: St,
55
+ toolbarConfig: Ct
56
+ }
57
+ }, Tt = "DocUI", vt = {
58
+ id: k.id,
59
+ binding: g.ARROW_UP,
60
+ preconditions: (e) => e.getContextValue(m),
61
+ staticParameters: {
62
+ direction: b.UP
63
+ }
64
+ }, Rt = {
65
+ id: k.id,
66
+ binding: g.ARROW_DOWN,
67
+ preconditions: (e) => e.getContextValue(m),
68
+ staticParameters: {
69
+ direction: b.DOWN
70
+ }
71
+ }, yt = {
72
+ id: k.id,
73
+ binding: g.ARROW_LEFT,
74
+ preconditions: (e) => e.getContextValue(m),
75
+ staticParameters: {
76
+ direction: b.LEFT
77
+ }
78
+ }, It = {
79
+ id: k.id,
80
+ binding: g.ARROW_RIGHT,
81
+ preconditions: (e) => e.getContextValue(m),
82
+ staticParameters: {
83
+ direction: b.RIGHT
84
+ }
85
+ }, bt = {
86
+ id: G.id,
87
+ binding: g.ARROW_UP | w.SHIFT,
88
+ preconditions: (e) => e.getContextValue(m),
89
+ staticParameters: {
90
+ direction: b.UP
91
+ }
92
+ }, xt = {
93
+ id: G.id,
94
+ binding: g.ARROW_DOWN | w.SHIFT,
95
+ preconditions: (e) => e.getContextValue(m),
96
+ staticParameters: {
97
+ direction: b.DOWN
98
+ }
99
+ }, Dt = {
100
+ id: G.id,
101
+ binding: g.ARROW_LEFT | w.SHIFT,
102
+ preconditions: (e) => e.getContextValue(m),
103
+ staticParameters: {
104
+ direction: b.LEFT
105
+ }
106
+ }, Pt = {
107
+ id: G.id,
108
+ binding: g.ARROW_RIGHT | w.SHIFT,
109
+ preconditions: (e) => e.getContextValue(m),
110
+ staticParameters: {
111
+ direction: b.RIGHT
112
+ }
113
+ }, Mt = {
114
+ id: rt.id,
115
+ binding: g.A | w.CTRL_COMMAND,
116
+ preconditions: (e) => e.getContextValue(m) || e.getContextValue(ge)
117
+ };
118
+ var Et = Object.defineProperty, At = Object.getOwnPropertyDescriptor, Lt = (e, t, n, o) => {
119
+ for (var r = o > 1 ? void 0 : o ? At(t, n) : t, i = e.length - 1, s; i >= 0; i--)
120
+ (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
121
+ return o && r && Et(t, n, r), r;
122
+ }, ue = (e, t) => (n, o) => t(n, o, e);
123
+ let J = class {
124
+ constructor(e, t, n) {
64
125
  h(this, "_docContainer");
65
126
  // 获取SheetContainer组件
66
127
  h(this, "getComponent", (e) => {
@@ -69,7 +130,7 @@ let D = class {
69
130
  });
70
131
  /**
71
132
  * Change language
72
- * @param {String} lang new language
133
+ * @param {string} lang new language
73
134
  *
74
135
  * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
75
136
  *
@@ -77,7 +138,7 @@ let D = class {
77
138
  h(this, "changeLocale", (e) => {
78
139
  this._localeService.setLocale(e);
79
140
  });
80
- this._config = e, this._localeService = n, this._injector = t;
141
+ this._config = e, this._localeService = t, this._injector = n;
81
142
  }
82
143
  getUIConfig() {
83
144
  return {
@@ -98,357 +159,366 @@ let D = class {
98
159
  return this._docContainer;
99
160
  }
100
161
  };
101
- D = Le([
102
- b(1, f(U)),
103
- b(2, f(F))
104
- ], D);
105
- var xe = Object.defineProperty, De = Object.getOwnPropertyDescriptor, Ue = (e, n, t, i) => {
106
- for (var o = i > 1 ? void 0 : i ? De(n, t) : n, s = e.length - 1, r; s >= 0; s--)
107
- (r = e[s]) && (o = (i ? r(n, t, o) : r(o)) || o);
108
- return i && o && xe(n, t, o), o;
109
- }, y = (e, n) => (t, i) => n(t, i, e);
110
- let R = class {
111
- constructor(e, n, t) {
162
+ J = Lt([
163
+ ue(1, y(ee)),
164
+ ue(2, y(Y))
165
+ ], J);
166
+ var Nt = Object.defineProperty, Ut = Object.getOwnPropertyDescriptor, Ft = (e, t, n, o) => {
167
+ for (var r = o > 1 ? void 0 : o ? Ut(t, n) : t, i = e.length - 1, s; i >= 0; i--)
168
+ (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
169
+ return o && r && Nt(t, n, r), r;
170
+ }, H = (e, t) => (n, o) => t(n, o, e);
171
+ let F = class extends Ce {
172
+ constructor(t, n, o, r, i) {
173
+ super();
112
174
  h(this, "_docContainerController");
113
175
  /**
114
176
  * Change language
115
- * @param {String} locale new language
177
+ * @param {string} locale new language
116
178
  *
117
179
  * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
118
180
  *
119
181
  */
120
- h(this, "changeLocale", (e) => {
121
- this._localeService.setLocale(e);
182
+ h(this, "changeLocale", (t) => {
183
+ this._localeService.setLocale(t);
122
184
  });
123
- this._localeService = n, this._injector = t, this._docContainerController = this._injector.createInstance(D, e);
185
+ this._localeService = n, this._injector = o, this._textSelectionRenderManager = r, this._layoutService = i, this._docContainerController = this._injector.createInstance(J, t), this._registerContainer();
186
+ }
187
+ _registerContainer() {
188
+ this._layoutService && this.disposeWithMe(
189
+ // the content editable div should be regarded as part of the applications container
190
+ this._layoutService.registerContainer(this._textSelectionRenderManager.__getEditorContainer())
191
+ );
124
192
  }
125
193
  getDocContainerController() {
126
194
  return this._docContainerController;
127
195
  }
128
196
  };
129
- R = Ue([
130
- y(1, f(U)),
131
- y(2, f(F))
132
- ], R);
133
- const A = "UI_PLUGIN_DOCS", z = `${A}_COLOR_PICKER_COMPONENT`, Y = `${A}_FONT_FAMILY_COMPONENT`, W = `${A}_FONT_FAMILY_ITEM_COMPONENT`, Z = `${A}_FONT_SIZE_COMPONENT`;
134
- function Ee(e) {
135
- const n = e.get(O);
197
+ F = Ft([
198
+ H(1, y(ee)),
199
+ H(2, y(Y)),
200
+ H(3, De),
201
+ H(4, We(Ye))
202
+ ], F);
203
+ const K = "UI_PLUGIN_DOCS", Pe = `${K}_COLOR_PICKER_COMPONENT`, Me = `${K}_FONT_FAMILY_COMPONENT`, Ee = `${K}_FONT_FAMILY_ITEM_COMPONENT`, Ae = `${K}_FONT_SIZE_COMPONENT`;
204
+ function $t(e) {
205
+ const t = e.get(_);
136
206
  return {
137
- id: _e.id,
138
- group: d.TOOLBAR_FORMAT,
139
- type: u.BUTTON,
207
+ id: it.id,
208
+ group: O.TOOLBAR_FORMAT,
209
+ type: T.BUTTON,
140
210
  icon: "BoldSingle",
141
211
  title: "Set bold",
142
212
  tooltip: "toolbar.bold",
143
- positions: [_.TOOLBAR_START],
144
- activated$: new T((t) => {
145
- const i = n.onCommandExecuted((o) => {
146
- var r;
147
- const s = o.id;
148
- if (s === C.id || s === v.id) {
149
- const c = S(e);
150
- if (c == null)
213
+ positions: [v.TOOLBAR_START],
214
+ activated$: new I((n) => {
215
+ const o = t.onCommandExecuted((r) => {
216
+ var s;
217
+ const i = r.id;
218
+ if (i === x.id || i === A.id) {
219
+ const a = D(e);
220
+ if (a == null)
151
221
  return;
152
- const l = (r = c.ts) == null ? void 0 : r.bl;
153
- t.next(l === M.TRUE);
222
+ const c = (s = a.ts) == null ? void 0 : s.bl;
223
+ n.next(c === u.TRUE);
154
224
  }
155
225
  });
156
- return t.next(!1), i.dispose;
226
+ return n.next(!1), o.dispose;
157
227
  }),
158
- hidden$: p(e, a.DOC)
228
+ hidden$: R(e, S.DOC)
159
229
  };
160
230
  }
161
- function Be(e) {
162
- const n = e.get(O);
231
+ function wt(e) {
232
+ const t = e.get(_);
163
233
  return {
164
- id: pe.id,
165
- group: d.TOOLBAR_FORMAT,
166
- type: u.BUTTON,
234
+ id: st.id,
235
+ group: O.TOOLBAR_FORMAT,
236
+ type: T.BUTTON,
167
237
  icon: "ItalicSingle",
168
238
  title: "Set italic",
169
239
  tooltip: "toolbar.italic",
170
- positions: [_.TOOLBAR_START],
171
- activated$: new T((t) => {
172
- const i = n.onCommandExecuted((o) => {
173
- var r;
174
- const s = o.id;
175
- if (s === C.id || s === v.id) {
176
- const c = S(e);
177
- if (c == null)
240
+ positions: [v.TOOLBAR_START],
241
+ activated$: new I((n) => {
242
+ const o = t.onCommandExecuted((r) => {
243
+ var s;
244
+ const i = r.id;
245
+ if (i === x.id || i === A.id) {
246
+ const a = D(e);
247
+ if (a == null)
178
248
  return;
179
- const l = (r = c.ts) == null ? void 0 : r.it;
180
- t.next(l === M.TRUE);
249
+ const c = (s = a.ts) == null ? void 0 : s.it;
250
+ n.next(c === u.TRUE);
181
251
  }
182
252
  });
183
- return t.next(!1), i.dispose;
253
+ return n.next(!1), o.dispose;
184
254
  }),
185
- hidden$: p(e, a.DOC)
255
+ hidden$: R(e, S.DOC)
186
256
  };
187
257
  }
188
- function Ne(e) {
189
- const n = e.get(O);
258
+ function Bt(e) {
259
+ const t = e.get(_);
190
260
  return {
191
- id: Oe.id,
192
- group: d.TOOLBAR_FORMAT,
193
- type: u.BUTTON,
261
+ id: at.id,
262
+ group: O.TOOLBAR_FORMAT,
263
+ type: T.BUTTON,
194
264
  icon: "UnderlineSingle",
195
265
  title: "Set underline",
196
266
  tooltip: "toolbar.underline",
197
- positions: [_.TOOLBAR_START],
198
- activated$: new T((t) => {
199
- const i = n.onCommandExecuted((o) => {
200
- var r;
201
- const s = o.id;
202
- if (s === C.id || s === v.id) {
203
- const c = S(e);
204
- if (c == null)
267
+ positions: [v.TOOLBAR_START],
268
+ activated$: new I((n) => {
269
+ const o = t.onCommandExecuted((r) => {
270
+ var s;
271
+ const i = r.id;
272
+ if (i === x.id || i === A.id) {
273
+ const a = D(e);
274
+ if (a == null)
205
275
  return;
206
- const l = (r = c.ts) == null ? void 0 : r.ul;
207
- t.next((l == null ? void 0 : l.s) === M.TRUE);
276
+ const c = (s = a.ts) == null ? void 0 : s.ul;
277
+ n.next((c == null ? void 0 : c.s) === u.TRUE);
208
278
  }
209
279
  });
210
- return t.next(!1), i.dispose;
280
+ return n.next(!1), o.dispose;
211
281
  }),
212
- hidden$: p(e, a.DOC)
282
+ hidden$: R(e, S.DOC)
213
283
  };
214
284
  }
215
- function Pe(e) {
216
- const n = e.get(O);
285
+ function jt(e) {
286
+ const t = e.get(_);
217
287
  return {
218
- id: me.id,
219
- group: d.TOOLBAR_FORMAT,
220
- type: u.BUTTON,
288
+ id: ct.id,
289
+ group: O.TOOLBAR_FORMAT,
290
+ type: T.BUTTON,
221
291
  icon: "StrikethroughSingle",
222
292
  title: "Set strike through",
223
293
  tooltip: "toolbar.strikethrough",
224
- positions: [_.TOOLBAR_START],
225
- activated$: new T((t) => {
226
- const i = n.onCommandExecuted((o) => {
227
- var r;
228
- const s = o.id;
229
- if (s === C.id || s === v.id) {
230
- const c = S(e);
231
- if (c == null)
294
+ positions: [v.TOOLBAR_START],
295
+ activated$: new I((n) => {
296
+ const o = t.onCommandExecuted((r) => {
297
+ var s;
298
+ const i = r.id;
299
+ if (i === x.id || i === A.id) {
300
+ const a = D(e);
301
+ if (a == null)
232
302
  return;
233
- const l = (r = c.ts) == null ? void 0 : r.st;
234
- t.next((l == null ? void 0 : l.s) === M.TRUE);
303
+ const c = (s = a.ts) == null ? void 0 : s.st;
304
+ n.next((c == null ? void 0 : c.s) === u.TRUE);
235
305
  }
236
306
  });
237
- return t.next(!1), i.dispose;
307
+ return n.next(!1), o.dispose;
238
308
  }),
239
- hidden$: p(e, a.DOC)
309
+ hidden$: R(e, S.DOC)
240
310
  };
241
311
  }
242
- function be(e) {
243
- const n = e.get(O);
312
+ function Ht(e) {
313
+ const t = e.get(_);
244
314
  return {
245
- id: Te.id,
246
- group: d.TOOLBAR_FORMAT,
247
- type: u.BUTTON,
315
+ id: lt.id,
316
+ group: O.TOOLBAR_FORMAT,
317
+ type: T.BUTTON,
248
318
  icon: "SubscriptSingle",
249
319
  tooltip: "toolbar.subscript",
250
- positions: [_.TOOLBAR_START],
251
- activated$: new T((t) => {
252
- const i = n.onCommandExecuted((o) => {
253
- var r;
254
- const s = o.id;
255
- if (s === C.id || s === v.id) {
256
- const c = S(e);
257
- if (c == null)
320
+ positions: [v.TOOLBAR_START],
321
+ activated$: new I((n) => {
322
+ const o = t.onCommandExecuted((r) => {
323
+ var s;
324
+ const i = r.id;
325
+ if (i === x.id || i === A.id) {
326
+ const a = D(e);
327
+ if (a == null)
258
328
  return;
259
- const l = (r = c.ts) == null ? void 0 : r.va;
260
- t.next(l === j.SUBSCRIPT);
329
+ const c = (s = a.ts) == null ? void 0 : s.va;
330
+ n.next(c === E.SUBSCRIPT);
261
331
  }
262
332
  });
263
- return t.next(!1), i.dispose;
333
+ return n.next(!1), o.dispose;
264
334
  }),
265
- hidden$: p(e, a.DOC)
335
+ hidden$: R(e, S.DOC)
266
336
  };
267
337
  }
268
- function ye(e) {
269
- const n = e.get(O);
338
+ function Vt(e) {
339
+ const t = e.get(_);
270
340
  return {
271
- id: fe.id,
272
- group: d.TOOLBAR_FORMAT,
273
- type: u.BUTTON,
341
+ id: dt.id,
342
+ group: O.TOOLBAR_FORMAT,
343
+ type: T.BUTTON,
274
344
  icon: "SuperscriptSingle",
275
345
  tooltip: "toolbar.superscript",
276
- positions: [_.TOOLBAR_START],
277
- activated$: new T((t) => {
278
- const i = n.onCommandExecuted((o) => {
279
- var r;
280
- const s = o.id;
281
- if (s === C.id || s === v.id) {
282
- const c = S(e);
283
- if (c == null)
346
+ positions: [v.TOOLBAR_START],
347
+ activated$: new I((n) => {
348
+ const o = t.onCommandExecuted((r) => {
349
+ var s;
350
+ const i = r.id;
351
+ if (i === x.id || i === A.id) {
352
+ const a = D(e);
353
+ if (a == null)
284
354
  return;
285
- const l = (r = c.ts) == null ? void 0 : r.va;
286
- t.next(l === j.SUPERSCRIPT);
355
+ const c = (s = a.ts) == null ? void 0 : s.va;
356
+ n.next(c === E.SUPERSCRIPT);
287
357
  }
288
358
  });
289
- return t.next(!1), i.dispose;
359
+ return n.next(!1), o.dispose;
290
360
  }),
291
- hidden$: p(e, a.DOC)
361
+ hidden$: R(e, S.DOC)
292
362
  };
293
363
  }
294
- function $e(e) {
295
- const n = e.get(O);
364
+ function Wt(e) {
365
+ const t = e.get(_);
296
366
  return {
297
- id: B.id,
367
+ id: ce.id,
298
368
  tooltip: "toolbar.font",
299
- group: d.TOOLBAR_FORMAT,
300
- type: u.SELECTOR,
301
- label: Y,
302
- positions: [_.TOOLBAR_START],
303
- selections: E.map((t) => ({
369
+ group: O.TOOLBAR_FORMAT,
370
+ type: T.SELECTOR,
371
+ label: Me,
372
+ positions: [v.TOOLBAR_START],
373
+ selections: ae.map((n) => ({
304
374
  label: {
305
- name: W,
375
+ name: Ee,
306
376
  hoverable: !0
307
377
  },
308
- value: t.value
378
+ value: n.value
309
379
  })),
310
380
  // disabled$: getCurrentSheetDisabled$(accessor),
311
- value$: new T((t) => {
312
- const i = E[0].value, o = n.onCommandExecuted((s) => {
313
- var c;
314
- const r = s.id;
315
- if (r === C.id || r === B.id) {
316
- const l = S(e);
317
- if (l == null)
381
+ value$: new I((n) => {
382
+ const o = ae[0].value, r = t.onCommandExecuted((i) => {
383
+ var a;
384
+ const s = i.id;
385
+ if (s === x.id || s === ce.id) {
386
+ const c = D(e);
387
+ if (c == null)
318
388
  return;
319
- const m = (c = l.ts) == null ? void 0 : c.ff;
320
- t.next(m != null ? m : i);
389
+ const l = (a = c.ts) == null ? void 0 : a.ff;
390
+ n.next(l != null ? l : o);
321
391
  }
322
392
  });
323
- return t.next(i), o.dispose;
393
+ return n.next(o), r.dispose;
324
394
  }),
325
- hidden$: p(e, a.DOC)
395
+ hidden$: R(e, S.DOC)
326
396
  };
327
397
  }
328
- function je(e) {
329
- const n = e.get(O);
398
+ function zt(e) {
399
+ const t = e.get(_);
330
400
  return {
331
- id: N.id,
332
- group: d.TOOLBAR_FORMAT,
333
- type: u.SELECTOR,
401
+ id: le.id,
402
+ group: O.TOOLBAR_FORMAT,
403
+ type: T.SELECTOR,
334
404
  tooltip: "toolbar.fontSize",
335
405
  label: {
336
- name: Z,
406
+ name: Ae,
337
407
  props: {
338
408
  min: 1,
339
409
  max: 400
340
410
  // disabled$,
341
411
  }
342
412
  },
343
- positions: [_.TOOLBAR_START],
344
- selections: ie,
413
+ positions: [v.TOOLBAR_START],
414
+ selections: ke,
345
415
  // disabled$,
346
- value$: new T((t) => {
347
- const o = n.onCommandExecuted((s) => {
348
- var c;
349
- const r = s.id;
350
- if (r === C.id || r === N.id) {
351
- const l = S(e);
352
- if (l == null)
416
+ value$: new I((n) => {
417
+ const r = t.onCommandExecuted((i) => {
418
+ var a;
419
+ const s = i.id;
420
+ if (s === x.id || s === le.id) {
421
+ const c = D(e);
422
+ if (c == null)
353
423
  return;
354
- const m = (c = l.ts) == null ? void 0 : c.fs;
355
- t.next(m != null ? m : 14);
424
+ const l = (a = c.ts) == null ? void 0 : a.fs;
425
+ n.next(l != null ? l : 14);
356
426
  }
357
427
  });
358
- return t.next(14), o.dispose;
428
+ return n.next(14), r.dispose;
359
429
  }),
360
- hidden$: p(e, a.DOC)
430
+ hidden$: R(e, S.DOC)
361
431
  };
362
432
  }
363
- function we(e) {
364
- const n = e.get(O), t = e.get(V);
433
+ function Yt(e) {
434
+ const t = e.get(_), n = e.get(Ue);
365
435
  return {
366
- id: P.id,
436
+ id: de.id,
367
437
  icon: "FontColor",
368
438
  tooltip: "toolbar.textColor.main",
369
- group: d.TOOLBAR_FORMAT,
370
- type: u.BUTTON_SELECTOR,
371
- positions: [_.TOOLBAR_START],
439
+ group: O.TOOLBAR_FORMAT,
440
+ type: T.BUTTON_SELECTOR,
441
+ positions: [v.TOOLBAR_START],
372
442
  selections: [
373
443
  {
374
444
  label: {
375
- name: z,
445
+ name: Pe,
376
446
  hoverable: !1
377
447
  }
378
448
  }
379
449
  ],
380
- value$: new T((i) => {
381
- const o = t.getCurrentTheme().textColor, s = n.onCommandExecuted((r) => {
382
- if (r.id === P.id) {
383
- const c = r.params.value;
384
- i.next(c != null ? c : o);
450
+ value$: new I((o) => {
451
+ const r = n.getCurrentTheme().textColor, i = t.onCommandExecuted((s) => {
452
+ if (s.id === de.id) {
453
+ const a = s.params.value;
454
+ o.next(a != null ? a : r);
385
455
  }
386
456
  });
387
- return i.next(o), s.dispose;
457
+ return o.next(r), i.dispose;
388
458
  }),
389
- hidden$: p(e, a.DOC)
459
+ hidden$: R(e, S.DOC)
390
460
  // disabled$: getCurrentSheetDisabled$(accessor),
391
461
  };
392
462
  }
393
- function ze(e) {
463
+ function kt(e) {
394
464
  return {
395
- id: Ce.id,
396
- group: d.TOOLBAR_LAYOUT,
397
- type: u.BUTTON,
465
+ id: ut.id,
466
+ group: O.TOOLBAR_LAYOUT,
467
+ type: T.BUTTON,
398
468
  icon: "OrderSingle",
399
469
  tooltip: "toolbar.order",
400
- positions: [_.TOOLBAR_START],
401
- hidden$: p(e, a.DOC)
470
+ positions: [v.TOOLBAR_START],
471
+ hidden$: R(e, S.DOC)
402
472
  };
403
473
  }
404
- function Ye(e) {
474
+ function Gt(e) {
405
475
  return {
406
- id: Se.id,
407
- group: d.TOOLBAR_LAYOUT,
408
- type: u.BUTTON,
476
+ id: pt.id,
477
+ group: O.TOOLBAR_LAYOUT,
478
+ type: T.BUTTON,
409
479
  icon: "UnorderSingle",
410
480
  tooltip: "toolbar.unorder",
411
- positions: [_.TOOLBAR_START],
412
- hidden$: p(e, a.DOC)
481
+ positions: [v.TOOLBAR_START],
482
+ hidden$: R(e, S.DOC)
413
483
  };
414
484
  }
415
- function S(e) {
416
- var l;
417
- const n = e.get(w), t = e.get(he), i = n.getCurrentUniverDocInstance(), o = t.getActiveRange();
418
- if (i == null || o == null)
485
+ function D(e) {
486
+ var c;
487
+ const t = e.get(te), n = e.get(Ie), o = t.getCurrentUniverDocInstance(), r = n.getActiveRange();
488
+ if (o == null || r == null)
419
489
  return;
420
- const s = (l = i.getBody()) == null ? void 0 : l.textRuns;
421
- if (s == null)
490
+ const i = (c = o.getBody()) == null ? void 0 : c.textRuns;
491
+ if (i == null)
422
492
  return;
423
- const { startOffset: r } = o;
424
- return s.find(({ st: m, ed: H }) => r >= m && r < H);
493
+ const { startOffset: s } = r;
494
+ return i.find(({ st: l, ed: p }) => s >= l && s < p);
425
495
  }
426
- var We = Object.defineProperty, Ze = Object.getOwnPropertyDescriptor, He = (e, n, t, i) => {
427
- for (var o = i > 1 ? void 0 : i ? Ze(n, t) : n, s = e.length - 1, r; s >= 0; s--)
428
- (r = e[s]) && (o = (i ? r(n, t, o) : r(o)) || o);
429
- return i && o && We(n, t, o), o;
430
- }, g = (e, n) => (t, i) => n(t, i, e);
431
- let I = class extends X {
432
- constructor(e, n, t, i, o, s) {
433
- super(), this._injector = e, this._componentManager = n, this._commandService = t, this._shortcutService = i, this._menuService = o, this._uiController = s, this._init();
496
+ var Kt = Object.defineProperty, Zt = Object.getOwnPropertyDescriptor, Xt = (e, t, n, o) => {
497
+ for (var r = o > 1 ? void 0 : o ? Zt(t, n) : t, i = e.length - 1, s; i >= 0; i--)
498
+ (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
499
+ return o && r && Kt(t, n, r), r;
500
+ }, M = (e, t) => (n, o) => t(n, o, e);
501
+ let V = class extends Te {
502
+ constructor(e, t, n, o, r, i) {
503
+ super(), this._injector = e, this._componentManager = t, this._commandService = n, this._shortcutService = o, this._menuService = r, this._uiController = i, this._init();
434
504
  }
435
505
  _initCustomComponents() {
436
506
  const e = this._componentManager;
437
- this.disposeWithMe(e.register(z, ge)), this.disposeWithMe(e.register(Y, re)), this.disposeWithMe(e.register(W, se)), this.disposeWithMe(e.register(Z, ce));
507
+ this.disposeWithMe(e.register(Pe, _t)), this.disposeWithMe(e.register(Me, Ke)), this.disposeWithMe(e.register(Ee, Ze)), this.disposeWithMe(e.register(Ae, Xe));
438
508
  }
439
509
  _initMenus() {
440
510
  [
441
- Ee,
442
- Be,
443
- Ne,
444
- Pe,
445
- be,
446
- ye,
447
- je,
448
- $e,
449
- we,
450
- ze,
451
- Ye
511
+ $t,
512
+ wt,
513
+ Bt,
514
+ jt,
515
+ Ht,
516
+ Vt,
517
+ zt,
518
+ Wt,
519
+ Yt,
520
+ kt,
521
+ Gt
452
522
  ].forEach((e) => {
453
523
  this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e)));
454
524
  });
@@ -457,16 +527,16 @@ let I = class extends X {
457
527
  this._initCustomComponents(), this._initMenus();
458
528
  }
459
529
  };
460
- I = He([
461
- q(J.Rendered, I),
462
- g(0, f(F)),
463
- g(1, f(le)),
464
- g(2, O),
465
- g(3, ae),
466
- g(4, de),
467
- g(5, ue)
468
- ], I);
469
- const ot = {
530
+ V = Xt([
531
+ Se(Oe.Rendered, V),
532
+ M(0, y(Y)),
533
+ M(1, y(Ge)),
534
+ M(2, _),
535
+ M(3, ye),
536
+ M(4, qe),
537
+ M(5, Je)
538
+ ], V);
539
+ const Nn = {
470
540
  toolbar: {
471
541
  undo: "Undo",
472
542
  redo: "Redo",
@@ -485,7 +555,7 @@ const ot = {
485
555
  order: "Ordered list",
486
556
  unorder: "Unordered list"
487
557
  }
488
- }, Ke = {
558
+ }, qt = {
489
559
  toolbar: {
490
560
  undo: "撤销",
491
561
  redo: "重做",
@@ -505,61 +575,588 @@ const ot = {
505
575
  order: "有序列表",
506
576
  unorder: "无序列表"
507
577
  }
578
+ }, Jt = {
579
+ id: ht.id,
580
+ preconditions: (e) => e.getContextValue(m),
581
+ binding: g.ENTER
582
+ }, Qt = {
583
+ id: ft.id,
584
+ preconditions: (e) => e.getContextValue(m),
585
+ binding: g.BACKSPACE
586
+ }, en = {
587
+ id: mt.id,
588
+ preconditions: (e) => e.getContextValue(m),
589
+ binding: g.DELETE
590
+ }, tn = 10, nn = 6;
591
+ function on() {
592
+ return ve.generateRandomId(nn);
593
+ }
594
+ function rn(e) {
595
+ const t = e.match(/data-copy-id="([^\s]+)"/);
596
+ return t && t[1] ? t[1] : null;
597
+ }
598
+ class sn {
599
+ constructor() {
600
+ h(this, "_cache", new Fe(tn));
601
+ }
602
+ set(t, n) {
603
+ this._cache.set(t, n);
604
+ }
605
+ get(t) {
606
+ return this._cache.get(t);
607
+ }
608
+ clear() {
609
+ this._cache.clear();
610
+ }
611
+ }
612
+ const pe = new sn();
613
+ function re(e) {
614
+ const t = e.style, n = {}, o = e.tagName.toLowerCase();
615
+ switch (o) {
616
+ case "b":
617
+ case "em":
618
+ case "strong": {
619
+ n.bl = u.TRUE;
620
+ break;
621
+ }
622
+ case "s": {
623
+ n.st = {
624
+ s: u.TRUE
625
+ };
626
+ break;
627
+ }
628
+ case "u": {
629
+ n.ul = {
630
+ s: u.TRUE
631
+ };
632
+ break;
633
+ }
634
+ case "i": {
635
+ n.it = u.TRUE;
636
+ break;
637
+ }
638
+ case "sub":
639
+ case "sup": {
640
+ n.va = o === "sup" ? E.SUPERSCRIPT : E.SUBSCRIPT;
641
+ break;
642
+ }
643
+ }
644
+ for (let r = 0; r < t.length; r++) {
645
+ const i = t[r], s = t.getPropertyValue(i);
646
+ switch (i) {
647
+ case "font-family": {
648
+ n.ff = s;
649
+ break;
650
+ }
651
+ case "font-size": {
652
+ const a = Number.parseInt(s);
653
+ Number.isNaN(a) || s.endsWith("pt") && (n.fs = a);
654
+ break;
655
+ }
656
+ case "font-style": {
657
+ s === "italic" && (n.it = u.TRUE);
658
+ break;
659
+ }
660
+ case "font-weight": {
661
+ Number(s) > 400 && (n.bl = u.TRUE);
662
+ break;
663
+ }
664
+ case "text-decoration": {
665
+ /underline/.test(s) ? n.ul = {
666
+ s: u.TRUE
667
+ } : /overline/.test(s) ? n.ol = {
668
+ s: u.TRUE
669
+ } : /line-through/.test(s) && (n.st = {
670
+ s: u.TRUE
671
+ });
672
+ break;
673
+ }
674
+ case "color": {
675
+ const a = new se(s);
676
+ a.isValid && (n.cl = {
677
+ rgb: a.toRgbString()
678
+ });
679
+ break;
680
+ }
681
+ case "background-color": {
682
+ const a = new se(s);
683
+ a.isValid && (n.bg = {
684
+ rgb: a.toRgbString()
685
+ });
686
+ break;
687
+ }
688
+ }
689
+ }
690
+ return n;
691
+ }
692
+ function an(e) {
693
+ const t = new DOMParser(), n = `<x-univer id="univer-root">${e}</x-univer>`;
694
+ return t.parseFromString(n, "text/html").querySelector("#univer-root");
695
+ }
696
+ function he(e, t) {
697
+ const n = e.tagName.toLowerCase();
698
+ return typeof t == "string" ? n === t : Array.isArray(t) ? t.some((o) => o === n) : t(e);
699
+ }
700
+ const z = class z {
701
+ constructor() {
702
+ h(this, "_styleCache", /* @__PURE__ */ new Map());
703
+ h(this, "_styleRules", []);
704
+ h(this, "_afterProcessRules", []);
705
+ }
706
+ static use(t) {
707
+ if (this._pluginList.includes(t))
708
+ throw new Error(`Univer paste plugin ${t.name} already added`);
709
+ this._pluginList.push(t);
710
+ }
711
+ convert(t) {
712
+ const n = z._pluginList.find((i) => i.checkPasteType(t)), o = an(t), r = {
713
+ dataStream: "",
714
+ textRuns: []
715
+ };
716
+ return n && (this._styleRules = [...n.stylesRules], this._afterProcessRules = [...n.afterProcessRules]), this._styleCache.clear(), this._process(null, o == null ? void 0 : o.childNodes, r), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], r;
717
+ }
718
+ _process(t, n, o) {
719
+ var r;
720
+ for (const i of n)
721
+ if (i.nodeType === Node.TEXT_NODE) {
722
+ const s = (r = i.nodeValue) == null ? void 0 : r.replace(/[\r\n]/g, "");
723
+ let a;
724
+ t && this._styleCache.has(t) && (a = this._styleCache.get(t)), o.dataStream += s, a && Object.getOwnPropertyNames(a).length && o.textRuns.push({
725
+ st: o.dataStream.length - s.length,
726
+ ed: o.dataStream.length,
727
+ ts: a
728
+ });
729
+ } else if (i.nodeType === Node.ELEMENT_NODE) {
730
+ const s = t ? this._styleCache.get(t) : {}, a = this._styleRules.find(({ filter: C }) => he(i, C)), c = a ? a.getStyle(i) : re(i);
731
+ this._styleCache.set(i, { ...s, ...c });
732
+ const { childNodes: l } = i;
733
+ this._process(i, l, o);
734
+ const p = this._afterProcessRules.find(
735
+ ({ filter: C }) => he(i, C)
736
+ );
737
+ p && p.handler(o, i);
738
+ }
739
+ }
740
+ };
741
+ h(z, "_pluginList", []);
742
+ let $ = z;
743
+ const cn = {
744
+ name: "univer-doc-paste-plugin-lark",
745
+ checkPasteType(e) {
746
+ return /lark-record-clipboard/i.test(e);
747
+ },
748
+ // TODO: @JOCS, support inline code copy from lark.
749
+ stylesRules: [
750
+ {
751
+ filter: ["s"],
752
+ getStyle(e) {
753
+ const t = re(e);
754
+ return {
755
+ st: {
756
+ s: u.TRUE
757
+ },
758
+ ...t
759
+ };
760
+ }
761
+ }
762
+ ],
763
+ afterProcessRules: [
764
+ {
765
+ filter(e) {
766
+ return e.tagName === "DIV" && /ace-line/i.test(e.className);
767
+ },
768
+ handler(e) {
769
+ e.paragraphs == null && (e.paragraphs = []), e.paragraphs.push({
770
+ startIndex: e.dataStream.length
771
+ }), e.dataStream += "\r";
772
+ }
773
+ }
774
+ ]
508
775
  };
509
- var Ge = Object.defineProperty, Ve = Object.getOwnPropertyDescriptor, Xe = (e, n, t, i) => {
510
- for (var o = i > 1 ? void 0 : i ? Ve(n, t) : n, s = e.length - 1, r; s >= 0; s--)
511
- (r = e[s]) && (o = (i ? r(n, t, o) : r(o)) || o);
512
- return i && o && Ge(n, t, o), o;
513
- }, L = (e, n) => (t, i) => n(t, i, e), x;
514
- let $ = (x = class extends Q {
515
- constructor(e, n, t, i) {
516
- super(Me), this._config = e, this._injector = n, this._localeService = t, this._logService = i, this._localeService.load({
517
- zhCN: Ke
518
- }), this._config = k.deepMerge({}, Ie, this._config), this._initDependencies(n);
776
+ function ln(e) {
777
+ const t = e.style, n = {};
778
+ for (let o = 0; o < t.length; o++) {
779
+ const r = t[o], i = t.getPropertyValue(r);
780
+ switch (r) {
781
+ case "margin-top": {
782
+ const s = Number.parseInt(i);
783
+ n.spaceAbove = /pt/.test(i) ? fe(s) : s;
784
+ break;
785
+ }
786
+ case "margin-bottom": {
787
+ const s = Number.parseInt(i);
788
+ n.spaceBelow = /pt/.test(i) ? fe(s) : s;
789
+ break;
790
+ }
791
+ }
792
+ }
793
+ return Object.getOwnPropertyNames(n).length ? n : null;
794
+ }
795
+ function fe(e) {
796
+ return e / 0.75;
797
+ }
798
+ const dn = {
799
+ name: "univer-doc-paste-plugin-word",
800
+ checkPasteType(e) {
801
+ return /word|mso/i.test(e);
802
+ },
803
+ stylesRules: [
804
+ {
805
+ filter: ["b"],
806
+ getStyle(e) {
807
+ const t = re(e);
808
+ return { bl: u.TRUE, ...t };
809
+ }
810
+ }
811
+ ],
812
+ afterProcessRules: [
813
+ {
814
+ filter(e) {
815
+ return e.tagName === "P" && /mso/i.test(e.className);
816
+ },
817
+ handler(e, t) {
818
+ e.paragraphs == null && (e.paragraphs = []);
819
+ const n = {
820
+ startIndex: e.dataStream.length
821
+ }, o = ln(t);
822
+ o && (n.paragraphStyle = o), e.paragraphs.push(n), e.dataStream += "\r";
823
+ }
824
+ }
825
+ ]
826
+ };
827
+ function un(e, t) {
828
+ const { st: n, ed: o, ts: r = {} } = t, { ff: i, fs: s, it: a, bl: c, ul: l, st: p, ol: C, bg: L, cl: j, va: P } = r;
829
+ let d = e.slice(n, o);
830
+ const f = [];
831
+ return a === u.TRUE && (d = `<i>${d}</i>`), P === E.SUPERSCRIPT ? d = `<sup>${d}</sup>` : P === E.SUBSCRIPT && (d = `<sub>${d}</sub>`), (l == null ? void 0 : l.s) === u.TRUE && (d = `<u>${d}</u>`), (p == null ? void 0 : p.s) === u.TRUE && (d = `<s>${d}</s>`), c === u.TRUE && (d = `<strong>${d}</strong>`), i && f.push(`font-family: ${i}`), j && f.push(`color: ${j.rgb}`), s && f.push(`font-size: ${s}px`), C && f.push("text-decoration: overline"), L && f.push(`background: ${L.rgb}`), f.length ? `<span style="${f.join(";")}">${d}</span>` : d;
832
+ }
833
+ function me(e, t = !0) {
834
+ const { dataStream: n, textRuns: o = [], paragraphs: r = [] } = e;
835
+ let i = 0;
836
+ const s = [], a = [];
837
+ for (const c of o) {
838
+ const { st: l, ed: p } = c;
839
+ if (l !== i && s.push(n.slice(i, l)), s.push(un(n, c)), i = p, t)
840
+ for (const C of r) {
841
+ const { startIndex: L, paragraphStyle: j = {} } = C;
842
+ if (L >= l && L <= p) {
843
+ const { spaceAbove: P, spaceBelow: d } = j, f = [];
844
+ P != null && (typeof P == "number" ? f.push(`margin-top: ${P}px`) : f.push(`margin-top: ${P.v}px`)), d != null && (typeof d == "number" ? f.push(`margin-bottom: ${d}px`) : f.push(`margin-bottom: ${d.v}px`)), a.push(
845
+ `<p className="UniverNormal" ${f.length ? `style="${f.join(";")}"` : ""}>${s.join("")}</p>`
846
+ ), s.length = 0;
847
+ }
848
+ }
849
+ }
850
+ return i < n.length && s.push(n.slice(i, n.length)), a.join("") + s.join("");
851
+ }
852
+ class pn {
853
+ convert(t) {
854
+ if (t.length === 0)
855
+ throw new Error("The bodyList length at least to be 1");
856
+ if (t.length === 1)
857
+ return me(t[0]);
858
+ let n = "";
859
+ for (const o of t)
860
+ n += '<p className="UniverNormal">', n += me(o, !1), n += "</p>";
861
+ return n;
862
+ }
863
+ }
864
+ var hn = Object.defineProperty, fn = Object.getOwnPropertyDescriptor, mn = (e, t, n, o) => {
865
+ for (var r = o > 1 ? void 0 : o ? fn(t, n) : t, i = e.length - 1, s; i >= 0; i--)
866
+ (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
867
+ return o && r && hn(t, n, r), r;
868
+ }, N = (e, t) => (n, o) => t(n, o, e);
869
+ $.use(dn);
870
+ $.use(cn);
871
+ function _n(e) {
872
+ const t = e.replace(/\n/g, "\r"), n = [];
873
+ for (let o = 0; o < t.length; o++)
874
+ t[o] === "\r" && n.push({ startIndex: o });
875
+ return {
876
+ dataStream: t,
877
+ paragraphs: n
878
+ };
879
+ }
880
+ const B = ze("doc.clipboard-service");
881
+ let Q = class extends Te {
882
+ constructor(t, n, o, r, i) {
883
+ super();
884
+ h(this, "_clipboardHooks", []);
885
+ h(this, "_htmlToUDM", new $());
886
+ h(this, "_umdToHtml", new pn());
887
+ this._currentUniverService = t, this._logService = n, this._commandService = o, this._clipboardInterfaceService = r, this._textSelectionManagerService = i;
888
+ }
889
+ async copy() {
890
+ const t = this._getDocumentBodyInRanges();
891
+ try {
892
+ this._setClipboardData(t);
893
+ } catch (n) {
894
+ return this._logService.error("[DocClipboardService] copy failed", n), !1;
895
+ }
896
+ return !0;
897
+ }
898
+ async cut() {
899
+ return this._cut();
900
+ }
901
+ async paste(t) {
902
+ const n = await this._generateBodyFromClipboardItems(t);
903
+ return this._paste(n);
904
+ }
905
+ async legacyPaste(t, n) {
906
+ const o = this._generateBodyFromHtmlAndText(t, n);
907
+ return this._paste(o);
908
+ }
909
+ async _cut() {
910
+ var i;
911
+ const {
912
+ segmentId: t,
913
+ endOffset: n,
914
+ style: o
915
+ } = (i = this._textSelectionManagerService.getActiveRange()) != null ? i : {}, r = this._textSelectionManagerService.getSelections();
916
+ if (t == null && this._logService.error("[DocClipboardController] segmentId is not existed"), n == null || r == null)
917
+ return !1;
918
+ this.copy();
919
+ try {
920
+ let s = n;
921
+ for (const c of r) {
922
+ const { startOffset: l, endOffset: p } = c;
923
+ l == null || p == null || p <= n && (s -= p - l);
924
+ }
925
+ const a = [
926
+ {
927
+ startOffset: s,
928
+ endOffset: s,
929
+ style: o
930
+ }
931
+ ];
932
+ return this._commandService.executeCommand(be.id, { segmentId: t, textRanges: a });
933
+ } catch {
934
+ return this._logService.error("[DocClipboardController] cut content failed"), !1;
935
+ }
936
+ }
937
+ async _paste(t) {
938
+ var s;
939
+ const { segmentId: n, endOffset: o, style: r } = (s = this._textSelectionManagerService.getActiveRange()) != null ? s : {}, i = this._textSelectionManagerService.getSelections();
940
+ if (n == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), o == null || i == null)
941
+ return !1;
942
+ try {
943
+ let a = o;
944
+ for (const l of i) {
945
+ const { startOffset: p, endOffset: C } = l;
946
+ p == null || C == null || C <= o && (a += t.dataStream.length - (C - p));
947
+ }
948
+ const c = [
949
+ {
950
+ startOffset: a,
951
+ endOffset: a,
952
+ style: r
953
+ }
954
+ ];
955
+ return this._commandService.executeCommand(xe.id, { body: t, segmentId: n, textRanges: c });
956
+ } catch {
957
+ return this._logService.error("[DocClipboardController]", "clipboard is empty."), !1;
958
+ }
959
+ }
960
+ async _setClipboardData(t) {
961
+ const n = on(), o = t.length > 1 ? t.map((i) => i.dataStream).join(`
962
+ `) : t[0].dataStream;
963
+ let r = this._umdToHtml.convert(t);
964
+ return t.length === 1 && (r = r.replace(/(<[a-z]+)/, (i, s) => `${s} data-copy-id="${n}"`), pe.set(n, t[0])), this._clipboardInterfaceService.write(o, r);
965
+ }
966
+ addClipboardHook(t) {
967
+ return this._clipboardHooks.push(t), $e(() => {
968
+ const n = this._clipboardHooks.indexOf(t);
969
+ n > -1 && this._clipboardHooks.splice(n, 1);
970
+ });
971
+ }
972
+ _getDocumentBodyInRanges() {
973
+ const t = this._textSelectionManagerService.getSelections(), n = this._currentUniverService.getCurrentUniverDocInstance(), o = [];
974
+ if (t == null)
975
+ return o;
976
+ for (const r of t) {
977
+ const { startOffset: i, endOffset: s, collapsed: a } = r;
978
+ if (a || i == null || s == null)
979
+ continue;
980
+ const c = n.sliceBody(i, s);
981
+ c != null && o.push(c);
982
+ }
983
+ return o;
984
+ }
985
+ async _generateBodyFromClipboardItems(t) {
986
+ try {
987
+ let n = "", o = "";
988
+ for (const r of t)
989
+ for (const i of r.types)
990
+ i === Qe ? o = await r.getType(i).then((s) => s && s.text()) : i === et && (n = await r.getType(i).then((s) => s && s.text()));
991
+ return this._generateBodyFromHtmlAndText(n, o);
992
+ } catch (n) {
993
+ return Promise.reject(n);
994
+ }
995
+ }
996
+ _generateBodyFromHtmlAndText(t, n) {
997
+ if (!t) {
998
+ if (n)
999
+ return _n(n);
1000
+ throw new Error("[DocClipboardService] html and text cannot be both empty!");
1001
+ }
1002
+ const o = rn(t);
1003
+ if (o) {
1004
+ const r = pe.get(o);
1005
+ if (r)
1006
+ return r;
1007
+ }
1008
+ return this._htmlToUDM.convert(t);
1009
+ }
1010
+ };
1011
+ Q = mn([
1012
+ N(0, te),
1013
+ N(1, Re),
1014
+ N(2, _),
1015
+ N(3, oe),
1016
+ N(4, y(Ie))
1017
+ ], Q);
1018
+ function Z(e) {
1019
+ return e.getContextValue(m) || e.getContextValue(ge);
1020
+ }
1021
+ const ie = 999, gn = {
1022
+ id: tt.id,
1023
+ name: "doc.command.copy",
1024
+ type: ne.COMMAND,
1025
+ multi: !0,
1026
+ priority: ie,
1027
+ preconditions: Z,
1028
+ handler: async (e) => e.get(B).copy()
1029
+ }, Cn = {
1030
+ id: nt.id,
1031
+ name: "doc.command.cut",
1032
+ type: ne.COMMAND,
1033
+ multi: !0,
1034
+ priority: ie,
1035
+ preconditions: Z,
1036
+ handler: async (e) => e.get(B).cut()
1037
+ }, Sn = {
1038
+ id: ot.id,
1039
+ name: "doc.command.paste",
1040
+ type: ne.COMMAND,
1041
+ multi: !0,
1042
+ priority: ie,
1043
+ preconditions: Z,
1044
+ handler: async (e) => {
1045
+ const t = e.get(B), o = await e.get(oe).read();
1046
+ return o.length === 0 ? !1 : t.paste(o);
1047
+ }
1048
+ };
1049
+ var On = Object.defineProperty, Tn = Object.getOwnPropertyDescriptor, vn = (e, t, n, o) => {
1050
+ for (var r = o > 1 ? void 0 : o ? Tn(t, n) : t, i = e.length - 1, s; i >= 0; i--)
1051
+ (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
1052
+ return o && r && On(t, n, r), r;
1053
+ }, U = (e, t) => (n, o) => t(n, o, e);
1054
+ let W = class extends Ce {
1055
+ constructor(e, t, n, o, r) {
1056
+ super(), this._commandService = e, this._clipboardInterfaceService = t, this._docClipboardService = n, this._textSelectionRenderManager = o, this._contextService = r, this._init();
1057
+ }
1058
+ _init() {
1059
+ [gn, Cn, Sn].forEach((e) => this.disposeWithMe(this._commandService.registerMultipleCommand(e))), [xe, be].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e))), this._initLegacyPasteCommand();
1060
+ }
1061
+ _initLegacyPasteCommand() {
1062
+ var e;
1063
+ this._clipboardInterfaceService.supportClipboard || (e = this._textSelectionRenderManager) == null || e.onPaste$.pipe(gt(this.dispose$)).subscribe((t) => {
1064
+ var i, s;
1065
+ if (!Z(this._contextService))
1066
+ return;
1067
+ t.event.preventDefault();
1068
+ const n = t.event, o = (i = n.clipboardData) == null ? void 0 : i.getData("text/html"), r = (s = n.clipboardData) == null ? void 0 : s.getData("text/plain");
1069
+ this._docClipboardService.legacyPaste(o, r);
1070
+ });
1071
+ }
1072
+ };
1073
+ W = vn([
1074
+ Se(Oe.Steady, W),
1075
+ U(0, _),
1076
+ U(1, oe),
1077
+ U(2, B),
1078
+ U(3, De),
1079
+ U(4, we)
1080
+ ], W);
1081
+ var Rn = Object.defineProperty, yn = Object.getOwnPropertyDescriptor, In = (e, t, n, o) => {
1082
+ for (var r = o > 1 ? void 0 : o ? yn(t, n) : t, i = e.length - 1, s; i >= 0; i--)
1083
+ (s = e[i]) && (r = (o ? s(t, n, r) : s(r)) || r);
1084
+ return o && r && Rn(t, n, r), r;
1085
+ }, X = (e, t) => (n, o) => t(n, o, e), q;
1086
+ let _e = (q = class extends Be {
1087
+ constructor(e, t, n, o) {
1088
+ super(Tt), this._config = e, this._injector = t, this._localeService = n, this._logService = o, this._localeService.load({
1089
+ zhCN: qt
1090
+ }), this._config = ve.deepMerge({}, Ot, this._config), this._initDependencies(t), this._initializeCommands();
519
1091
  }
520
1092
  onRendered() {
521
1093
  this._initModules(), this._markDocAsFocused();
522
1094
  }
523
1095
  onDestroy() {
524
1096
  }
1097
+ _initializeCommands() {
1098
+ [
1099
+ vt,
1100
+ Rt,
1101
+ It,
1102
+ yt,
1103
+ bt,
1104
+ xt,
1105
+ Dt,
1106
+ Pt,
1107
+ Mt,
1108
+ Qt,
1109
+ en,
1110
+ Jt
1111
+ ].forEach((e) => {
1112
+ this._injector.get(ye).registerShortcut(e);
1113
+ });
1114
+ }
525
1115
  _initDependencies(e) {
526
1116
  [
527
- [I],
1117
+ [V],
1118
+ [W],
528
1119
  [
529
1120
  // controllers
530
- R,
1121
+ F,
1122
+ {
1123
+ useFactory: () => this._injector.createInstance(F, this._config)
1124
+ }
1125
+ ],
1126
+ [
1127
+ B,
531
1128
  {
532
- useFactory: () => this._injector.createInstance(R, this._config)
1129
+ useClass: Q
533
1130
  }
534
1131
  ]
535
- ].forEach((t) => {
536
- e.add(t);
1132
+ ].forEach((n) => {
1133
+ e.add(n);
537
1134
  });
538
1135
  }
539
1136
  _markDocAsFocused() {
540
- const e = this._injector.get(w);
1137
+ const e = this._injector.get(te);
541
1138
  try {
542
- const n = e.getCurrentUniverDocInstance(), t = n.getUnitId();
543
- t !== te && t !== ne && e.focusUniverInstance(n.getUnitId());
544
- } catch (n) {
545
- this._logService.warn(n);
1139
+ const t = e.getCurrentUniverDocInstance(), n = t.getUnitId();
1140
+ n !== He && n !== Ve && e.focusUniverInstance(t.getUnitId());
1141
+ } catch (t) {
1142
+ this._logService.warn(t);
546
1143
  }
547
1144
  }
548
1145
  _initModules() {
549
- this._injector.get(R);
550
- }
551
- }, h(x, "type", ee.Doc), x);
552
- $ = Xe([
553
- L(1, f(F)),
554
- L(2, f(U)),
555
- L(3, oe)
556
- ], $);
1146
+ this._injector.get(F);
1147
+ }
1148
+ }, h(q, "type", je.Doc), q);
1149
+ _e = In([
1150
+ X(1, y(Y)),
1151
+ X(2, y(ee)),
1152
+ X(3, Re)
1153
+ ], _e);
557
1154
  export {
558
- Me as DOC_UI_PLUGIN_NAME,
559
- Re as DefaultDocContainerConfig,
560
- Ie as DefaultDocUiConfig,
561
- ve as DefaultToolbarConfig,
562
- $ as UniverDocsUIPlugin,
563
- ot as enUS,
564
- Ke as zhCN
1155
+ Tt as DOC_UI_PLUGIN_NAME,
1156
+ St as DefaultDocContainerConfig,
1157
+ Ot as DefaultDocUiConfig,
1158
+ Ct as DefaultToolbarConfig,
1159
+ _e as UniverDocsUIPlugin,
1160
+ Nn as enUS,
1161
+ qt as zhCN
565
1162
  };