@univerjs/docs-ui 0.2.4 → 0.2.6

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 (27) hide show
  1. package/lib/cjs/index.js +4 -4
  2. package/lib/es/index.js +2134 -1729
  3. package/lib/index.css +1 -1
  4. package/lib/types/controllers/app-ui-controller.d.ts +1 -2
  5. package/lib/types/controllers/doc-container-ui-controller.d.ts +1 -2
  6. package/lib/types/controllers/doc-ui.controller.d.ts +8 -4
  7. package/lib/types/controllers/menu/context-menu.d.ts +7 -0
  8. package/lib/types/controllers/menu/menu.d.ts +1 -1
  9. package/lib/types/controllers/render-controllers/contextmenu.render-controller.d.ts +18 -0
  10. package/lib/types/controllers/render-controllers/doc-hover.render-controller.d.ts +11 -0
  11. package/lib/types/controllers/render-controllers/doc-resize.render-controller.d.ts +12 -0
  12. package/lib/types/controllers/render-controllers/zoom.render-controller.d.ts +4 -3
  13. package/lib/types/controllers/shortcut/toolbar.shortcut.d.ts +14 -0
  14. package/lib/types/docs-ui-plugin.d.ts +1 -2
  15. package/lib/types/index.d.ts +1 -0
  16. package/lib/types/services/clipboard/clipboard.service.d.ts +2 -3
  17. package/lib/types/services/doc-hover-manager.service.d.ts +18 -0
  18. package/lib/types/services/doc-page-layout.service.d.ts +8 -0
  19. package/lib/types/services/doc-popup-manager.service.d.ts +1 -2
  20. package/lib/types/views/count-bar/CountBar.d.ts +8 -0
  21. package/lib/types/views/count-bar/ZoomSlider.d.ts +3 -0
  22. package/lib/types/views/count-bar/index.d.ts +16 -0
  23. package/lib/types/views/doc-footer/DocFooter.d.ts +3 -0
  24. package/lib/types/views/doc-footer/index.d.ts +16 -0
  25. package/lib/umd/index.js +4 -4
  26. package/package.json +15 -17
  27. package/lib/types/services/doc-mark-selection.service.d.ts +0 -27
package/lib/es/index.js CHANGED
@@ -1,610 +1,626 @@
1
- var Sn = Object.defineProperty;
2
- var vn = (t, e, n) => e in t ? Sn(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var T = (t, e, n) => vn(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { FOCUSING_DOC as Ue, FOCUSING_UNIVER_EDITOR as dt, FOCUSING_COMMON_DRAWINGS as Xt, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE as Rn, Tools as j, LRUMap as On, BaselineOffset as ae, BooleanNumber as S, ColorKit as _t, DataStreamTreeTokenType as Pe, CustomRangeType as Kt, skipParseTagNames as Cn, IUniverInstanceService as w, ILogService as Zt, ICommandService as O, Disposable as Q, SliceBodyType as mt, normalizeBody as En, UniverInstanceType as v, toDisposable as Jt, RxDisposable as Se, Direction as K, EDITOR_ACTIVATED as qt, LocaleService as le, CommandType as de, DocumentFlavor as Tn, JSONX as Qe, ThemeService as Qt, HorizontalAlign as Le, OnLifecycle as we, LifecycleStages as Be, IContextService as In, checkForSubstrings as bn, IConfigService as Mn, isInternalEditorID as yn, DisposableCollection as St, Plugin as xn, ObjectRelativeFromH as Pn, ObjectRelativeFromV as Dn } from "@univerjs/core";
5
- import { IClipboardInterfaceService as ut, PLAIN_TEXT_CLIPBOARD_MIME_TYPE as An, HTML_CLIPBOARD_MIME_TYPE as Nn, IEditorService as ee, KeyCode as H, MetaKeys as ve, ILayoutService as en, ISidebarService as Fn, ComponentManager as tn, MenuGroup as x, MenuItemType as y, MenuPosition as P, getMenuHiddenObservable as D, FONT_FAMILY_LIST as vt, FONT_SIZE_LIST as Un, getHeaderFooterMenuHiddenObservable as Ln, FontFamily as wn, FontFamilyItem as Bn, FontSize as $n, IMenuService as Hn, CopyCommand as Vn, CutCommand as jn, PasteCommand as Wn, SetEditorResizeOperation as kn, ICanvasPopupService as Gn, IShortcutService as zn } from "@univerjs/ui";
6
- import { createIdentifier as Yn, Inject as I, Injector as $e, Optional as Xn } from "@wendellhu/redi";
7
- import { TextSelectionManagerService as te, DocCustomRangeService as Kn, CutContentCommand as nn, InnerPasteCommand as on, getDeleteSelection as Zn, DocSkeletonManagerService as L, VIEWPORT_KEY as q, getDocObject as Jn, MoveCursorOperation as He, MoveSelectionOperation as Ve, SelectAllOperation as qn, neoGetDocObject as J, RichTextEditingMutation as ht, SetInlineFormatBoldCommand as Qn, SetTextSelectionsOperation as V, SetInlineFormatCommand as ue, SetInlineFormatItalicCommand as eo, SetInlineFormatUnderlineCommand as to, SetInlineFormatStrikethroughCommand as no, SetInlineFormatSubscriptCommand as oo, SetInlineFormatSuperscriptCommand as ro, SetInlineFormatFontFamilyCommand as Rt, SetInlineFormatFontSizeCommand as Ot, SetInlineFormatTextColorCommand as Ct, AlignLeftCommand as io, AlignOperationCommand as je, AlignCenterCommand as so, AlignRightCommand as ao, AlignJustifyCommand as co, OrderListCommand as lo, BulletListCommand as uo, ResetInlineFormatTextBackgroundColorCommand as ho, SetInlineFormatTextBackgroundColorCommand as et, BreakLineCommand as go, DeleteLeftCommand as po, DeleteRightCommand as fo, CoverContentCommand as _o, DOCS_COMPONENT_MAIN_LAYER_INDEX as Ye, DOCS_COMPONENT_HEADER_LAYER_INDEX as mo, DOCS_VIEW_KEY as oe, DOCS_COMPONENT_DEFAULT_Z_INDEX as Et, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX as So, SetDocZoomRatioCommand as vo, SetDocZoomRatioOperation as De, DocInterceptorService as Ro } from "@univerjs/docs";
8
- import { pixelToPt as Oo, ptToPixel as Tt, NodePositionConvertToCursor as rn, getAnchorBounding as Co, IRenderManagerService as W, ITextSelectionRenderManager as ne, Shape as Eo, DocumentEditArea as F, PageLayoutType as Ae, Vector2 as sn, Rect as Xe, Path as It, ScrollBar as tt, Viewport as To, Layer as bt, Documents as Io, DocBackground as bo, CURSOR_TYPE as Mt, getLineBounding as Mo } from "@univerjs/engine-render";
9
- import { takeUntil as se, Observable as B, combineLatest as yo, fromEvent as yt, BehaviorSubject as xt, map as xo } from "rxjs";
10
- import Po, { useState as an, useEffect as cn } from "react";
11
- import { useDependency as z } from "@wendellhu/redi/react-bindings";
12
- import { Checkbox as Pt, InputNumber as Dt, Button as Do, ColorPicker as Ao } from "@univerjs/design";
13
- import No from "clsx";
14
- function k(t) {
15
- return t.getContextValue(Ue) && t.getContextValue(dt) && !t.getContextValue(Xt);
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { FOCUSING_DOC, FOCUSING_UNIVER_EDITOR, FOCUSING_COMMON_DRAWINGS, FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, Tools, LRUMap, BaselineOffset, BooleanNumber, ColorKit, DataStreamTreeTokenType, CustomRangeType, skipParseTagNames, createIdentifier, Inject, IUniverInstanceService, ILogService, ICommandService, Disposable, SliceBodyType, normalizeBody, UniverInstanceType, toDisposable, RxDisposable, Direction, EDITOR_ACTIVATED, LocaleService, Injector, Optional, useDependency, useObservable, CommandType, DocumentFlavor, JSONX, ThemeService, HorizontalAlign, connectInjector, OnLifecycle, LifecycleStages, IContextService, checkForSubstrings, IConfigService, isInternalEditorID, DisposableCollection, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, fromEventSubject, Plugin, ObjectRelativeFromH, ObjectRelativeFromV } from "@univerjs/core";
6
+ import { IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, HTML_CLIPBOARD_MIME_TYPE, IEditorService, KeyCode, MetaKeys, ILayoutService, ISidebarService, ComponentManager, MenuGroup, MenuItemType, MenuPosition, getMenuHiddenObservable, FONT_FAMILY_LIST, FONT_SIZE_LIST, getHeaderFooterMenuHiddenObservable, CopyCommand, CutCommand, PasteCommand, FontFamily, FontFamilyItem, FontSize, BuiltInUIPart, IMenuService, IUIPartsService, IShortcutService, SetEditorResizeOperation, ICanvasPopupService, IContextMenuService } from "@univerjs/ui";
7
+ import { TextSelectionManagerService, DocCustomRangeService, CutContentCommand, InnerPasteCommand, getDeleteSelection, DocSkeletonManagerService, VIEWPORT_KEY, getDocObject, MoveCursorOperation, MoveSelectionOperation, SelectAllOperation, SetDocZoomRatioOperation, neoGetDocObject, RichTextEditingMutation, SetInlineFormatBoldCommand, SetTextSelectionsOperation, SetInlineFormatCommand, SetInlineFormatItalicCommand, SetInlineFormatUnderlineCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatSubscriptCommand, SetInlineFormatSuperscriptCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatTextColorCommand, AlignLeftCommand, AlignOperationCommand, AlignCenterCommand, AlignRightCommand, AlignJustifyCommand, OrderListCommand, BulletListCommand, ResetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextBackgroundColorCommand, DeleteLeftCommand, BreakLineCommand, DeleteRightCommand, CoverContentCommand, DOCS_COMPONENT_MAIN_LAYER_INDEX, DOCS_COMPONENT_HEADER_LAYER_INDEX, DOCS_VIEW_KEY, DOCS_COMPONENT_DEFAULT_Z_INDEX, DOCS_COMPONENT_BACKGROUND_LAYER_INDEX, SetDocZoomRatioCommand, DocInterceptorService } from "@univerjs/docs";
8
+ import { pixelToPt, ptToPixel, NodePositionConvertToCursor, getAnchorBounding, IRenderManagerService, ITextSelectionRenderManager, Shape, DocumentEditArea, PageLayoutType, Vector2, Rect, Path, ScrollBar, Viewport, Layer, Documents, DocBackground, CURSOR_TYPE, pxToNum, getLineBounding, TRANSFORM_CHANGE_OBSERVABLE_TYPE } from "@univerjs/engine-render";
9
+ import { takeUntil, Observable, combineLatest, fromEvent, BehaviorSubject, map, filter, throttleTime, debounceTime } from "rxjs";
10
+ import require$$0, { useMemo, useCallback, useState, useEffect } from "react";
11
+ import { Slider, Checkbox, InputNumber, Button, ColorPicker } from "@univerjs/design";
12
+ import clsx from "clsx";
13
+ function whenDocAndEditorFocused(contextService) {
14
+ return contextService.getContextValue(FOCUSING_DOC) && contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && !contextService.getContextValue(FOCUSING_COMMON_DRAWINGS);
16
15
  }
17
- function Fo(t) {
18
- return t.getContextValue(Ue) && t.getContextValue(dt) && !t.getContextValue(Rn) && !t.getContextValue(Xt);
16
+ __name(whenDocAndEditorFocused, "whenDocAndEditorFocused");
17
+ function whenDocAndEditorFocusedWithBreakLine(contextService) {
18
+ return contextService.getContextValue(FOCUSING_DOC) && contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && !contextService.getContextValue(FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE) && !contextService.getContextValue(FOCUSING_COMMON_DRAWINGS);
19
19
  }
20
- const Uo = 10, Lo = 6;
21
- function wo() {
22
- return j.generateRandomId(Lo);
20
+ __name(whenDocAndEditorFocusedWithBreakLine, "whenDocAndEditorFocusedWithBreakLine");
21
+ const COPY_CONTENT_CACHE_LIMIT = 10, ID_LENGTH = 6;
22
+ function genId() {
23
+ return Tools.generateRandomId(ID_LENGTH);
23
24
  }
24
- function Bo(t) {
25
- const e = t.match(/data-copy-id="([^\s]+)"/);
26
- return e && e[1] ? e[1] : null;
25
+ __name(genId, "genId");
26
+ function extractId(html) {
27
+ const match = html.match(/data-copy-id="([^\s]+)"/);
28
+ return match && match[1] ? match[1] : null;
27
29
  }
28
- class $o {
30
+ __name(extractId, "extractId");
31
+ const _CopyContentCache = class _CopyContentCache {
29
32
  constructor() {
30
- T(this, "_cache", new On(Uo));
33
+ __publicField(this, "_cache", new LRUMap(COPY_CONTENT_CACHE_LIMIT));
31
34
  }
32
- set(e, n) {
33
- this._cache.set(e, n);
35
+ set(id, clipboardData) {
36
+ this._cache.set(id, clipboardData);
34
37
  }
35
- get(e) {
36
- return this._cache.get(e);
38
+ get(id) {
39
+ return this._cache.get(id);
37
40
  }
38
41
  clear() {
39
42
  this._cache.clear();
40
43
  }
41
- }
42
- const At = new $o();
43
- function gt(t) {
44
- const e = t.style, n = {}, o = t.tagName.toLowerCase();
45
- switch (o) {
44
+ };
45
+ __name(_CopyContentCache, "CopyContentCache");
46
+ let CopyContentCache = _CopyContentCache;
47
+ const copyContentCache = new CopyContentCache();
48
+ function extractNodeStyle(node) {
49
+ const styles2 = node.style, docStyles = {}, tagName = node.tagName.toLowerCase();
50
+ switch (tagName) {
46
51
  case "b":
47
52
  case "em":
48
53
  case "strong": {
49
- n.bl = S.TRUE;
54
+ docStyles.bl = BooleanNumber.TRUE;
50
55
  break;
51
56
  }
52
57
  case "s": {
53
- n.st = {
54
- s: S.TRUE
58
+ docStyles.st = {
59
+ s: BooleanNumber.TRUE
55
60
  };
56
61
  break;
57
62
  }
58
63
  case "u": {
59
- n.ul = {
60
- s: S.TRUE
64
+ docStyles.ul = {
65
+ s: BooleanNumber.TRUE
61
66
  };
62
67
  break;
63
68
  }
64
69
  case "i": {
65
- n.it = S.TRUE;
70
+ docStyles.it = BooleanNumber.TRUE;
66
71
  break;
67
72
  }
68
73
  case "sub":
69
74
  case "sup": {
70
- n.va = o === "sup" ? ae.SUPERSCRIPT : ae.SUBSCRIPT;
75
+ docStyles.va = tagName === "sup" ? BaselineOffset.SUPERSCRIPT : BaselineOffset.SUBSCRIPT;
71
76
  break;
72
77
  }
73
78
  }
74
- for (let r = 0; r < e.length; r++) {
75
- const i = e[r], s = e.getPropertyValue(i);
76
- switch (i) {
79
+ for (let i = 0; i < styles2.length; i++) {
80
+ const cssRule = styles2[i], cssValue = styles2.getPropertyValue(cssRule);
81
+ switch (cssRule) {
77
82
  case "font-family": {
78
- n.ff = s;
83
+ docStyles.ff = cssValue;
79
84
  break;
80
85
  }
81
86
  case "font-size": {
82
- const a = Number.parseInt(s);
83
- Number.isNaN(a) || (s.endsWith("pt") ? n.fs = a : s.endsWith("px") && (n.fs = Oo(a)));
87
+ const fontSize = Number.parseInt(cssValue);
88
+ Number.isNaN(fontSize) || (cssValue.endsWith("pt") ? docStyles.fs = fontSize : cssValue.endsWith("px") && (docStyles.fs = pixelToPt(fontSize)));
84
89
  break;
85
90
  }
86
91
  case "font-style": {
87
- s === "italic" && (n.it = S.TRUE);
92
+ cssValue === "italic" && (docStyles.it = BooleanNumber.TRUE);
88
93
  break;
89
94
  }
90
95
  case "font-weight": {
91
- (Number(s) > 400 || String(s) === "bold") && (n.bl = S.TRUE);
96
+ (Number(cssValue) > 400 || String(cssValue) === "bold") && (docStyles.bl = BooleanNumber.TRUE);
92
97
  break;
93
98
  }
94
99
  case "text-decoration": {
95
- /underline/.test(s) ? n.ul = {
96
- s: S.TRUE
97
- } : /overline/.test(s) ? n.ol = {
98
- s: S.TRUE
99
- } : /line-through/.test(s) && (n.st = {
100
- s: S.TRUE
100
+ /underline/.test(cssValue) ? docStyles.ul = {
101
+ s: BooleanNumber.TRUE
102
+ } : /overline/.test(cssValue) ? docStyles.ol = {
103
+ s: BooleanNumber.TRUE
104
+ } : /line-through/.test(cssValue) && (docStyles.st = {
105
+ s: BooleanNumber.TRUE
101
106
  });
102
107
  break;
103
108
  }
104
109
  case "color": {
105
- const a = new _t(s);
106
- a.isValid && (n.cl = {
107
- rgb: a.toRgbString()
110
+ const color = new ColorKit(cssValue);
111
+ color.isValid && (docStyles.cl = {
112
+ rgb: color.toRgbString()
108
113
  });
109
114
  break;
110
115
  }
111
116
  case "background-color": {
112
- const a = new _t(s);
113
- a.isValid && (n.bg = {
114
- rgb: a.toRgbString()
117
+ const color = new ColorKit(cssValue);
118
+ color.isValid && (docStyles.bg = {
119
+ rgb: color.toRgbString()
115
120
  });
116
121
  break;
117
122
  }
118
123
  }
119
124
  }
120
- return n;
125
+ return docStyles;
121
126
  }
122
- function Ho(t) {
123
- const e = new DOMParser(), n = `<x-univer id="univer-root">${t}</x-univer>`;
124
- return e.parseFromString(n, "text/html").querySelector("#univer-root");
127
+ __name(extractNodeStyle, "extractNodeStyle");
128
+ function parseToDom(rawHtml) {
129
+ const parser = new DOMParser(), html = `<x-univer id="univer-root">${rawHtml}</x-univer>`;
130
+ return parser.parseFromString(html, "text/html").querySelector("#univer-root");
125
131
  }
126
- function Nt(t, e) {
127
- const n = t.tagName.toLowerCase();
128
- return typeof e == "string" ? n === e : Array.isArray(e) ? e.some((o) => o === n) : e(t);
132
+ __name(parseToDom, "parseToDom");
133
+ function matchFilter(node, filter2) {
134
+ const tagName = node.tagName.toLowerCase();
135
+ return typeof filter2 == "string" ? tagName === filter2 : Array.isArray(filter2) ? filter2.some((name) => name === tagName) : filter2(node);
129
136
  }
130
- const Fe = class Fe {
137
+ __name(matchFilter, "matchFilter");
138
+ const _HtmlToUDMService = class _HtmlToUDMService {
131
139
  constructor() {
132
- T(this, "_styleCache", /* @__PURE__ */ new Map());
133
- T(this, "_styleRules", []);
134
- T(this, "_afterProcessRules", []);
140
+ __publicField(this, "_styleCache", /* @__PURE__ */ new Map());
141
+ __publicField(this, "_styleRules", []);
142
+ __publicField(this, "_afterProcessRules", []);
135
143
  }
136
- static use(e) {
137
- if (this._pluginList.includes(e))
138
- throw new Error(`Univer paste plugin ${e.name} already added`);
139
- this._pluginList.push(e);
144
+ static use(plugin) {
145
+ if (this._pluginList.includes(plugin))
146
+ throw new Error(`Univer paste plugin ${plugin.name} already added`);
147
+ this._pluginList.push(plugin);
140
148
  }
141
- convert(e) {
142
- const n = Fe._pluginList.find((i) => i.checkPasteType(e)), o = Ho(e), r = {
149
+ convert(html) {
150
+ const pastePlugin = _HtmlToUDMService._pluginList.find((plugin) => plugin.checkPasteType(html)), dom = parseToDom(html), newDocBody = {
143
151
  dataStream: "",
144
152
  textRuns: []
145
153
  };
146
- 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;
154
+ return pastePlugin && (this._styleRules = [...pastePlugin.stylesRules], this._afterProcessRules = [...pastePlugin.afterProcessRules]), this._styleCache.clear(), this._process(null, dom == null ? void 0 : dom.childNodes, newDocBody), this._styleCache.clear(), this._styleRules = [], this._afterProcessRules = [], newDocBody;
147
155
  }
148
- _process(e, n, o) {
149
- var r, i, s;
150
- for (const a of n)
151
- if (a.nodeType === Node.TEXT_NODE) {
152
- if (((r = a.nodeValue) == null ? void 0 : r.trim()) === "")
156
+ _process(parent, nodes, doc) {
157
+ var _a19, _b, _c;
158
+ for (const node of nodes)
159
+ if (node.nodeType === Node.TEXT_NODE) {
160
+ if (((_a19 = node.nodeValue) == null ? void 0 : _a19.trim()) === "")
153
161
  continue;
154
- let c = (i = a.nodeValue) == null ? void 0 : i.replace(/[\r\n]/g, ""), d;
155
- if (e && e.nodeType === Node.ELEMENT_NODE && e.tagName.toUpperCase() === "A") {
156
- const g = j.generateRandomId();
157
- c = `${Pe.CUSTOM_RANGE_START}${c}${Pe.CUSTOM_RANGE_END}`, o.customRanges = [
158
- ...(s = o.customRanges) != null ? s : [],
162
+ let text = (_b = node.nodeValue) == null ? void 0 : _b.replace(/[\r\n]/g, ""), style;
163
+ if (parent && parent.nodeType === Node.ELEMENT_NODE && parent.tagName.toUpperCase() === "A") {
164
+ const id = Tools.generateRandomId();
165
+ text = `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${text}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`, doc.customRanges = [
166
+ ...(_c = doc.customRanges) != null ? _c : [],
159
167
  {
160
- startIndex: o.dataStream.length,
161
- endIndex: o.dataStream.length + c.length - 1,
162
- rangeId: g,
163
- rangeType: Kt.HYPERLINK
168
+ startIndex: doc.dataStream.length,
169
+ endIndex: doc.dataStream.length + text.length - 1,
170
+ rangeId: id,
171
+ rangeType: CustomRangeType.HYPERLINK
164
172
  }
165
- ], o.payloads = {
166
- ...o.payloads,
167
- [g]: e.href
173
+ ], doc.payloads = {
174
+ ...doc.payloads,
175
+ [id]: parent.href
168
176
  };
169
177
  }
170
- e && this._styleCache.has(e) && (d = this._styleCache.get(e)), o.dataStream += c, d && Object.getOwnPropertyNames(d).length && o.textRuns.push({
171
- st: o.dataStream.length - c.length,
172
- ed: o.dataStream.length,
173
- ts: d
178
+ parent && this._styleCache.has(parent) && (style = this._styleCache.get(parent)), doc.dataStream += text, style && Object.getOwnPropertyNames(style).length && doc.textRuns.push({
179
+ st: doc.dataStream.length - text.length,
180
+ ed: doc.dataStream.length,
181
+ ts: style
174
182
  });
175
183
  } else {
176
- if (Cn.includes(a.nodeName.toLowerCase()))
184
+ if (skipParseTagNames.includes(node.nodeName.toLowerCase()))
177
185
  continue;
178
- if (a.nodeType === Node.ELEMENT_NODE) {
179
- const c = e ? this._styleCache.get(e) : {}, d = this._styleRules.find(({ filter: l }) => Nt(a, l)), g = d ? d.getStyle(a) : gt(a);
180
- this._styleCache.set(a, { ...c, ...g });
181
- const { childNodes: h } = a;
182
- this._process(a, h, o);
183
- const p = this._afterProcessRules.find(
184
- ({ filter: l }) => Nt(a, l)
186
+ if (node.nodeType === Node.ELEMENT_NODE) {
187
+ const parentStyles = parent ? this._styleCache.get(parent) : {}, styleRule = this._styleRules.find(({ filter: filter2 }) => matchFilter(node, filter2)), nodeStyles = styleRule ? styleRule.getStyle(node) : extractNodeStyle(node);
188
+ this._styleCache.set(node, { ...parentStyles, ...nodeStyles });
189
+ const { childNodes } = node;
190
+ this._process(node, childNodes, doc);
191
+ const afterProcessRule = this._afterProcessRules.find(
192
+ ({ filter: filter2 }) => matchFilter(node, filter2)
185
193
  );
186
- p && p.handler(o, a);
194
+ afterProcessRule && afterProcessRule.handler(doc, node);
187
195
  }
188
196
  }
189
197
  }
190
198
  };
191
- T(Fe, "_pluginList", []);
192
- let ce = Fe;
193
- const Vo = {
199
+ __name(_HtmlToUDMService, "HtmlToUDMService"), __publicField(_HtmlToUDMService, "_pluginList", []);
200
+ let HtmlToUDMService = _HtmlToUDMService;
201
+ const wordPastePlugin$1 = {
194
202
  name: "univer-doc-paste-plugin-lark",
195
- checkPasteType(t) {
196
- return /lark-record-clipboard/i.test(t);
203
+ checkPasteType(html) {
204
+ return /lark-record-clipboard/i.test(html);
197
205
  },
198
206
  // TODO: @JOCS, support inline code copy from lark.
199
207
  stylesRules: [
200
208
  {
201
209
  filter: ["s"],
202
- getStyle(t) {
203
- const e = gt(t);
210
+ getStyle(node) {
211
+ const inlineStyle = extractNodeStyle(node);
204
212
  return {
205
213
  st: {
206
- s: S.TRUE
214
+ s: BooleanNumber.TRUE
207
215
  },
208
- ...e
216
+ ...inlineStyle
209
217
  };
210
218
  }
211
219
  }
212
220
  ],
213
221
  afterProcessRules: [
214
222
  {
215
- filter(t) {
216
- return t.tagName === "DIV" && /ace-line/i.test(t.className);
223
+ filter(el) {
224
+ return el.tagName === "DIV" && /ace-line/i.test(el.className);
217
225
  },
218
- handler(t) {
219
- t.paragraphs == null && (t.paragraphs = []), t.paragraphs.push({
220
- startIndex: t.dataStream.length
221
- }), t.dataStream += "\r";
226
+ handler(doc) {
227
+ doc.paragraphs == null && (doc.paragraphs = []), doc.paragraphs.push({
228
+ startIndex: doc.dataStream.length
229
+ }), doc.dataStream += "\r";
222
230
  }
223
231
  }
224
232
  ]
225
- }, jo = Vo;
226
- function ln(t) {
227
- const e = t.style, n = {};
228
- for (let o = 0; o < e.length; o++) {
229
- const r = e[o], i = e.getPropertyValue(r);
230
- switch (r) {
233
+ }, PastePluginLark = wordPastePlugin$1;
234
+ function getParagraphStyle(el) {
235
+ const styles2 = el.style, paragraphStyle = {};
236
+ for (let i = 0; i < styles2.length; i++) {
237
+ const cssRule = styles2[i], cssValue = styles2.getPropertyValue(cssRule);
238
+ switch (cssRule) {
231
239
  case "margin-top": {
232
- const s = Number.parseInt(i);
233
- n.spaceAbove = { v: /pt/.test(i) ? Tt(s) : s };
240
+ const marginTopValue = Number.parseInt(cssValue);
241
+ paragraphStyle.spaceAbove = { v: /pt/.test(cssValue) ? ptToPixel(marginTopValue) : marginTopValue };
234
242
  break;
235
243
  }
236
244
  case "margin-bottom": {
237
- const s = Number.parseInt(i);
238
- n.spaceBelow = { v: /pt/.test(i) ? Tt(s) : s };
245
+ const marginBottomValue = Number.parseInt(cssValue);
246
+ paragraphStyle.spaceBelow = { v: /pt/.test(cssValue) ? ptToPixel(marginBottomValue) : marginBottomValue };
239
247
  break;
240
248
  }
241
249
  case "line-height": {
242
- const s = Number.parseFloat(i);
243
- n.lineSpacing = s;
250
+ const lineHeightValue = Number.parseFloat(cssValue);
251
+ paragraphStyle.lineSpacing = lineHeightValue;
244
252
  break;
245
253
  }
246
254
  }
247
255
  }
248
- return Object.getOwnPropertyNames(n).length ? n : null;
256
+ return Object.getOwnPropertyNames(paragraphStyle).length ? paragraphStyle : null;
249
257
  }
250
- const Wo = {
258
+ __name(getParagraphStyle, "getParagraphStyle");
259
+ const wordPastePlugin = {
251
260
  name: "univer-doc-paste-plugin-word",
252
- checkPasteType(t) {
253
- return /word|mso/i.test(t);
261
+ checkPasteType(html) {
262
+ return /word|mso/i.test(html);
254
263
  },
255
264
  stylesRules: [
256
265
  {
257
266
  filter: ["b"],
258
- getStyle(t) {
259
- const e = gt(t);
260
- return { bl: S.TRUE, ...e };
267
+ getStyle(node) {
268
+ const inlineStyle = extractNodeStyle(node);
269
+ return { bl: BooleanNumber.TRUE, ...inlineStyle };
261
270
  }
262
271
  }
263
272
  ],
264
273
  afterProcessRules: [
265
274
  {
266
- filter(t) {
267
- return t.tagName === "P";
275
+ filter(el) {
276
+ return el.tagName === "P";
268
277
  },
269
- handler(t, e) {
270
- t.paragraphs == null && (t.paragraphs = []);
271
- const n = {
272
- startIndex: t.dataStream.length
273
- }, o = ln(e);
274
- o && (n.paragraphStyle = o), t.paragraphs.push(n), t.dataStream += "\r";
278
+ handler(doc, el) {
279
+ doc.paragraphs == null && (doc.paragraphs = []);
280
+ const paragraph = {
281
+ startIndex: doc.dataStream.length
282
+ }, paragraphStyle = getParagraphStyle(el);
283
+ paragraphStyle && (paragraph.paragraphStyle = paragraphStyle), doc.paragraphs.push(paragraph), doc.dataStream += "\r";
275
284
  }
276
285
  }
277
286
  ]
278
- }, ko = Wo, Go = {
287
+ }, PastePluginWord = wordPastePlugin, univerPastePlugin = {
279
288
  name: "univer-doc-paste-plugin-univer",
280
- checkPasteType(t) {
281
- return /UniverNormal/i.test(t);
289
+ checkPasteType(html) {
290
+ return /UniverNormal/i.test(html);
282
291
  },
283
292
  stylesRules: [],
284
293
  afterProcessRules: [
285
294
  {
286
- filter(t) {
287
- return t.tagName === "P" && /UniverNormal/i.test(t.className);
295
+ filter(el) {
296
+ return el.tagName === "P" && /UniverNormal/i.test(el.className);
288
297
  },
289
- handler(t, e) {
290
- t.paragraphs == null && (t.paragraphs = []);
291
- const n = {
292
- startIndex: t.dataStream.length
293
- }, o = ln(e);
294
- o && (n.paragraphStyle = o), t.paragraphs.push(n), t.dataStream += "\r";
298
+ handler(doc, el) {
299
+ doc.paragraphs == null && (doc.paragraphs = []);
300
+ const paragraph = {
301
+ startIndex: doc.dataStream.length
302
+ }, paragraphStyle = getParagraphStyle(el);
303
+ paragraphStyle && (paragraph.paragraphStyle = paragraphStyle), doc.paragraphs.push(paragraph), doc.dataStream += "\r";
295
304
  }
296
305
  }
297
306
  ]
298
- }, zo = Go;
299
- function Ft(t, e) {
300
- const { st: n, ed: o, ts: r = {} } = e, { ff: i, fs: s, it: a, bl: c, ul: d, st: g, ol: h, bg: p, cl: l, va: f } = r;
301
- let u = t.slice(n, o);
302
- const _ = [];
303
- return a === S.TRUE && (u = `<i>${u}</i>`), f === ae.SUPERSCRIPT ? u = `<sup>${u}</sup>` : f === ae.SUBSCRIPT && (u = `<sub>${u}</sub>`), (d == null ? void 0 : d.s) === S.TRUE && (u = `<u>${u}</u>`), (g == null ? void 0 : g.s) === S.TRUE && (u = `<s>${u}</s>`), c === S.TRUE && (u = `<strong>${u}</strong>`), i && _.push(`font-family: ${i}`), l && _.push(`color: ${l.rgb}`), s && _.push(`font-size: ${s}pt`), h && _.push("text-decoration: overline"), p && _.push(`background: ${p.rgb}`), _.length ? `<span style="${_.join("; ")};">${u}</span>` : u;
307
+ }, PastePluginUniver = univerPastePlugin;
308
+ function covertTextRunToHtml(dataStream, textRun) {
309
+ const { st: start, ed, ts = {} } = textRun, { ff, fs, it, bl, ul, st, ol, bg, cl, va } = ts;
310
+ let html = dataStream.slice(start, ed);
311
+ const style = [];
312
+ return it === BooleanNumber.TRUE && (html = `<i>${html}</i>`), va === BaselineOffset.SUPERSCRIPT ? html = `<sup>${html}</sup>` : va === BaselineOffset.SUBSCRIPT && (html = `<sub>${html}</sub>`), (ul == null ? void 0 : ul.s) === BooleanNumber.TRUE && (html = `<u>${html}</u>`), (st == null ? void 0 : st.s) === BooleanNumber.TRUE && (html = `<s>${html}</s>`), bl === BooleanNumber.TRUE && (html = `<strong>${html}</strong>`), ff && style.push(`font-family: ${ff}`), cl && style.push(`color: ${cl.rgb}`), fs && style.push(`font-size: ${fs}pt`), ol && style.push("text-decoration: overline"), bg && style.push(`background: ${bg.rgb}`), style.length ? `<span style="${style.join("; ")};">${html}</span>` : html;
304
313
  }
305
- function Ke(t, e, n) {
306
- const { dataStream: o, textRuns: r = [] } = t;
307
- let i = e;
308
- const s = [];
309
- for (const a of r) {
310
- const { st: c, ed: d } = a;
311
- j.hasIntersectionBetweenTwoRanges(e, n, c, d) && (c > i ? (s.push(o.slice(i, c)), s.push(Ft(o, {
312
- ...a,
313
- ed: Math.min(d, n)
314
- }))) : s.push(Ft(o, {
315
- ...a,
316
- st: i,
317
- ed: Math.min(d, n)
318
- }))), i = Math.max(e, Math.min(d, n));
319
- }
320
- return i !== n && s.push(o.slice(i, n)), s.join("");
314
+ __name(covertTextRunToHtml, "covertTextRunToHtml");
315
+ function getBodySliceHtml(body, startIndex, endIndex) {
316
+ const { dataStream, textRuns = [] } = body;
317
+ let cursorIndex = startIndex;
318
+ const spanList = [];
319
+ for (const textRun of textRuns) {
320
+ const { st, ed } = textRun;
321
+ Tools.hasIntersectionBetweenTwoRanges(startIndex, endIndex, st, ed) && (st > cursorIndex ? (spanList.push(dataStream.slice(cursorIndex, st)), spanList.push(covertTextRunToHtml(dataStream, {
322
+ ...textRun,
323
+ ed: Math.min(ed, endIndex)
324
+ }))) : spanList.push(covertTextRunToHtml(dataStream, {
325
+ ...textRun,
326
+ st: cursorIndex,
327
+ ed: Math.min(ed, endIndex)
328
+ }))), cursorIndex = Math.max(startIndex, Math.min(ed, endIndex));
329
+ }
330
+ return cursorIndex !== endIndex && spanList.push(dataStream.slice(cursorIndex, endIndex)), spanList.join("");
321
331
  }
322
- function Ut(t, e = !0) {
323
- var n;
324
- if (e && ((n = t.paragraphs) != null && n.length)) {
325
- const { dataStream: o, paragraphs: r = [] } = t;
326
- let i = "", s = -1;
327
- for (const a of r) {
328
- const { startIndex: c, paragraphStyle: d = {} } = a, { spaceAbove: g, spaceBelow: h, lineSpacing: p } = d, l = [];
329
- g != null && (typeof g == "number" ? l.push(`margin-top: ${g}px`) : l.push(`margin-top: ${g.v}px`)), h != null && (typeof h == "number" ? l.push(`margin-bottom: ${h}px`) : l.push(`margin-bottom: ${h.v}px`)), p != null && l.push(`line-height: ${p}`), c > s + 1 ? i += `<p class="UniverNormal" ${l.length ? `style="${l.join("; ")};"` : ""}>${Ke(t, s + 1, c)}</p>` : i += `<p class="UniverNormal" ${l.length ? `style="${l.join("; ")};"` : ""}></p>`, s = c;
332
+ __name(getBodySliceHtml, "getBodySliceHtml");
333
+ function convertBodyToHtml(body, withParagraphInfo = !0) {
334
+ var _a19;
335
+ if (withParagraphInfo && ((_a19 = body.paragraphs) != null && _a19.length)) {
336
+ const { dataStream, paragraphs = [] } = body;
337
+ let result = "", cursorIndex = -1;
338
+ for (const paragraph of paragraphs) {
339
+ const { startIndex, paragraphStyle = {} } = paragraph, { spaceAbove, spaceBelow, lineSpacing } = paragraphStyle, style = [];
340
+ spaceAbove != null && (typeof spaceAbove == "number" ? style.push(`margin-top: ${spaceAbove}px`) : style.push(`margin-top: ${spaceAbove.v}px`)), spaceBelow != null && (typeof spaceBelow == "number" ? style.push(`margin-bottom: ${spaceBelow}px`) : style.push(`margin-bottom: ${spaceBelow.v}px`)), lineSpacing != null && style.push(`line-height: ${lineSpacing}`), startIndex > cursorIndex + 1 ? result += `<p class="UniverNormal" ${style.length ? `style="${style.join("; ")};"` : ""}>${getBodySliceHtml(body, cursorIndex + 1, startIndex)}</p>` : result += `<p class="UniverNormal" ${style.length ? `style="${style.join("; ")};"` : ""}></p>`, cursorIndex = startIndex;
330
341
  }
331
- return s !== o.length && (i += Ke(t, s, o.length)), i;
342
+ return cursorIndex !== dataStream.length && (result += getBodySliceHtml(body, cursorIndex, dataStream.length)), result;
332
343
  } else
333
- return Ke(t, 0, t.dataStream.length);
344
+ return getBodySliceHtml(body, 0, body.dataStream.length);
334
345
  }
335
- class Yo {
336
- convert(e) {
337
- if (e.length === 0)
346
+ __name(convertBodyToHtml, "convertBodyToHtml");
347
+ const _UDMToHtmlService = class _UDMToHtmlService {
348
+ convert(bodyList) {
349
+ if (bodyList.length === 0)
338
350
  throw new Error("The bodyList length at least to be 1");
339
- if (e.length === 1)
340
- return Ut(e[0]);
341
- let n = "";
342
- for (const o of e)
343
- n += '<p className="UniverNormal">', n += Ut(o, !1), n += "</p>";
344
- return n;
351
+ if (bodyList.length === 1)
352
+ return convertBodyToHtml(bodyList[0]);
353
+ let html = "";
354
+ for (const body of bodyList)
355
+ html += '<p className="UniverNormal">', html += convertBodyToHtml(body, !1), html += "</p>";
356
+ return html;
345
357
  }
346
- }
347
- var Xo = Object.defineProperty, Ko = Object.getOwnPropertyDescriptor, Zo = (t, e, n, o) => {
348
- for (var r = o > 1 ? void 0 : o ? Ko(e, n) : e, i = t.length - 1, s; i >= 0; i--)
349
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
350
- return o && r && Xo(e, n, r), r;
351
- }, re = (t, e) => (n, o) => e(n, o, t);
352
- ce.use(ko);
353
- ce.use(jo);
354
- ce.use(zo);
355
- const Re = Yn("doc.clipboard-service");
356
- let nt = class extends Q {
357
- constructor(e, n, o, r, i, s) {
358
+ };
359
+ __name(_UDMToHtmlService, "UDMToHtmlService");
360
+ let UDMToHtmlService = _UDMToHtmlService;
361
+ var __defProp$h = Object.defineProperty, __getOwnPropDesc$h = Object.getOwnPropertyDescriptor, __decorateClass$h = /* @__PURE__ */ __name((decorators, target, key, kind) => {
362
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$h(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
363
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
364
+ return kind && result && __defProp$h(target, key, result), result;
365
+ }, "__decorateClass$h"), __decorateParam$h = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$h");
366
+ HtmlToUDMService.use(PastePluginWord);
367
+ HtmlToUDMService.use(PastePluginLark);
368
+ HtmlToUDMService.use(PastePluginUniver);
369
+ const IDocClipboardService = createIdentifier("doc.clipboard-service");
370
+ var _a;
371
+ let DocClipboardService = (_a = class extends Disposable {
372
+ constructor(_univerInstanceService, _logService, _commandService, _clipboardInterfaceService, _textSelectionManagerService, _docCustomRangeService) {
358
373
  super();
359
- T(this, "_clipboardHooks", []);
360
- T(this, "_htmlToUDM", new ce());
361
- T(this, "_umdToHtml", new Yo());
362
- this._univerInstanceService = e, this._logService = n, this._commandService = o, this._clipboardInterfaceService = r, this._textSelectionManagerService = i, this._docCustomRangeService = s;
363
- }
364
- async copy(e = mt.copy) {
365
- const n = this._getDocumentBodyInRanges(e);
366
- if (n.length === 0)
374
+ __publicField(this, "_clipboardHooks", []);
375
+ __publicField(this, "_htmlToUDM", new HtmlToUDMService());
376
+ __publicField(this, "_umdToHtml", new UDMToHtmlService());
377
+ this._univerInstanceService = _univerInstanceService, this._logService = _logService, this._commandService = _commandService, this._clipboardInterfaceService = _clipboardInterfaceService, this._textSelectionManagerService = _textSelectionManagerService, this._docCustomRangeService = _docCustomRangeService;
378
+ }
379
+ async copy(sliceType = SliceBodyType.copy) {
380
+ const documentBodyList = this._getDocumentBodyInRanges(sliceType);
381
+ if (documentBodyList.length === 0)
367
382
  return !1;
368
383
  try {
369
- const o = this._textSelectionManagerService.getActiveRange(), r = !!(o != null && o.segmentId);
370
- this._setClipboardData(n, !r);
371
- } catch (o) {
372
- return this._logService.error("[DocClipboardService] copy failed", o), !1;
384
+ const activeRange = this._textSelectionManagerService.getActiveRange(), isCopyInHeaderFooter = !!(activeRange != null && activeRange.segmentId);
385
+ this._setClipboardData(documentBodyList, !isCopyInHeaderFooter);
386
+ } catch (e) {
387
+ return this._logService.error("[DocClipboardService] copy failed", e), !1;
373
388
  }
374
389
  return !0;
375
390
  }
376
391
  async cut() {
377
392
  return this._cut();
378
393
  }
379
- async paste(e) {
380
- const n = await this._generateBodyFromClipboardItems(e);
381
- return this._paste(n);
394
+ async paste(items) {
395
+ const body = await this._generateBodyFromClipboardItems(items);
396
+ return this._paste(body);
382
397
  }
383
- async legacyPaste(e, n) {
384
- const o = this._generateBodyFromHtmlAndText(e, n);
385
- return this._paste(o);
398
+ async legacyPaste(html, text) {
399
+ const body = this._generateBodyFromHtmlAndText(html, text);
400
+ return this._paste(body);
386
401
  }
387
402
  async _cut() {
388
- var i;
403
+ var _a19;
389
404
  const {
390
- segmentId: e,
391
- endOffset: n,
392
- style: o
393
- } = (i = this._textSelectionManagerService.getActiveRange()) != null ? i : {}, r = this._textSelectionManagerService.getCurrentSelections();
394
- if (e == null && this._logService.error("[DocClipboardController] segmentId is not existed"), n == null || r == null)
405
+ segmentId,
406
+ endOffset: activeEndOffset,
407
+ style
408
+ } = (_a19 = this._textSelectionManagerService.getActiveRange()) != null ? _a19 : {}, ranges = this._textSelectionManagerService.getCurrentSelections();
409
+ if (segmentId == null && this._logService.error("[DocClipboardController] segmentId is not existed"), activeEndOffset == null || ranges == null)
395
410
  return !1;
396
- this.copy(mt.cut);
411
+ this.copy(SliceBodyType.cut);
397
412
  try {
398
- let s = n;
399
- for (const c of r) {
400
- const { startOffset: d, endOffset: g } = c;
401
- d == null || g == null || g <= n && (s -= g - d);
413
+ let cursor = activeEndOffset;
414
+ for (const range of ranges) {
415
+ const { startOffset, endOffset } = range;
416
+ startOffset == null || endOffset == null || endOffset <= activeEndOffset && (cursor -= endOffset - startOffset);
402
417
  }
403
- const a = [
418
+ const textRanges = [
404
419
  {
405
- startOffset: s,
406
- endOffset: s,
407
- style: o
420
+ startOffset: cursor,
421
+ endOffset: cursor,
422
+ style
408
423
  }
409
424
  ];
410
- return this._commandService.executeCommand(nn.id, { segmentId: e, textRanges: a });
425
+ return this._commandService.executeCommand(CutContentCommand.id, { segmentId, textRanges });
411
426
  } catch {
412
427
  return this._logService.error("[DocClipboardController] cut content failed"), !1;
413
428
  }
414
429
  }
415
- async _paste(e) {
416
- var d, g;
417
- let n = En(e);
418
- const o = (d = this._univerInstanceService.getCurrentUnitForType(v.UNIVER_DOC)) == null ? void 0 : d.getUnitId();
419
- if (!o)
430
+ async _paste(_body) {
431
+ var _a19, _b;
432
+ let body = normalizeBody(_body);
433
+ const unitId = (_a19 = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a19.getUnitId();
434
+ if (!unitId)
420
435
  return !1;
421
- this._clipboardHooks.forEach((h) => {
422
- h.onBeforePaste && (n = h.onBeforePaste(n));
423
- }), n.customRanges = (g = n.customRanges) == null ? void 0 : g.map((h) => this._docCustomRangeService.copyCustomRange(o, h));
424
- const r = this._textSelectionManagerService.getActiveRange(), { segmentId: i, endOffset: s, style: a } = r || {}, c = this._textSelectionManagerService.getCurrentSelections();
425
- if (i == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), s == null || c == null)
436
+ this._clipboardHooks.forEach((hook) => {
437
+ hook.onBeforePaste && (body = hook.onBeforePaste(body));
438
+ }), body.customRanges = (_b = body.customRanges) == null ? void 0 : _b.map((range) => this._docCustomRangeService.copyCustomRange(unitId, range));
439
+ const activeRange = this._textSelectionManagerService.getActiveRange(), { segmentId, endOffset: activeEndOffset, style } = activeRange || {}, ranges = this._textSelectionManagerService.getCurrentSelections();
440
+ if (segmentId == null && this._logService.error("[DocClipboardController] segmentId does not exist!"), activeEndOffset == null || ranges == null)
426
441
  return !1;
427
442
  try {
428
- let h = s;
429
- for (const l of c) {
430
- const { startOffset: f, endOffset: u } = l;
431
- f == null || u == null || u <= s && (h += n.dataStream.length - (u - f));
443
+ let cursor = activeEndOffset;
444
+ for (const range of ranges) {
445
+ const { startOffset, endOffset } = range;
446
+ startOffset == null || endOffset == null || endOffset <= activeEndOffset && (cursor += body.dataStream.length - (endOffset - startOffset));
432
447
  }
433
- const p = [
448
+ const textRanges = [
434
449
  {
435
- startOffset: h,
436
- endOffset: h,
437
- style: a
450
+ startOffset: cursor,
451
+ endOffset: cursor,
452
+ style
438
453
  }
439
454
  ];
440
- return this._commandService.executeCommand(on.id, { body: n, segmentId: i, textRanges: p });
455
+ return this._commandService.executeCommand(InnerPasteCommand.id, { body, segmentId, textRanges });
441
456
  } catch {
442
457
  return this._logService.error("[DocClipboardController]", "clipboard is empty."), !1;
443
458
  }
444
459
  }
445
- async _setClipboardData(e, n = !0) {
446
- const o = wo(), r = e.length > 1 ? e.map((s) => s.dataStream).join(`
447
- `) : e[0].dataStream;
448
- let i = this._umdToHtml.convert(e);
449
- return e.length === 1 && n && (i = i.replace(/(<[a-z]+)/, (s, a) => `${a} data-copy-id="${o}"`), At.set(o, e[0])), this._clipboardInterfaceService.write(r, i);
460
+ async _setClipboardData(documentBodyList, needCache = !0) {
461
+ const copyId = genId(), text = documentBodyList.length > 1 ? documentBodyList.map((body) => body.dataStream).join(`
462
+ `) : documentBodyList[0].dataStream;
463
+ let html = this._umdToHtml.convert(documentBodyList);
464
+ return documentBodyList.length === 1 && needCache && (html = html.replace(/(<[a-z]+)/, (_p0, p1) => `${p1} data-copy-id="${copyId}"`), copyContentCache.set(copyId, documentBodyList[0])), this._clipboardInterfaceService.write(text, html);
450
465
  }
451
- addClipboardHook(e) {
452
- return this._clipboardHooks.push(e), Jt(() => {
453
- const n = this._clipboardHooks.indexOf(e);
454
- n > -1 && this._clipboardHooks.splice(n, 1);
466
+ addClipboardHook(hook) {
467
+ return this._clipboardHooks.push(hook), toDisposable(() => {
468
+ const index = this._clipboardHooks.indexOf(hook);
469
+ index > -1 && this._clipboardHooks.splice(index, 1);
455
470
  });
456
471
  }
457
- _getDocumentBodyInRanges(e) {
458
- const n = this._textSelectionManagerService.getCurrentSelections(), o = this._textSelectionManagerService.getActiveRange(), r = this._univerInstanceService.getCurrentUniverDocInstance(), i = [], s = r == null ? void 0 : r.getBody();
459
- if (n == null || r == null || s == null || o == null)
460
- return i;
461
- const { segmentId: a } = o;
462
- for (const c of n) {
463
- const { startOffset: d, endOffset: g, collapsed: h } = c;
464
- if (h || d == null || g == null)
472
+ _getDocumentBodyInRanges(sliceType) {
473
+ const ranges = this._textSelectionManagerService.getCurrentSelections(), activeRange = this._textSelectionManagerService.getActiveRange(), docDataModel = this._univerInstanceService.getCurrentUniverDocInstance(), results = [], body = docDataModel == null ? void 0 : docDataModel.getBody();
474
+ if (ranges == null || docDataModel == null || body == null || activeRange == null)
475
+ return results;
476
+ const { segmentId } = activeRange;
477
+ for (const range of ranges) {
478
+ const { startOffset, endOffset, collapsed } = range;
479
+ if (collapsed || startOffset == null || endOffset == null)
465
480
  continue;
466
- const p = Zn({ startOffset: d, endOffset: g, collapsed: h }, s), l = r.getSelfOrHeaderFooterModel(a).sliceBody(p.startOffset, p.endOffset, e);
467
- if (l != null) {
468
- if (l.customRanges) {
469
- const f = [];
470
- l.customRanges.forEach((m) => {
471
- m.startIndex === m.endIndex && f.push(m);
472
- }), l.customRanges = l.customRanges.filter((m) => f.indexOf(m) === -1);
473
- let u = "", _ = 0;
474
- f.forEach((m) => {
475
- u += l.dataStream.slice(_, m.endIndex), _ = m.endIndex + 1;
476
- }), u += l.dataStream.slice(_, l.dataStream.length), l.dataStream = u;
481
+ const deleteRange = getDeleteSelection({ startOffset, endOffset, collapsed }, body), docBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).sliceBody(deleteRange.startOffset, deleteRange.endOffset, sliceType);
482
+ if (docBody != null) {
483
+ if (docBody.customRanges) {
484
+ const deleteRange2 = [];
485
+ docBody.customRanges.forEach((range2) => {
486
+ range2.startIndex === range2.endIndex && deleteRange2.push(range2);
487
+ }), docBody.customRanges = docBody.customRanges.filter((range2) => deleteRange2.indexOf(range2) === -1);
488
+ let text = "", cursor = 0;
489
+ deleteRange2.forEach((range2) => {
490
+ text += docBody.dataStream.slice(cursor, range2.endIndex), cursor = range2.endIndex + 1;
491
+ }), text += docBody.dataStream.slice(cursor, docBody.dataStream.length), docBody.dataStream = text;
477
492
  }
478
- i.push(l);
493
+ results.push(docBody);
479
494
  }
480
495
  }
481
- return i;
496
+ return results;
482
497
  }
483
- async _generateBodyFromClipboardItems(e) {
498
+ async _generateBodyFromClipboardItems(items) {
484
499
  try {
485
- let n = "", o = "";
486
- for (const r of e)
487
- for (const i of r.types)
488
- i === An ? o = await r.getType(i).then((s) => s && s.text()) : i === Nn && (n = await r.getType(i).then((s) => s && s.text()));
489
- return this._generateBodyFromHtmlAndText(n, o);
490
- } catch (n) {
491
- return Promise.reject(n);
500
+ let html = "", text = "";
501
+ for (const clipboardItem of items)
502
+ for (const type of clipboardItem.types)
503
+ type === PLAIN_TEXT_CLIPBOARD_MIME_TYPE ? text = await clipboardItem.getType(type).then((blob) => blob && blob.text()) : type === HTML_CLIPBOARD_MIME_TYPE && (html = await clipboardItem.getType(type).then((blob) => blob && blob.text()));
504
+ return this._generateBodyFromHtmlAndText(html, text);
505
+ } catch (e) {
506
+ return Promise.reject(e);
492
507
  }
493
508
  }
494
- _generateBody(e) {
495
- const n = e.replace(/\n/g, "\r");
496
- if (!e.includes("\r") && j.isLegalUrl(e)) {
497
- const r = j.generateRandomId(), i = this._univerInstanceService.getCurrentUnitForType(v.UNIVER_DOC), s = this._docCustomRangeService.copyCustomRange(
498
- i.getUnitId(),
509
+ _generateBody(text) {
510
+ const dataStream = text.replace(/\n/g, "\r");
511
+ if (!text.includes("\r") && Tools.isLegalUrl(text)) {
512
+ const id = Tools.generateRandomId(), docDataModel = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), urlText = `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${dataStream}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`, range = this._docCustomRangeService.copyCustomRange(
513
+ docDataModel.getUnitId(),
499
514
  {
500
515
  startIndex: 0,
501
- endIndex: n.length - 1,
502
- rangeId: r,
503
- rangeType: Kt.HYPERLINK,
504
- data: e
516
+ endIndex: urlText.length - 1,
517
+ rangeId: id,
518
+ rangeType: CustomRangeType.HYPERLINK,
519
+ data: text
505
520
  }
506
521
  );
507
522
  return {
508
- dataStream: `${Pe.CUSTOM_RANGE_START}${n}${Pe.CUSTOM_RANGE_END}`,
509
- customRanges: [s]
523
+ dataStream: urlText,
524
+ customRanges: [range]
510
525
  };
511
526
  }
512
- const o = [];
513
- for (let r = 0; r < n.length; r++)
514
- n[r] === "\r" && o.push({ startIndex: r });
527
+ const paragraphs = [];
528
+ for (let i = 0; i < dataStream.length; i++)
529
+ dataStream[i] === "\r" && paragraphs.push({ startIndex: i });
515
530
  return {
516
- dataStream: n,
517
- paragraphs: o
531
+ dataStream,
532
+ paragraphs
518
533
  };
519
534
  }
520
- _generateBodyFromHtmlAndText(e, n) {
521
- if (!e) {
522
- if (n)
523
- return this._generateBody(n);
535
+ _generateBodyFromHtmlAndText(html, text) {
536
+ if (!html) {
537
+ if (text)
538
+ return this._generateBody(text);
524
539
  throw new Error("[DocClipboardService] html and text cannot be both empty!");
525
540
  }
526
- const o = Bo(e);
527
- if (o) {
528
- const r = At.get(o);
529
- if (r)
530
- return r;
541
+ const copyId = extractId(html);
542
+ if (copyId) {
543
+ const copyCache = copyContentCache.get(copyId);
544
+ if (copyCache)
545
+ return copyCache;
531
546
  }
532
- return this._htmlToUDM.convert(e);
533
- }
534
- };
535
- nt = Zo([
536
- re(0, w),
537
- re(1, Zt),
538
- re(2, O),
539
- re(3, ut),
540
- re(4, I(te)),
541
- re(5, I(Kn))
542
- ], nt);
543
- var Jo = Object.defineProperty, qo = Object.getOwnPropertyDescriptor, Qo = (t, e, n, o) => {
544
- for (var r = o > 1 ? void 0 : o ? qo(e, n) : e, i = t.length - 1, s; i >= 0; i--)
545
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
546
- return o && r && Jo(e, n, r), r;
547
- }, Oe = (t, e) => (n, o) => e(n, o, t);
548
- const Lt = 1.5;
549
- let ot = class extends Se {
550
- constructor(t, e, n, o, r) {
551
- super(), this._context = t, this._textSelectionManagerService = e, this._editorService = n, this._univerInstanceService = o, this._renderManagerService = r, this._init();
547
+ return this._htmlToUDM.convert(html);
548
+ }
549
+ }, __name(_a, "DocClipboardService"), _a);
550
+ DocClipboardService = __decorateClass$h([
551
+ __decorateParam$h(0, IUniverInstanceService),
552
+ __decorateParam$h(1, ILogService),
553
+ __decorateParam$h(2, ICommandService),
554
+ __decorateParam$h(3, IClipboardInterfaceService),
555
+ __decorateParam$h(4, Inject(TextSelectionManagerService)),
556
+ __decorateParam$h(5, Inject(DocCustomRangeService))
557
+ ], DocClipboardService);
558
+ var __defProp$g = Object.defineProperty, __getOwnPropDesc$g = Object.getOwnPropertyDescriptor, __decorateClass$g = /* @__PURE__ */ __name((decorators, target, key, kind) => {
559
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$g(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
560
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
561
+ return kind && result && __defProp$g(target, key, result), result;
562
+ }, "__decorateClass$g"), __decorateParam$g = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$g");
563
+ const ANCHOR_WIDTH = 1.5;
564
+ var _a2;
565
+ let DocBackScrollRenderController = (_a2 = class extends RxDisposable {
566
+ constructor(_context, _textSelectionManagerService, _editorService, _univerInstanceService, _renderManagerService) {
567
+ super(), this._context = _context, this._textSelectionManagerService = _textSelectionManagerService, this._editorService = _editorService, this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._init();
552
568
  }
553
569
  _init() {
554
- this._textSelectionManagerService.textSelection$.pipe(se(this.dispose$)).subscribe((t) => {
555
- if (t == null)
570
+ this._textSelectionManagerService.textSelection$.pipe(takeUntil(this.dispose$)).subscribe((params) => {
571
+ if (params == null)
556
572
  return;
557
- const { isEditing: e, unitId: n } = t;
558
- e && this._scrollToSelection(n);
573
+ const { isEditing, unitId } = params;
574
+ isEditing && this._scrollToSelection(unitId);
559
575
  });
560
576
  }
561
- scrollToRange(t, e) {
562
- var s;
563
- const n = (s = this._renderManagerService.getRenderById(t)) == null ? void 0 : s.with(L), o = n == null ? void 0 : n.getSkeleton();
564
- if (!o)
577
+ scrollToRange(unitId, range) {
578
+ var _a19;
579
+ const docSkeletonManagerService = (_a19 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a19.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
580
+ if (!skeleton)
565
581
  return;
566
- const { startOffset: r } = e, i = o.findNodePositionByCharIndex(r);
567
- this.scrollToNode(t, i);
582
+ const { startOffset } = range, anchorNodePosition = skeleton.findNodePositionByCharIndex(startOffset);
583
+ this.scrollToNode(unitId, anchorNodePosition);
568
584
  }
569
- scrollToNode(t, e) {
570
- var G;
571
- const n = this._getDocObject(), o = (G = this._renderManagerService.getRenderById(t)) == null ? void 0 : G.with(L), r = o == null ? void 0 : o.getSkeleton();
572
- if (n == null || r == null)
585
+ scrollToNode(unitId, startNodePosition) {
586
+ var _a19;
587
+ const docObject = this._getDocObject(), docSkeletonManagerService = (_a19 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a19.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
588
+ if (docObject == null || skeleton == null)
573
589
  return;
574
- const i = n.document.getOffsetConfig(), { docsLeft: s, docsTop: a } = i, c = new rn(i, r), { contentBoxPointGroup: d } = c.getRangePointData(e, e), { left: g, top: h, height: p } = Co(d), l = g + s, f = h + a, u = n.scene.getViewport(q.VIEW_MAIN), _ = !!this._editorService.getEditor(t);
575
- if (u == null)
590
+ const documentOffsetConfig = docObject.document.getOffsetConfig(), { docsLeft, docsTop } = documentOffsetConfig, convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { contentBoxPointGroup } = convertor.getRangePointData(startNodePosition, startNodePosition), { left: aLeft, top: aTop, height } = getAnchorBounding(contentBoxPointGroup), left = aLeft + docsLeft, top = aTop + docsTop, viewportMain = docObject.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN), isEditor = !!this._editorService.getEditor(unitId);
591
+ if (viewportMain == null)
576
592
  return;
577
593
  const {
578
- left: m,
579
- top: R,
580
- right: C,
581
- bottom: E
582
- } = u.getBounding().viewBound;
583
- let b = 0, A = 0;
584
- const N = _ ? 0 : 100;
585
- f < R ? b = f - R - N : f > E - p && (b = f - E + p + N), l < m ? A = l - m : l > C - Lt && (A = l - C + Lt);
586
- const Y = u.transViewportScroll2ScrollValue(A, b);
587
- u.scrollBy(Y);
594
+ left: boundLeft,
595
+ top: boundTop,
596
+ right: boundRight,
597
+ bottom: boundBottom
598
+ } = viewportMain.getBounding().viewBound;
599
+ let offsetY = 0, offsetX = 0;
600
+ const delta = isEditor ? 0 : 100;
601
+ top < boundTop ? offsetY = top - boundTop - delta : top > boundBottom - height && (offsetY = top - boundBottom + height + delta), left < boundLeft ? offsetX = left - boundLeft : left > boundRight - ANCHOR_WIDTH && (offsetX = left - boundRight + ANCHOR_WIDTH);
602
+ const config = viewportMain.transViewportScroll2ScrollValue(offsetX, offsetY);
603
+ viewportMain.scrollByBarDeltaValue(config);
588
604
  }
589
605
  // Let the selection show on the current screen.
590
- _scrollToSelection(t) {
591
- const e = this._textSelectionManagerService.getActiveRange();
592
- if (e == null)
606
+ _scrollToSelection(unitId) {
607
+ const activeTextRange = this._textSelectionManagerService.getActiveRange();
608
+ if (activeTextRange == null)
593
609
  return;
594
- const { collapsed: n, startNodePosition: o } = e;
595
- n && this.scrollToNode(t, o);
610
+ const { collapsed, startNodePosition } = activeTextRange;
611
+ collapsed && this.scrollToNode(unitId, startNodePosition);
596
612
  }
597
613
  _getDocObject() {
598
- return Jn(this._univerInstanceService, this._renderManagerService);
599
- }
600
- };
601
- ot = Qo([
602
- Oe(1, I(te)),
603
- Oe(2, ee),
604
- Oe(3, I(w)),
605
- Oe(4, W)
606
- ], ot);
607
- const er = {
614
+ return getDocObject(this._univerInstanceService, this._renderManagerService);
615
+ }
616
+ }, __name(_a2, "DocBackScrollRenderController"), _a2);
617
+ DocBackScrollRenderController = __decorateClass$g([
618
+ __decorateParam$g(1, Inject(TextSelectionManagerService)),
619
+ __decorateParam$g(2, IEditorService),
620
+ __decorateParam$g(3, Inject(IUniverInstanceService)),
621
+ __decorateParam$g(4, IRenderManagerService)
622
+ ], DocBackScrollRenderController);
623
+ const DefaultToolbarConfig = {
608
624
  undo: !0,
609
625
  redo: !0,
610
626
  // Undo redo
@@ -632,7 +648,7 @@ const er = {
632
648
  // 'Wrap mode'
633
649
  textRotateMode: !0
634
650
  // 'Text Rotation Mode'
635
- }, tr = {
651
+ }, DefaultDocContainerConfig = {
636
652
  outerLeft: !1,
637
653
  outerRight: !1,
638
654
  header: !0,
@@ -645,85 +661,85 @@ const er = {
645
661
  frozenContent: !1,
646
662
  infoBar: !0,
647
663
  toolbar: !0
648
- }, nr = {
664
+ }, DefaultDocUiConfig = {
649
665
  layout: {
650
- docContainerConfig: tr,
651
- toolbarConfig: er
666
+ docContainerConfig: DefaultDocContainerConfig,
667
+ toolbarConfig: DefaultToolbarConfig
652
668
  }
653
- }, or = "DocUI", rr = {
654
- id: He.id,
655
- binding: H.ARROW_UP,
656
- preconditions: k,
669
+ }, DOC_UI_PLUGIN_NAME = "DocUI", MoveCursorUpShortcut = {
670
+ id: MoveCursorOperation.id,
671
+ binding: KeyCode.ARROW_UP,
672
+ preconditions: whenDocAndEditorFocused,
657
673
  staticParameters: {
658
- direction: K.UP
674
+ direction: Direction.UP
659
675
  }
660
- }, ir = {
661
- id: He.id,
662
- binding: H.ARROW_DOWN,
663
- preconditions: k,
676
+ }, MoveCursorDownShortcut = {
677
+ id: MoveCursorOperation.id,
678
+ binding: KeyCode.ARROW_DOWN,
679
+ preconditions: whenDocAndEditorFocused,
664
680
  staticParameters: {
665
- direction: K.DOWN
681
+ direction: Direction.DOWN
666
682
  }
667
- }, sr = {
668
- id: He.id,
669
- binding: H.ARROW_LEFT,
670
- preconditions: k,
683
+ }, MoveCursorLeftShortcut = {
684
+ id: MoveCursorOperation.id,
685
+ binding: KeyCode.ARROW_LEFT,
686
+ preconditions: whenDocAndEditorFocused,
671
687
  staticParameters: {
672
- direction: K.LEFT
688
+ direction: Direction.LEFT
673
689
  }
674
- }, ar = {
675
- id: He.id,
676
- binding: H.ARROW_RIGHT,
677
- preconditions: k,
690
+ }, MoveCursorRightShortcut = {
691
+ id: MoveCursorOperation.id,
692
+ binding: KeyCode.ARROW_RIGHT,
693
+ preconditions: whenDocAndEditorFocused,
678
694
  staticParameters: {
679
- direction: K.RIGHT
695
+ direction: Direction.RIGHT
680
696
  }
681
- }, cr = {
682
- id: Ve.id,
683
- binding: H.ARROW_UP | ve.SHIFT,
684
- preconditions: k,
697
+ }, MoveSelectionUpShortcut = {
698
+ id: MoveSelectionOperation.id,
699
+ binding: KeyCode.ARROW_UP | MetaKeys.SHIFT,
700
+ preconditions: whenDocAndEditorFocused,
685
701
  staticParameters: {
686
- direction: K.UP
702
+ direction: Direction.UP
687
703
  }
688
- }, lr = {
689
- id: Ve.id,
690
- binding: H.ARROW_DOWN | ve.SHIFT,
691
- preconditions: k,
704
+ }, MoveSelectionDownShortcut = {
705
+ id: MoveSelectionOperation.id,
706
+ binding: KeyCode.ARROW_DOWN | MetaKeys.SHIFT,
707
+ preconditions: whenDocAndEditorFocused,
692
708
  staticParameters: {
693
- direction: K.DOWN
709
+ direction: Direction.DOWN
694
710
  }
695
- }, dr = {
696
- id: Ve.id,
697
- binding: H.ARROW_LEFT | ve.SHIFT,
698
- preconditions: k,
711
+ }, MoveSelectionLeftShortcut = {
712
+ id: MoveSelectionOperation.id,
713
+ binding: KeyCode.ARROW_LEFT | MetaKeys.SHIFT,
714
+ preconditions: whenDocAndEditorFocused,
699
715
  staticParameters: {
700
- direction: K.LEFT
716
+ direction: Direction.LEFT
701
717
  }
702
- }, ur = {
703
- id: Ve.id,
704
- binding: H.ARROW_RIGHT | ve.SHIFT,
705
- preconditions: k,
718
+ }, MoveSelectionRightShortcut = {
719
+ id: MoveSelectionOperation.id,
720
+ binding: KeyCode.ARROW_RIGHT | MetaKeys.SHIFT,
721
+ preconditions: whenDocAndEditorFocused,
706
722
  staticParameters: {
707
- direction: K.RIGHT
723
+ direction: Direction.RIGHT
708
724
  }
709
- }, hr = {
710
- id: qn.id,
711
- binding: H.A | ve.CTRL_COMMAND,
712
- preconditions: (t) => t.getContextValue(dt) && (t.getContextValue(Ue) || t.getContextValue(qt))
725
+ }, SelectAllShortcut = {
726
+ id: SelectAllOperation.id,
727
+ binding: KeyCode.A | MetaKeys.CTRL_COMMAND,
728
+ preconditions: /* @__PURE__ */ __name((contextService) => contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && (contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED)), "preconditions")
713
729
  };
714
- var gr = Object.defineProperty, pr = Object.getOwnPropertyDescriptor, fr = (t, e, n, o) => {
715
- for (var r = o > 1 ? void 0 : o ? pr(e, n) : e, i = t.length - 1, s; i >= 0; i--)
716
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
717
- return o && r && gr(e, n, r), r;
718
- }, wt = (t, e) => (n, o) => e(n, o, t);
719
- let rt = class {
720
- constructor(t, e, n) {
721
- T(this, "_docContainer");
730
+ var __defProp$f = Object.defineProperty, __getOwnPropDesc$f = Object.getOwnPropertyDescriptor, __decorateClass$f = /* @__PURE__ */ __name((decorators, target, key, kind) => {
731
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$f(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
732
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
733
+ return kind && result && __defProp$f(target, key, result), result;
734
+ }, "__decorateClass$f"), __decorateParam$f = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$f"), _a3;
735
+ let DocContainerUIController = (_a3 = class {
736
+ constructor(_config, _localeService, _injector) {
737
+ __publicField(this, "_docContainer");
722
738
  // 获取SheetContainer组件
723
- T(this, "getComponent", (t) => {
724
- if (this._docContainer = t, !t.getContentRef().current)
739
+ __publicField(this, "getComponent", /* @__PURE__ */ __name((ref) => {
740
+ if (this._docContainer = ref, !ref.getContentRef().current)
725
741
  throw new Error("container is not ready");
726
- });
742
+ }, "getComponent"));
727
743
  /**
728
744
  * Change language
729
745
  * @param {string} lang new language
@@ -731,10 +747,10 @@ let rt = class {
731
747
  * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
732
748
  *
733
749
  */
734
- T(this, "changeLocale", (t) => {
735
- this._localeService.setLocale(t);
736
- });
737
- this._config = t, this._localeService = e, this._injector = n;
750
+ __publicField(this, "changeLocale", /* @__PURE__ */ __name((locale) => {
751
+ this._localeService.setLocale(locale);
752
+ }, "changeLocale"));
753
+ this._config = _config, this._localeService = _localeService, this._injector = _injector;
738
754
  }
739
755
  getUIConfig() {
740
756
  return {
@@ -747,27 +763,27 @@ let rt = class {
747
763
  getContentRef() {
748
764
  return this._docContainer.getContentRef();
749
765
  }
750
- UIDidMount(t) {
766
+ UIDidMount(cb) {
751
767
  if (this._docContainer)
752
- return t(this._docContainer);
768
+ return cb(this._docContainer);
753
769
  }
754
770
  getDocContainer() {
755
771
  return this._docContainer;
756
772
  }
757
- };
758
- rt = fr([
759
- wt(1, I(le)),
760
- wt(2, I($e))
761
- ], rt);
762
- var _r = Object.defineProperty, mr = Object.getOwnPropertyDescriptor, Sr = (t, e, n, o) => {
763
- for (var r = o > 1 ? void 0 : o ? mr(e, n) : e, i = t.length - 1, s; i >= 0; i--)
764
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
765
- return o && r && _r(e, n, r), r;
766
- }, Ce = (t, e) => (n, o) => e(n, o, t);
767
- let _e = class extends Se {
768
- constructor(e, n, o, r, i) {
773
+ }, __name(_a3, "DocContainerUIController"), _a3);
774
+ DocContainerUIController = __decorateClass$f([
775
+ __decorateParam$f(1, Inject(LocaleService)),
776
+ __decorateParam$f(2, Inject(Injector))
777
+ ], DocContainerUIController);
778
+ var __defProp$e = Object.defineProperty, __getOwnPropDesc$e = Object.getOwnPropertyDescriptor, __decorateClass$e = /* @__PURE__ */ __name((decorators, target, key, kind) => {
779
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$e(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
780
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
781
+ return kind && result && __defProp$e(target, key, result), result;
782
+ }, "__decorateClass$e"), __decorateParam$e = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$e"), _a4;
783
+ let AppUIController = (_a4 = class extends RxDisposable {
784
+ constructor(_config, _localeService, _injector, _textSelectionRenderManager, _layoutService) {
769
785
  super();
770
- T(this, "_docContainerController");
786
+ __publicField(this, "_docContainerController");
771
787
  /**
772
788
  * Change language
773
789
  * @param {string} locale new language
@@ -775,10 +791,10 @@ let _e = class extends Se {
775
791
  * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
776
792
  *
777
793
  */
778
- T(this, "changeLocale", (e) => {
779
- this._localeService.setLocale(e);
780
- });
781
- this._localeService = n, this._injector = o, this._textSelectionRenderManager = r, this._layoutService = i, this._docContainerController = this._injector.createInstance(rt, e), this._registerContainer();
794
+ __publicField(this, "changeLocale", /* @__PURE__ */ __name((locale) => {
795
+ this._localeService.setLocale(locale);
796
+ }, "changeLocale"));
797
+ this._localeService = _localeService, this._injector = _injector, this._textSelectionRenderManager = _textSelectionRenderManager, this._layoutService = _layoutService, this._docContainerController = this._injector.createInstance(DocContainerUIController, _config), this._registerContainer();
782
798
  }
783
799
  _registerContainer() {
784
800
  this._layoutService && this.disposeWithMe(
@@ -789,457 +805,508 @@ let _e = class extends Se {
789
805
  getDocContainerController() {
790
806
  return this._docContainerController;
791
807
  }
792
- };
793
- _e = Sr([
794
- Ce(1, I(le)),
795
- Ce(2, I($e)),
796
- Ce(3, ne),
797
- Ce(4, Xn(en))
798
- ], _e);
799
- const We = "UI_PLUGIN_DOCS", pt = `${We}_COLOR_PICKER_COMPONENT`, dn = `${We}_FONT_FAMILY_COMPONENT`, un = `${We}_FONT_FAMILY_ITEM_COMPONENT`, hn = `${We}_FONT_SIZE_COMPONENT`, Bt = 18, $t = 200, Ze = 6, vr = 4;
800
- function Rr(t, e) {
801
- let { radius: n, width: o, height: r } = e;
802
- n = n != null ? n : 0, o = o != null ? o : 30, r = r != null ? r : 30;
803
- let i = 0;
804
- i = Math.min(n, o / 2, r / 2), t.beginPath(), t.moveTo(0, 0), t.lineTo(o, 0), t.lineTo(o, r - i), t.arc(o - i, r - i, i, 0, Math.PI / 2, !1), t.lineTo(0, r), t.lineTo(0, 0), t.closePath(), e.fill && (t.save(), t.fillStyle = e.fill, e.fillRule === "evenodd" ? t.fill("evenodd") : t.fill(), t.restore());
808
+ }, __name(_a4, "AppUIController"), _a4);
809
+ AppUIController = __decorateClass$e([
810
+ __decorateParam$e(1, Inject(LocaleService)),
811
+ __decorateParam$e(2, Inject(Injector)),
812
+ __decorateParam$e(3, ITextSelectionRenderManager),
813
+ __decorateParam$e(4, Optional(ILayoutService))
814
+ ], AppUIController);
815
+ const COMPONENT_PREFIX = "UI_PLUGIN_DOCS", COLOR_PICKER_COMPONENT = `${COMPONENT_PREFIX}_COLOR_PICKER_COMPONENT`, FONT_FAMILY_COMPONENT = `${COMPONENT_PREFIX}_FONT_FAMILY_COMPONENT`, FONT_FAMILY_ITEM_COMPONENT = `${COMPONENT_PREFIX}_FONT_FAMILY_ITEM_COMPONENT`, FONT_SIZE_COMPONENT = `${COMPONENT_PREFIX}_FONT_SIZE_COMPONENT`;
816
+ var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
817
+ /**
818
+ * @license React
819
+ * react-jsx-runtime.production.min.js
820
+ *
821
+ * Copyright (c) Facebook, Inc. and its affiliates.
822
+ *
823
+ * This source code is licensed under the MIT license found in the
824
+ * LICENSE file in the root directory of this source tree.
825
+ */
826
+ var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
827
+ function q(c, a, g) {
828
+ var b, d = {}, e = null, h = null;
829
+ g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
830
+ for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
831
+ if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
832
+ return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
833
+ }
834
+ __name(q, "q");
835
+ reactJsxRuntime_production_min.Fragment = l;
836
+ reactJsxRuntime_production_min.jsx = q;
837
+ reactJsxRuntime_production_min.jsxs = q;
838
+ jsxRuntime.exports = reactJsxRuntime_production_min;
839
+ var jsxRuntimeExports = jsxRuntime.exports;
840
+ const docCountBar = "univer-doc-count-bar", styles$2 = {
841
+ docCountBar
842
+ }, ZOOM_MAP = [50, 80, 100, 130, 150, 170, 200, 400], DOC_ZOOM_RANGE = [10, 400];
843
+ function ZoomSlider() {
844
+ const commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), currentDoc$ = useMemo(() => univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC), []), documentDataModel = useObservable(currentDoc$), getCurrentZoom = useCallback(() => {
845
+ var _a19, _b;
846
+ if (!documentDataModel) return 100;
847
+ const currentZoom = ((_b = (_a19 = documentDataModel.getSettings()) == null ? void 0 : _a19.zoomRatio) != null ? _b : 1) * 100;
848
+ return Math.round(currentZoom);
849
+ }, [documentDataModel]), [zoom, setZoom] = useState(() => getCurrentZoom());
850
+ useEffect(() => (setZoom(getCurrentZoom()), commandService.onCommandExecuted((commandInfo) => {
851
+ if (commandInfo.id === SetDocZoomRatioOperation.id) {
852
+ const currentZoom = getCurrentZoom();
853
+ setZoom(currentZoom);
854
+ }
855
+ }).dispose), [commandService, getCurrentZoom]);
856
+ function handleChange(value) {
857
+ if (setZoom(value), documentDataModel == null)
858
+ return;
859
+ const zoomRatio = value / 100;
860
+ commandService.executeCommand(SetDocZoomRatioOperation.id, {
861
+ unitId: documentDataModel.getUnitId(),
862
+ zoomRatio
863
+ });
864
+ }
865
+ return __name(handleChange, "handleChange"), /* @__PURE__ */ jsxRuntimeExports.jsx(
866
+ Slider,
867
+ {
868
+ min: DOC_ZOOM_RANGE[0],
869
+ value: zoom,
870
+ shortcuts: ZOOM_MAP,
871
+ onChange: handleChange
872
+ }
873
+ );
805
874
  }
806
- class Ne extends Eo {
807
- constructor(n, o) {
808
- super(n, o);
809
- T(this, "color");
810
- T(this, "text");
811
- this.color = o == null ? void 0 : o.color, this.text = o == null ? void 0 : o.text;
812
- }
813
- static drawWith(n, o) {
814
- const { text: r, color: i } = o;
815
- n.save(), n.font = "13px Source Han Sans CN";
816
- const s = n.measureText(r).width, a = Math.min(
817
- s + 2 * Ze,
818
- $t
875
+ __name(ZoomSlider, "ZoomSlider");
876
+ function CountBar(props) {
877
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("section", { className: styles$2.docCountBar, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ZoomSlider, {}) });
878
+ }
879
+ __name(CountBar, "CountBar");
880
+ const docFooterContainer = "univer-doc-footer-container", styles$1 = {
881
+ docFooterContainer
882
+ }, DocFooter = /* @__PURE__ */ __name(() => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.docFooterContainer, children: [
883
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", {}),
884
+ /* @__PURE__ */ jsxRuntimeExports.jsx(CountBar, {})
885
+ ] }), "DocFooter"), COLLAB_CURSOR_LABEL_HEIGHT = 18, COLLAB_CURSOR_LABEL_MAX_WIDTH = 200, COLLAB_CURSOR_LABEL_TEXT_PADDING_LR = 6, COLLAB_CURSOR_LABEL_TEXT_PADDING_TB = 4;
886
+ function drawBubble(ctx, props) {
887
+ let { radius, width, height } = props;
888
+ radius = radius != null ? radius : 0, width = width != null ? width : 30, height = height != null ? height : 30;
889
+ let bottomRight = 0;
890
+ bottomRight = Math.min(radius, width / 2, height / 2), ctx.beginPath(), ctx.moveTo(0, 0), ctx.lineTo(width, 0), ctx.lineTo(width, height - bottomRight), ctx.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, !1), ctx.lineTo(0, height), ctx.lineTo(0, 0), ctx.closePath(), props.fill && (ctx.save(), ctx.fillStyle = props.fill, props.fillRule === "evenodd" ? ctx.fill("evenodd") : ctx.fill(), ctx.restore());
891
+ }
892
+ __name(drawBubble, "drawBubble");
893
+ const _TextBubbleShape = class _TextBubbleShape extends Shape {
894
+ constructor(key, props) {
895
+ super(key, props);
896
+ __publicField(this, "color");
897
+ __publicField(this, "text");
898
+ this.color = props == null ? void 0 : props.color, this.text = props == null ? void 0 : props.text;
899
+ }
900
+ static drawWith(ctx, props) {
901
+ const { text, color } = props;
902
+ ctx.save(), ctx.font = "13px Source Han Sans CN";
903
+ const textWidth = ctx.measureText(text).width, realInfoWidth = Math.min(
904
+ textWidth + 2 * COLLAB_CURSOR_LABEL_TEXT_PADDING_LR,
905
+ COLLAB_CURSOR_LABEL_MAX_WIDTH
819
906
  );
820
- Rr(n, {
821
- height: Bt,
822
- width: a,
907
+ drawBubble(ctx, {
908
+ height: COLLAB_CURSOR_LABEL_HEIGHT,
909
+ width: realInfoWidth,
823
910
  radius: 4,
824
- fill: i,
911
+ fill: color,
825
912
  evented: !1
826
- }), n.fillStyle = "rgba(58, 96, 247, 1)";
827
- const c = Ze, d = Bt - vr, g = $t - 2 * Ze;
828
- if (s > g) {
829
- let h = "", p = 0;
830
- for (const l of r) {
831
- const f = n.measureText(l).width;
832
- if (p + f <= g - n.measureText("...").width)
833
- h += l, p += f;
913
+ }), ctx.fillStyle = "rgba(58, 96, 247, 1)";
914
+ const offsetX = COLLAB_CURSOR_LABEL_TEXT_PADDING_LR, offsetY = COLLAB_CURSOR_LABEL_HEIGHT - COLLAB_CURSOR_LABEL_TEXT_PADDING_TB, maxTextWidth = COLLAB_CURSOR_LABEL_MAX_WIDTH - 2 * COLLAB_CURSOR_LABEL_TEXT_PADDING_LR;
915
+ if (textWidth > maxTextWidth) {
916
+ let truncatedText = "", currentWidth = 0;
917
+ for (const element of text) {
918
+ const charWidth = ctx.measureText(element).width;
919
+ if (currentWidth + charWidth <= maxTextWidth - ctx.measureText("...").width)
920
+ truncatedText += element, currentWidth += charWidth;
834
921
  else {
835
- h += "...";
922
+ truncatedText += "...";
836
923
  break;
837
924
  }
838
925
  }
839
- n.fillText(h, c, d);
926
+ ctx.fillText(truncatedText, offsetX, offsetY);
840
927
  } else
841
- n.fillText(r, c, d);
842
- n.restore();
928
+ ctx.fillText(text, offsetX, offsetY);
929
+ ctx.restore();
843
930
  }
844
- _draw(n) {
845
- Ne.drawWith(n, this);
931
+ _draw(ctx) {
932
+ _TextBubbleShape.drawWith(ctx, this);
846
933
  }
847
- }
848
- const gn = "COMPONENT_DOC_HEADER_FOOTER_PANEL";
849
- var pn = { exports: {} }, ke = {};
850
- /**
851
- * @license React
852
- * react-jsx-runtime.production.min.js
853
- *
854
- * Copyright (c) Facebook, Inc. and its affiliates.
855
- *
856
- * This source code is licensed under the MIT license found in the
857
- * LICENSE file in the root directory of this source tree.
858
- */
859
- var Or = Po, Cr = Symbol.for("react.element"), Er = Symbol.for("react.fragment"), Tr = Object.prototype.hasOwnProperty, Ir = Or.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, br = { key: !0, ref: !0, __self: !0, __source: !0 };
860
- function fn(t, e, n) {
861
- var o, r = {}, i = null, s = null;
862
- n !== void 0 && (i = "" + n), e.key !== void 0 && (i = "" + e.key), e.ref !== void 0 && (s = e.ref);
863
- for (o in e) Tr.call(e, o) && !br.hasOwnProperty(o) && (r[o] = e[o]);
864
- if (t && t.defaultProps) for (o in e = t.defaultProps, e) r[o] === void 0 && (r[o] = e[o]);
865
- return { $$typeof: Cr, type: t, key: i, ref: s, props: r, _owner: Ir.current };
866
- }
867
- ke.Fragment = Er;
868
- ke.jsx = fn;
869
- ke.jsxs = fn;
870
- pn.exports = ke;
871
- var M = pn.exports;
872
- const Mr = "univer-panel", yr = "univer-options-section", xr = "univer-options-form-item", Pr = "univer-options-input", Dr = "univer-options-margin-setting", $ = {
873
- panel: Mr,
874
- optionsSection: yr,
875
- optionsFormItem: xr,
876
- optionsInput: Pr,
877
- optionsMarginSetting: Dr
878
- }, Ar = (t) => {
879
- const e = z(le), n = z(w), o = z(W), r = z(O), i = z(ne), s = z(te), { unitId: a } = t, [c, d] = an({}), g = (l, f) => {
880
- var N;
881
- d((Y) => ({
882
- ...Y,
883
- [f]: l ? S.TRUE : S.FALSE
934
+ };
935
+ __name(_TextBubbleShape, "TextBubbleShape");
936
+ let TextBubbleShape = _TextBubbleShape;
937
+ const COMPONENT_DOC_HEADER_FOOTER_PANEL = "COMPONENT_DOC_HEADER_FOOTER_PANEL", panel = "univer-panel", optionsSection = "univer-options-section", optionsFormItem = "univer-options-form-item", optionsInput = "univer-options-input", optionsMarginSetting = "univer-options-margin-setting", styles = {
938
+ panel,
939
+ optionsSection,
940
+ optionsFormItem,
941
+ optionsInput,
942
+ optionsMarginSetting
943
+ }, DocHeaderFooterOptions = /* @__PURE__ */ __name((props) => {
944
+ const localeService = useDependency(LocaleService), univerInstanceService = useDependency(IUniverInstanceService), renderManagerService = useDependency(IRenderManagerService), commandService = useDependency(ICommandService), textSelectionRenderService = useDependency(ITextSelectionRenderManager), textSelectionManagerService = useDependency(TextSelectionManagerService), { unitId } = props, [options, setOptions] = useState({}), handleCheckboxChange = /* @__PURE__ */ __name((val, type) => {
945
+ var _a19;
946
+ setOptions((prev) => ({
947
+ ...prev,
948
+ [type]: val ? BooleanNumber.TRUE : BooleanNumber.FALSE
884
949
  }));
885
- const u = n.getUniverDocInstance(a), _ = u == null ? void 0 : u.getSnapshot().documentStyle, m = (N = o.getRenderById(a)) == null ? void 0 : N.with(L), R = m == null ? void 0 : m.getViewModel();
886
- if (_ == null || R == null)
950
+ const docDataModel = univerInstanceService.getUniverDocInstance(unitId), documentStyle = docDataModel == null ? void 0 : docDataModel.getSnapshot().documentStyle, docSkeletonManagerService = (_a19 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a19.with(DocSkeletonManagerService), viewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel();
951
+ if (documentStyle == null || viewModel == null)
887
952
  return;
888
- const C = R.getEditArea();
889
- let E = !1;
890
- const b = i.getSegmentPage();
891
- let A = !1;
892
- if (f === "useFirstPageHeaderFooter" && l === !0 && ((C === F.HEADER && !_.firstPageHeaderId || C === F.FOOTER && !_.firstPageFooterId) && (E = !0), E && b === 0 && (A = !0)), f === "evenAndOddHeaders" && l === !0 && ((C === F.HEADER && !_.evenPageHeaderId || C === F.FOOTER && !_.evenPageFooterId) && (E = !0), E && b % 2 === 1 && (A = !0)), E) {
893
- const G = j.generateRandomId(6);
894
- A && i.setSegment(G), r.executeCommand(be, {
895
- unitId: a,
896
- segmentId: G,
953
+ const editArea = viewModel.getEditArea();
954
+ let needCreateHeaderFooter = !1;
955
+ const segmentPage = textSelectionRenderService.getSegmentPage();
956
+ let needChangeSegmentId = !1;
957
+ if (type === "useFirstPageHeaderFooter" && val === !0 && ((editArea === DocumentEditArea.HEADER && !documentStyle.firstPageHeaderId || editArea === DocumentEditArea.FOOTER && !documentStyle.firstPageFooterId) && (needCreateHeaderFooter = !0), needCreateHeaderFooter && segmentPage === 0 && (needChangeSegmentId = !0)), type === "evenAndOddHeaders" && val === !0 && ((editArea === DocumentEditArea.HEADER && !documentStyle.evenPageHeaderId || editArea === DocumentEditArea.FOOTER && !documentStyle.evenPageFooterId) && (needCreateHeaderFooter = !0), needCreateHeaderFooter && segmentPage % 2 === 1 && (needChangeSegmentId = !0)), needCreateHeaderFooter) {
958
+ const segmentId = Tools.generateRandomId(6);
959
+ needChangeSegmentId && textSelectionRenderService.setSegment(segmentId), commandService.executeCommand(CoreHeaderFooterCommandId, {
960
+ unitId,
961
+ segmentId,
897
962
  headerFooterProps: {
898
- [f]: l ? S.TRUE : S.FALSE
963
+ [type]: val ? BooleanNumber.TRUE : BooleanNumber.FALSE
899
964
  }
900
965
  });
901
966
  } else
902
- r.executeCommand(be, {
903
- unitId: a,
967
+ commandService.executeCommand(CoreHeaderFooterCommandId, {
968
+ unitId,
904
969
  headerFooterProps: {
905
- [f]: l ? S.TRUE : S.FALSE
970
+ [type]: val ? BooleanNumber.TRUE : BooleanNumber.FALSE
906
971
  }
907
972
  });
908
- }, h = async (l, f) => {
909
- d((u) => ({
910
- ...u,
911
- [f]: l
912
- })), await r.executeCommand(be, {
913
- unitId: a,
973
+ }, "handleCheckboxChange"), handleMarginChange = /* @__PURE__ */ __name(async (val, type) => {
974
+ setOptions((prev) => ({
975
+ ...prev,
976
+ [type]: val
977
+ })), await commandService.executeCommand(CoreHeaderFooterCommandId, {
978
+ unitId,
914
979
  headerFooterProps: {
915
- [f]: l
980
+ [type]: val
916
981
  }
917
- }), i.removeAllTextRanges(), i.blur();
918
- }, p = () => {
919
- var E;
920
- const l = o.getRenderById(a);
921
- if (l == null)
982
+ }), textSelectionRenderService.removeAllTextRanges(), textSelectionRenderService.blur();
983
+ }, "handleMarginChange"), closeHeaderFooter = /* @__PURE__ */ __name(() => {
984
+ var _a19;
985
+ const renderObject = renderManagerService.getRenderById(unitId);
986
+ if (renderObject == null)
922
987
  return;
923
- const { scene: f } = l, u = f.getTransformerByCreate(), _ = l.with(L), m = _ == null ? void 0 : _.getSkeleton(), R = _ == null ? void 0 : _.getViewModel(), C = o.getRenderById(a);
924
- C == null || R == null || m == null || (s.replaceTextRanges([]), u.clearSelectedObjects(), i.setSegment(""), i.setSegmentPage(-1), R.setEditArea(F.BODY), m.calculate(), (E = C.mainComponent) == null || E.makeDirty(!0));
925
- };
926
- return cn(() => {
927
- const l = n.getUniverDocInstance(a), f = l == null ? void 0 : l.getSnapshot().documentStyle;
928
- if (f) {
929
- const { marginHeader: u, marginFooter: _, useFirstPageHeaderFooter: m, evenAndOddHeaders: R } = f;
930
- d({
931
- marginHeader: u,
932
- marginFooter: _,
933
- useFirstPageHeaderFooter: m,
934
- evenAndOddHeaders: R
988
+ const { scene } = renderObject, transformer = scene.getTransformerByCreate(), docSkeletonManagerService = renderObject.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton(), viewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel(), render = renderManagerService.getRenderById(unitId);
989
+ render == null || viewModel == null || skeleton == null || (textSelectionManagerService.replaceTextRanges([]), transformer.clearSelectedObjects(), textSelectionRenderService.setSegment(""), textSelectionRenderService.setSegmentPage(-1), viewModel.setEditArea(DocumentEditArea.BODY), skeleton.calculate(), (_a19 = render.mainComponent) == null || _a19.makeDirty(!0));
990
+ }, "closeHeaderFooter");
991
+ return useEffect(() => {
992
+ const docDataModel = univerInstanceService.getUniverDocInstance(unitId), documentStyle = docDataModel == null ? void 0 : docDataModel.getSnapshot().documentStyle;
993
+ if (documentStyle) {
994
+ const { marginHeader, marginFooter, useFirstPageHeaderFooter, evenAndOddHeaders } = documentStyle;
995
+ setOptions({
996
+ marginHeader,
997
+ marginFooter,
998
+ useFirstPageHeaderFooter,
999
+ evenAndOddHeaders
935
1000
  });
936
1001
  }
937
- }, [a]), /* @__PURE__ */ M.jsxs("div", { className: $.options, children: [
938
- /* @__PURE__ */ M.jsxs("div", { className: $.optionsSection, children: [
939
- /* @__PURE__ */ M.jsx("div", { className: $.optionsFormItem, children: /* @__PURE__ */ M.jsx(
940
- Pt,
1002
+ }, [unitId]), /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.options, children: [
1003
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.optionsSection, children: [
1004
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.optionsFormItem, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1005
+ Checkbox,
941
1006
  {
942
- checked: c.useFirstPageHeaderFooter === S.TRUE,
943
- onChange: (l) => {
944
- g(l, "useFirstPageHeaderFooter");
945
- },
946
- children: e.t("headerFooter.firstPageCheckBox")
1007
+ checked: options.useFirstPageHeaderFooter === BooleanNumber.TRUE,
1008
+ onChange: /* @__PURE__ */ __name((val) => {
1009
+ handleCheckboxChange(val, "useFirstPageHeaderFooter");
1010
+ }, "onChange"),
1011
+ children: localeService.t("headerFooter.firstPageCheckBox")
947
1012
  }
948
1013
  ) }),
949
- /* @__PURE__ */ M.jsx("div", { className: $.optionsFormItem, children: /* @__PURE__ */ M.jsx(
950
- Pt,
1014
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.optionsFormItem, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1015
+ Checkbox,
951
1016
  {
952
- checked: c.evenAndOddHeaders === S.TRUE,
953
- onChange: (l) => {
954
- g(l, "evenAndOddHeaders");
955
- },
956
- children: e.t("headerFooter.oddEvenCheckBox")
1017
+ checked: options.evenAndOddHeaders === BooleanNumber.TRUE,
1018
+ onChange: /* @__PURE__ */ __name((val) => {
1019
+ handleCheckboxChange(val, "evenAndOddHeaders");
1020
+ }, "onChange"),
1021
+ children: localeService.t("headerFooter.oddEvenCheckBox")
957
1022
  }
958
1023
  ) })
959
1024
  ] }),
960
- /* @__PURE__ */ M.jsxs("div", { className: No($.optionsSection, $.optionsMarginSetting), children: [
961
- /* @__PURE__ */ M.jsxs("div", { className: $.optionsMarginItem, children: [
962
- /* @__PURE__ */ M.jsx("span", { children: e.t("headerFooter.headerTopMargin") }),
963
- /* @__PURE__ */ M.jsx(
964
- Dt,
1025
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: clsx(styles.optionsSection, styles.optionsMarginSetting), children: [
1026
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.optionsMarginItem, children: [
1027
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: localeService.t("headerFooter.headerTopMargin") }),
1028
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1029
+ InputNumber,
965
1030
  {
966
1031
  min: 0,
967
1032
  max: 200,
968
1033
  precision: 1,
969
- value: c.marginHeader,
970
- onChange: (l) => {
971
- h(l, "marginHeader");
972
- },
973
- className: $.optionsInput
1034
+ value: options.marginHeader,
1035
+ onChange: /* @__PURE__ */ __name((val) => {
1036
+ handleMarginChange(val, "marginHeader");
1037
+ }, "onChange"),
1038
+ className: styles.optionsInput
974
1039
  }
975
1040
  )
976
1041
  ] }),
977
- /* @__PURE__ */ M.jsxs("div", { className: $.optionsMarginItem, children: [
978
- /* @__PURE__ */ M.jsx("span", { children: e.t("headerFooter.footerBottomMargin") }),
979
- /* @__PURE__ */ M.jsx(
980
- Dt,
1042
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.optionsMarginItem, children: [
1043
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: localeService.t("headerFooter.footerBottomMargin") }),
1044
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1045
+ InputNumber,
981
1046
  {
982
1047
  min: 0,
983
1048
  max: 200,
984
1049
  precision: 1,
985
- value: c.marginFooter,
986
- onChange: (l) => {
987
- h(l, "marginFooter");
988
- },
989
- className: $.optionsInput
1050
+ value: options.marginFooter,
1051
+ onChange: /* @__PURE__ */ __name((val) => {
1052
+ handleMarginChange(val, "marginFooter");
1053
+ }, "onChange"),
1054
+ className: styles.optionsInput
990
1055
  }
991
1056
  )
992
1057
  ] })
993
1058
  ] }),
994
- /* @__PURE__ */ M.jsx("div", { className: $.optionsSection, children: /* @__PURE__ */ M.jsx(Do, { onClick: p, children: e.t("headerFooter.closeHeaderFooter") }) })
1059
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.optionsSection, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: closeHeaderFooter, children: localeService.t("headerFooter.closeHeaderFooter") }) })
995
1060
  ] });
996
- }, Nr = () => {
997
- var d;
998
- const t = z(le), e = z(W), r = z(w).getCurrentUniverDocInstance().getUnitId(), s = ((d = e.getRenderById(r)) == null ? void 0 : d.with(L)).getViewModel(), [a, c] = an(!0);
999
- return cn(() => {
1000
- const g = s.getEditArea();
1001
- c(g !== F.BODY);
1002
- const h = s.editAreaChange$.subscribe((p) => {
1003
- p != null && c(p !== F.BODY);
1061
+ }, "DocHeaderFooterOptions"), DocHeaderFooterPanel = /* @__PURE__ */ __name(() => {
1062
+ var _a19;
1063
+ const localeService = useDependency(LocaleService), renderManagerService = useDependency(IRenderManagerService), unitId = useDependency(IUniverInstanceService).getCurrentUniverDocInstance().getUnitId(), viewModel = ((_a19 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a19.with(DocSkeletonManagerService)).getViewModel(), [isEditHeaderFooter, setIsEditHeaderFooter] = useState(!0);
1064
+ return useEffect(() => {
1065
+ const editArea = viewModel.getEditArea();
1066
+ setIsEditHeaderFooter(editArea !== DocumentEditArea.BODY);
1067
+ const subscription = viewModel.editAreaChange$.subscribe((editArea2) => {
1068
+ editArea2 != null && setIsEditHeaderFooter(editArea2 !== DocumentEditArea.BODY);
1004
1069
  });
1005
1070
  return () => {
1006
- h.unsubscribe();
1071
+ subscription.unsubscribe();
1007
1072
  };
1008
- }, []), /* @__PURE__ */ M.jsx("div", { className: $.panel, children: a ? /* @__PURE__ */ M.jsx(Ar, { unitId: r }) : /* @__PURE__ */ M.jsx("div", { className: $.panelDisableText, children: t.t("headerFooter.disableText") }) });
1009
- }, _n = {
1073
+ }, []), /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.panel, children: isEditHeaderFooter ? /* @__PURE__ */ jsxRuntimeExports.jsx(DocHeaderFooterOptions, { unitId }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.panelDisableText, children: localeService.t("headerFooter.disableText") }) });
1074
+ }, "DocHeaderFooterPanel"), SidebarDocHeaderFooterPanelOperation = {
1010
1075
  id: "sidebar.operation.doc-header-footer-panel",
1011
- type: de.COMMAND,
1012
- handler: async (t, e) => {
1013
- const n = t.get(Fn), o = t.get(le);
1014
- switch (e.value) {
1076
+ type: CommandType.COMMAND,
1077
+ handler: /* @__PURE__ */ __name(async (accessor, params) => {
1078
+ const sidebarService = accessor.get(ISidebarService), localeService = accessor.get(LocaleService);
1079
+ switch (params.value) {
1015
1080
  case "open":
1016
- n.open({
1017
- header: { title: o.t("headerFooter.panel") },
1018
- children: { label: gn },
1019
- onClose: () => {
1020
- },
1081
+ sidebarService.open({
1082
+ header: { title: localeService.t("headerFooter.panel") },
1083
+ children: { label: COMPONENT_DOC_HEADER_FOOTER_PANEL },
1084
+ onClose: /* @__PURE__ */ __name(() => {
1085
+ }, "onClose"),
1021
1086
  width: 400
1022
1087
  });
1023
1088
  break;
1024
1089
  case "close":
1025
1090
  default:
1026
- n.close();
1091
+ sidebarService.close();
1027
1092
  break;
1028
1093
  }
1029
1094
  return !0;
1030
- }
1095
+ }, "handler")
1031
1096
  };
1032
- var Fr = Object.defineProperty, Ur = Object.getOwnPropertyDescriptor, Lr = (t, e, n, o) => {
1033
- for (var r = o > 1 ? void 0 : o ? Ur(e, n) : e, i = t.length - 1, s; i >= 0; i--)
1034
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
1035
- return o && r && Fr(e, n, r), r;
1036
- }, X = (t, e) => (n, o) => e(n, o, t);
1037
- const Ht = "rgba(58, 96, 247, 1)", Vt = "rgba(58, 96, 247, 0.08)";
1038
- var U = /* @__PURE__ */ ((t) => (t[t.FIRST_PAGE_HEADER = 0] = "FIRST_PAGE_HEADER", t[t.FIRST_PAGE_FOOTER = 1] = "FIRST_PAGE_FOOTER", t[t.DEFAULT_HEADER = 2] = "DEFAULT_HEADER", t[t.DEFAULT_FOOTER = 3] = "DEFAULT_FOOTER", t[t.EVEN_PAGE_HEADER = 4] = "EVEN_PAGE_HEADER", t[t.EVEN_PAGE_FOOTER = 5] = "EVEN_PAGE_FOOTER", t))(U || {});
1039
- function wr(t, e, n) {
1040
- const { documentStyle: o } = t.getDataModel().getSnapshot(), {
1041
- defaultHeaderId: r,
1042
- defaultFooterId: i,
1043
- evenPageHeaderId: s,
1044
- evenPageFooterId: a,
1045
- firstPageHeaderId: c,
1046
- firstPageFooterId: d,
1047
- evenAndOddHeaders: g,
1048
- useFirstPageHeaderFooter: h
1049
- } = o;
1050
- switch (e) {
1051
- case F.BODY:
1097
+ var __defProp$d = Object.defineProperty, __getOwnPropDesc$d = Object.getOwnPropertyDescriptor, __decorateClass$d = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1098
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$d(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1099
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1100
+ return kind && result && __defProp$d(target, key, result), result;
1101
+ }, "__decorateClass$d"), __decorateParam$d = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$d");
1102
+ const HEADER_FOOTER_STROKE_COLOR = "rgba(58, 96, 247, 1)", HEADER_FOOTER_FILL_COLOR = "rgba(58, 96, 247, 0.08)";
1103
+ var HeaderFooterType = /* @__PURE__ */ ((HeaderFooterType2) => (HeaderFooterType2[HeaderFooterType2.FIRST_PAGE_HEADER = 0] = "FIRST_PAGE_HEADER", HeaderFooterType2[HeaderFooterType2.FIRST_PAGE_FOOTER = 1] = "FIRST_PAGE_FOOTER", HeaderFooterType2[HeaderFooterType2.DEFAULT_HEADER = 2] = "DEFAULT_HEADER", HeaderFooterType2[HeaderFooterType2.DEFAULT_FOOTER = 3] = "DEFAULT_FOOTER", HeaderFooterType2[HeaderFooterType2.EVEN_PAGE_HEADER = 4] = "EVEN_PAGE_HEADER", HeaderFooterType2[HeaderFooterType2.EVEN_PAGE_FOOTER = 5] = "EVEN_PAGE_FOOTER", HeaderFooterType2))(HeaderFooterType || {});
1104
+ function checkCreateHeaderFooterType(viewModel, editArea, segmentPage) {
1105
+ const { documentStyle } = viewModel.getDataModel().getSnapshot(), {
1106
+ defaultHeaderId,
1107
+ defaultFooterId,
1108
+ evenPageHeaderId,
1109
+ evenPageFooterId,
1110
+ firstPageHeaderId,
1111
+ firstPageFooterId,
1112
+ evenAndOddHeaders,
1113
+ useFirstPageHeaderFooter
1114
+ } = documentStyle;
1115
+ switch (editArea) {
1116
+ case DocumentEditArea.BODY:
1052
1117
  return {
1053
1118
  createType: null,
1054
1119
  headerFooterId: null
1055
1120
  };
1056
- case F.HEADER:
1057
- return h === S.TRUE && !c ? {
1121
+ case DocumentEditArea.HEADER:
1122
+ return useFirstPageHeaderFooter === BooleanNumber.TRUE && !firstPageHeaderId ? {
1058
1123
  createType: 0,
1059
1124
  headerFooterId: null
1060
- } : g === S.TRUE && n % 2 === 0 && !s ? {
1125
+ } : evenAndOddHeaders === BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageHeaderId ? {
1061
1126
  createType: 4,
1062
1127
  headerFooterId: null
1063
- } : r ? {
1128
+ } : defaultHeaderId ? {
1064
1129
  createType: null,
1065
- headerFooterId: r
1130
+ headerFooterId: defaultHeaderId
1066
1131
  } : {
1067
1132
  createType: 2,
1068
1133
  headerFooterId: null
1069
1134
  };
1070
- case F.FOOTER:
1071
- return h === S.TRUE && !d ? {
1135
+ case DocumentEditArea.FOOTER:
1136
+ return useFirstPageHeaderFooter === BooleanNumber.TRUE && !firstPageFooterId ? {
1072
1137
  createType: 1,
1073
1138
  headerFooterId: null
1074
- } : g === S.TRUE && n % 2 === 0 && !a ? {
1139
+ } : evenAndOddHeaders === BooleanNumber.TRUE && segmentPage % 2 === 0 && !evenPageFooterId ? {
1075
1140
  createType: 5,
1076
1141
  headerFooterId: null
1077
- } : i ? {
1142
+ } : defaultFooterId ? {
1078
1143
  createType: null,
1079
- headerFooterId: i
1144
+ headerFooterId: defaultFooterId
1080
1145
  } : {
1081
1146
  createType: 3,
1082
1147
  headerFooterId: null
1083
1148
  };
1084
1149
  default:
1085
- throw new Error(`Invalid editArea: ${e}`);
1150
+ throw new Error(`Invalid editArea: ${editArea}`);
1086
1151
  }
1087
1152
  }
1088
- let it = class extends Q {
1089
- constructor(e, n, o, r, i, s, a, c, d) {
1153
+ __name(checkCreateHeaderFooterType, "checkCreateHeaderFooterType");
1154
+ var _a5;
1155
+ let DocHeaderFooterController = (_a5 = class extends Disposable {
1156
+ constructor(_context, _commandService, _editorService, _instanceSrv, _renderManagerService, _docSkeletonManagerService, _textSelectionRenderManager, _localeService, _componentManager) {
1090
1157
  super();
1091
- T(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
1092
- this._context = e, this._commandService = n, this._editorService = o, this._instanceSrv = r, this._renderManagerService = i, this._docSkeletonManagerService = s, this._textSelectionRenderManager = a, this._localeService = c, this._componentManager = d, this._initialize();
1158
+ __publicField(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
1159
+ this._context = _context, this._commandService = _commandService, this._editorService = _editorService, this._instanceSrv = _instanceSrv, this._renderManagerService = _renderManagerService, this._docSkeletonManagerService = _docSkeletonManagerService, this._textSelectionRenderManager = _textSelectionRenderManager, this._localeService = _localeService, this._componentManager = _componentManager, this._initialize();
1093
1160
  }
1094
1161
  _initialize() {
1095
- this._context.unit.getSnapshot().documentStyle.documentFlavor === Tn.TRADITIONAL && (this._init(), this._drawHeaderFooterLabel(), this._registerCommands(), this._initCustomComponents());
1162
+ this._context.unit.getSnapshot().documentStyle.documentFlavor === DocumentFlavor.TRADITIONAL && (this._init(), this._drawHeaderFooterLabel(), this._registerCommands(), this._initCustomComponents());
1096
1163
  }
1097
1164
  _registerCommands() {
1098
1165
  [
1099
- Wt,
1100
- mn,
1101
- _n
1102
- ].forEach((e) => this.disposeWithMe(this._commandService.registerCommand(e)));
1166
+ CoreHeaderFooterCommand,
1167
+ OpenHeaderFooterPanelCommand,
1168
+ SidebarDocHeaderFooterPanelOperation
1169
+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
1103
1170
  }
1104
1171
  _initCustomComponents() {
1105
- const e = this._componentManager;
1106
- this.disposeWithMe(e.register(gn, Nr));
1172
+ const componentManager = this._componentManager;
1173
+ this.disposeWithMe(componentManager.register(COMPONENT_DOC_HEADER_FOOTER_PANEL, DocHeaderFooterPanel));
1107
1174
  }
1108
1175
  _init() {
1109
- const { unitId: e } = this._context, n = J(this._context);
1110
- n == null || n.document == null || this._loadedMap.has(n.document) || (this._initialMain(e), this._loadedMap.add(n.document));
1176
+ const { unitId } = this._context, docObject = neoGetDocObject(this._context);
1177
+ docObject == null || docObject.document == null || this._loadedMap.has(docObject.document) || (this._initialMain(unitId), this._loadedMap.add(docObject.document));
1111
1178
  }
1112
- _initialMain(e) {
1113
- const n = J(this._context), { document: o } = n;
1114
- this.disposeWithMe(o.onDblclick$.subscribeEvent(async (r) => {
1115
- if (this._isEditorReadOnly(e))
1179
+ _initialMain(unitId) {
1180
+ const docObject = neoGetDocObject(this._context), { document } = docObject;
1181
+ this.disposeWithMe(document.onDblclick$.subscribeEvent(async (evt) => {
1182
+ if (this._isEditorReadOnly(unitId))
1116
1183
  return;
1117
- const { offsetX: i, offsetY: s } = r, {
1118
- pageLayoutType: a = Ae.VERTICAL,
1119
- pageMarginLeft: c,
1120
- pageMarginTop: d
1121
- } = o.getOffsetConfig(), g = this._getTransformCoordForDocumentOffset(i, s);
1122
- if (g == null)
1184
+ const { offsetX, offsetY } = evt, {
1185
+ pageLayoutType = PageLayoutType.VERTICAL,
1186
+ pageMarginLeft,
1187
+ pageMarginTop
1188
+ } = document.getOffsetConfig(), coord = this._getTransformCoordForDocumentOffset(offsetX, offsetY);
1189
+ if (coord == null)
1123
1190
  return;
1124
- const h = this._docSkeletonManagerService.getViewModel(), p = this._docSkeletonManagerService.getSkeleton(), l = h.getEditArea(), { editArea: f, pageNumber: u } = p.findEditAreaByCoord(
1125
- g,
1126
- a,
1127
- c,
1128
- d
1191
+ const viewModel = this._docSkeletonManagerService.getViewModel(), skeleton = this._docSkeletonManagerService.getSkeleton(), preEditArea = viewModel.getEditArea(), { editArea, pageNumber } = skeleton.findEditAreaByCoord(
1192
+ coord,
1193
+ pageLayoutType,
1194
+ pageMarginLeft,
1195
+ pageMarginTop
1129
1196
  );
1130
- if (l === f)
1197
+ if (preEditArea === editArea)
1131
1198
  return;
1132
- h.setEditArea(f);
1133
- const { createType: _, headerFooterId: m } = wr(h, f, u);
1134
- if (f === F.BODY)
1135
- this._textSelectionRenderManager.setSegment(""), this._textSelectionRenderManager.setSegmentPage(-1), this._textSelectionRenderManager.setCursorManually(i, s);
1136
- else if (_ != null) {
1137
- const C = j.generateRandomId(6);
1138
- this._textSelectionRenderManager.setSegment(C), this._textSelectionRenderManager.setSegmentPage(u), await this._commandService.executeCommand(Wt.id, {
1139
- unitId: e,
1140
- createType: _,
1141
- segmentId: C
1199
+ viewModel.setEditArea(editArea);
1200
+ const { createType, headerFooterId } = checkCreateHeaderFooterType(viewModel, editArea, pageNumber);
1201
+ if (editArea === DocumentEditArea.BODY)
1202
+ this._textSelectionRenderManager.setSegment(""), this._textSelectionRenderManager.setSegmentPage(-1), this._textSelectionRenderManager.setCursorManually(offsetX, offsetY);
1203
+ else if (createType != null) {
1204
+ const segmentId = Tools.generateRandomId(6);
1205
+ this._textSelectionRenderManager.setSegment(segmentId), this._textSelectionRenderManager.setSegmentPage(pageNumber), await this._commandService.executeCommand(CoreHeaderFooterCommand.id, {
1206
+ unitId,
1207
+ createType,
1208
+ segmentId
1142
1209
  });
1143
- } else m != null && (this._textSelectionRenderManager.setSegment(m), this._textSelectionRenderManager.setSegmentPage(u), this._textSelectionRenderManager.setCursorManually(i, s));
1210
+ } else headerFooterId != null && (this._textSelectionRenderManager.setSegment(headerFooterId), this._textSelectionRenderManager.setSegmentPage(pageNumber), this._textSelectionRenderManager.setCursorManually(offsetX, offsetY));
1144
1211
  }));
1145
1212
  }
1146
- _getTransformCoordForDocumentOffset(e, n) {
1147
- const o = J(this._context), { document: r, scene: i } = o, { documentTransform: s } = r.getOffsetConfig(), a = i.getViewports()[0];
1148
- if (a == null)
1213
+ _getTransformCoordForDocumentOffset(evtOffsetX, evtOffsetY) {
1214
+ const docObject = neoGetDocObject(this._context), { document, scene } = docObject, { documentTransform } = document.getOffsetConfig(), activeViewport = scene.getViewports()[0];
1215
+ if (activeViewport == null)
1149
1216
  return;
1150
- const c = a.transformVector2SceneCoord(sn.FromArray([e, n]));
1151
- return s.clone().invert().applyPoint(c);
1217
+ const originCoord = activeViewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
1218
+ return documentTransform.clone().invert().applyPoint(originCoord);
1152
1219
  }
1153
1220
  // eslint-disable-next-line max-lines-per-function
1154
1221
  _drawHeaderFooterLabel() {
1155
- const e = this._localeService;
1156
- this._renderManagerService.currentRender$.subscribe((n) => {
1157
- if (n == null)
1222
+ const localeService = this._localeService;
1223
+ this._renderManagerService.currentRender$.subscribe((unitId) => {
1224
+ if (unitId == null)
1158
1225
  return;
1159
- const o = this._renderManagerService.getRenderById(n);
1160
- if (this._editorService.isEditor(n) || this._instanceSrv.getUniverDocInstance(n) == null || o == null)
1226
+ const currentRender = this._renderManagerService.getRenderById(unitId);
1227
+ if (this._editorService.isEditor(unitId) || this._instanceSrv.getUniverDocInstance(unitId) == null || currentRender == null)
1161
1228
  return;
1162
- const { mainComponent: r } = o, i = r;
1229
+ const { mainComponent } = currentRender, docsComponent = mainComponent;
1163
1230
  this.disposeWithMe(
1164
- Jt(
1231
+ toDisposable(
1165
1232
  // eslint-disable-next-line max-lines-per-function
1166
- i.pageRender$.subscribe((s) => {
1167
- if (this._editorService.isEditor(n))
1233
+ docsComponent.pageRender$.subscribe((config) => {
1234
+ if (this._editorService.isEditor(unitId))
1168
1235
  return;
1169
- const d = this._docSkeletonManagerService.getViewModel().getEditArea() === F.BODY, { page: g, pageLeft: h, pageTop: p, ctx: l } = s, { pageWidth: f, pageHeight: u, marginTop: _, marginBottom: m } = g;
1170
- if (l.save(), l.translate(h - 0.5, p - 0.5), d ? (Xe.drawWith(l, {
1236
+ const isEditBody = this._docSkeletonManagerService.getViewModel().getEditArea() === DocumentEditArea.BODY, { page, pageLeft, pageTop, ctx } = config, { pageWidth, pageHeight, marginTop, marginBottom } = page;
1237
+ if (ctx.save(), ctx.translate(pageLeft - 0.5, pageTop - 0.5), isEditBody ? (Rect.drawWith(ctx, {
1171
1238
  left: 0,
1172
1239
  top: 0,
1173
- width: f,
1174
- height: _,
1240
+ width: pageWidth,
1241
+ height: marginTop,
1175
1242
  fill: "rgba(255, 255, 255, 0.5)"
1176
- }), l.save(), l.translate(0, u - m), Xe.drawWith(l, {
1243
+ }), ctx.save(), ctx.translate(0, pageHeight - marginBottom), Rect.drawWith(ctx, {
1177
1244
  left: 0,
1178
1245
  top: 0,
1179
- width: f,
1180
- height: m,
1246
+ width: pageWidth,
1247
+ height: marginBottom,
1181
1248
  fill: "rgba(255, 255, 255, 0.5)"
1182
- }), l.restore()) : (l.save(), l.translate(0, _), Xe.drawWith(l, {
1249
+ }), ctx.restore()) : (ctx.save(), ctx.translate(0, marginTop), Rect.drawWith(ctx, {
1183
1250
  left: 0,
1184
- top: _,
1185
- width: f,
1186
- height: u - _ - m,
1251
+ top: marginTop,
1252
+ width: pageWidth,
1253
+ height: pageHeight - marginTop - marginBottom,
1187
1254
  fill: "rgba(255, 255, 255, 0.5)"
1188
- }), l.restore()), !d) {
1189
- const R = {
1255
+ }), ctx.restore()), !isEditBody) {
1256
+ const headerPathConfigIPathProps = {
1190
1257
  dataArray: [{
1191
1258
  command: "M",
1192
- points: [0, _]
1259
+ points: [0, marginTop]
1193
1260
  }, {
1194
1261
  command: "L",
1195
- points: [f, _]
1262
+ points: [pageWidth, marginTop]
1196
1263
  }],
1197
1264
  strokeWidth: 1,
1198
- stroke: Ht
1199
- }, C = {
1265
+ stroke: HEADER_FOOTER_STROKE_COLOR
1266
+ }, footerPathConfigIPathProps = {
1200
1267
  dataArray: [{
1201
1268
  command: "M",
1202
- points: [0, u - m]
1269
+ points: [0, pageHeight - marginBottom]
1203
1270
  }, {
1204
1271
  command: "L",
1205
- points: [f, u - m]
1272
+ points: [pageWidth, pageHeight - marginBottom]
1206
1273
  }],
1207
1274
  strokeWidth: 1,
1208
- stroke: Ht
1275
+ stroke: HEADER_FOOTER_STROKE_COLOR
1209
1276
  };
1210
- It.drawWith(l, R), It.drawWith(l, C), l.translate(0, _ + 1), Ne.drawWith(l, {
1211
- text: e.t("headerFooter.header"),
1212
- color: Vt
1213
- }), l.translate(0, u - _ - m), Ne.drawWith(l, {
1214
- text: e.t("headerFooter.footer"),
1215
- color: Vt
1277
+ Path.drawWith(ctx, headerPathConfigIPathProps), Path.drawWith(ctx, footerPathConfigIPathProps), ctx.translate(0, marginTop + 1), TextBubbleShape.drawWith(ctx, {
1278
+ text: localeService.t("headerFooter.header"),
1279
+ color: HEADER_FOOTER_FILL_COLOR
1280
+ }), ctx.translate(0, pageHeight - marginTop - marginBottom), TextBubbleShape.drawWith(ctx, {
1281
+ text: localeService.t("headerFooter.footer"),
1282
+ color: HEADER_FOOTER_FILL_COLOR
1216
1283
  });
1217
1284
  }
1218
- l.restore();
1285
+ ctx.restore();
1219
1286
  })
1220
1287
  )
1221
1288
  );
1222
1289
  });
1223
1290
  }
1224
- _isEditorReadOnly(e) {
1225
- const n = this._editorService.getEditor(e);
1226
- return n ? n.isReadOnly() : !1;
1291
+ _isEditorReadOnly(unitId) {
1292
+ const editor = this._editorService.getEditor(unitId);
1293
+ return editor ? editor.isReadOnly() : !1;
1227
1294
  }
1228
1295
  _getDocDataModel() {
1229
1296
  return this._context.unit;
1230
1297
  }
1231
- };
1232
- it = Lr([
1233
- X(1, O),
1234
- X(2, ee),
1235
- X(3, w),
1236
- X(4, W),
1237
- X(5, I(L)),
1238
- X(6, ne),
1239
- X(7, I(le)),
1240
- X(8, I(tn))
1241
- ], it);
1242
- function jt() {
1298
+ }, __name(_a5, "DocHeaderFooterController"), _a5);
1299
+ DocHeaderFooterController = __decorateClass$d([
1300
+ __decorateParam$d(1, ICommandService),
1301
+ __decorateParam$d(2, IEditorService),
1302
+ __decorateParam$d(3, IUniverInstanceService),
1303
+ __decorateParam$d(4, IRenderManagerService),
1304
+ __decorateParam$d(5, Inject(DocSkeletonManagerService)),
1305
+ __decorateParam$d(6, ITextSelectionRenderManager),
1306
+ __decorateParam$d(7, Inject(LocaleService)),
1307
+ __decorateParam$d(8, Inject(ComponentManager))
1308
+ ], DocHeaderFooterController);
1309
+ function getEmptyHeaderFooterBody() {
1243
1310
  return {
1244
1311
  dataStream: `\r
1245
1312
  `,
@@ -1269,750 +1336,901 @@ function jt() {
1269
1336
  ]
1270
1337
  };
1271
1338
  }
1272
- function Je(t, e, n, o) {
1273
- const r = Qe.getInstance(), i = 6, s = t != null ? t : j.generateRandomId(i), a = e === U.DEFAULT_HEADER || e === U.FIRST_PAGE_HEADER || e === U.EVEN_PAGE_HEADER, c = r.insertOp([a ? "headers" : "footers", s], {
1274
- [a ? "headerId" : "footerId"]: s,
1275
- body: jt()
1339
+ __name(getEmptyHeaderFooterBody, "getEmptyHeaderFooterBody");
1340
+ function createHeaderFooterAction(segmentId, createType, documentStyle, actions) {
1341
+ const jsonX = JSONX.getInstance(), ID_LEN = 6, firstSegmentId = segmentId != null ? segmentId : Tools.generateRandomId(ID_LEN), isHeader = createType === HeaderFooterType.DEFAULT_HEADER || createType === HeaderFooterType.FIRST_PAGE_HEADER || createType === HeaderFooterType.EVEN_PAGE_HEADER, insertAction = jsonX.insertOp([isHeader ? "headers" : "footers", firstSegmentId], {
1342
+ [isHeader ? "headerId" : "footerId"]: firstSegmentId,
1343
+ body: getEmptyHeaderFooterBody()
1276
1344
  });
1277
- o.push(c);
1278
- const d = j.generateRandomId(i), g = r.insertOp([a ? "footers" : "headers", d], {
1279
- [a ? "footers" : "headers"]: d,
1280
- body: jt()
1345
+ actions.push(insertAction);
1346
+ const secondSegmentId = Tools.generateRandomId(ID_LEN), insertPairAction = jsonX.insertOp([isHeader ? "footers" : "headers", secondSegmentId], {
1347
+ [isHeader ? "footers" : "headers"]: secondSegmentId,
1348
+ body: getEmptyHeaderFooterBody()
1281
1349
  });
1282
- o.push(g);
1283
- let h = "defaultHeaderId", p = "defaultFooterId";
1284
- switch (e) {
1285
- case U.DEFAULT_HEADER:
1286
- h = "defaultHeaderId", p = "defaultFooterId";
1350
+ actions.push(insertPairAction);
1351
+ let key = "defaultHeaderId", pairKey = "defaultFooterId";
1352
+ switch (createType) {
1353
+ case HeaderFooterType.DEFAULT_HEADER:
1354
+ key = "defaultHeaderId", pairKey = "defaultFooterId";
1287
1355
  break;
1288
- case U.DEFAULT_FOOTER:
1289
- h = "defaultFooterId", p = "defaultHeaderId";
1356
+ case HeaderFooterType.DEFAULT_FOOTER:
1357
+ key = "defaultFooterId", pairKey = "defaultHeaderId";
1290
1358
  break;
1291
- case U.FIRST_PAGE_HEADER:
1292
- h = "firstPageHeaderId", p = "firstPageFooterId";
1359
+ case HeaderFooterType.FIRST_PAGE_HEADER:
1360
+ key = "firstPageHeaderId", pairKey = "firstPageFooterId";
1293
1361
  break;
1294
- case U.FIRST_PAGE_FOOTER:
1295
- h = "firstPageFooterId", p = "firstPageHeaderId";
1362
+ case HeaderFooterType.FIRST_PAGE_FOOTER:
1363
+ key = "firstPageFooterId", pairKey = "firstPageHeaderId";
1296
1364
  break;
1297
- case U.EVEN_PAGE_HEADER:
1298
- h = "evenPageHeaderId", p = "evenPageFooterId";
1365
+ case HeaderFooterType.EVEN_PAGE_HEADER:
1366
+ key = "evenPageHeaderId", pairKey = "evenPageFooterId";
1299
1367
  break;
1300
- case U.EVEN_PAGE_FOOTER:
1301
- h = "evenPageFooterId", p = "evenPageHeaderId";
1368
+ case HeaderFooterType.EVEN_PAGE_FOOTER:
1369
+ key = "evenPageFooterId", pairKey = "evenPageHeaderId";
1302
1370
  break;
1303
1371
  default:
1304
- throw new Error(`Unknown header footer type: ${e}`);
1372
+ throw new Error(`Unknown header footer type: ${createType}`);
1305
1373
  }
1306
- for (const [l, f] of [[h, s], [p, d]])
1307
- if (n[l] != null) {
1308
- const u = r.replaceOp(["documentStyle", l], n[l], f);
1309
- o.push(u);
1374
+ for (const [k2, id] of [[key, firstSegmentId], [pairKey, secondSegmentId]])
1375
+ if (documentStyle[k2] != null) {
1376
+ const replaceAction = jsonX.replaceOp(["documentStyle", k2], documentStyle[k2], id);
1377
+ actions.push(replaceAction);
1310
1378
  } else {
1311
- const u = r.insertOp(["documentStyle", l], f);
1312
- o.push(u);
1379
+ const insertAction2 = jsonX.insertOp(["documentStyle", k2], id);
1380
+ actions.push(insertAction2);
1313
1381
  }
1314
- return o;
1382
+ return actions;
1315
1383
  }
1316
- const be = "doc.command.core-header-footer", Wt = {
1317
- id: be,
1318
- type: de.COMMAND,
1384
+ __name(createHeaderFooterAction, "createHeaderFooterAction");
1385
+ const CoreHeaderFooterCommandId = "doc.command.core-header-footer", CoreHeaderFooterCommand = {
1386
+ id: CoreHeaderFooterCommandId,
1387
+ type: CommandType.COMMAND,
1319
1388
  // eslint-disable-next-line max-lines-per-function
1320
- handler: async (t, e) => {
1321
- var E;
1322
- const n = t.get(O), o = t.get(w), r = t.get(W), { unitId: i, segmentId: s, createType: a, headerFooterProps: c } = e, d = (E = r.getRenderById(i)) == null ? void 0 : E.with(L), g = o.getUniverDocInstance(i), h = d == null ? void 0 : d.getViewModel();
1323
- if (g == null || h == null)
1389
+ handler: /* @__PURE__ */ __name(async (accessor, params) => {
1390
+ var _a19;
1391
+ const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), { unitId, segmentId, createType, headerFooterProps } = params, docSkeletonManagerService = (_a19 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a19.with(DocSkeletonManagerService), docDataModel = univerInstanceService.getUniverDocInstance(unitId), docViewModel = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getViewModel();
1392
+ if (docDataModel == null || docViewModel == null)
1324
1393
  return !1;
1325
- const p = h.getEditArea(), { documentStyle: l } = g.getSnapshot(), f = (c == null ? void 0 : c.marginFooter) != null || (c == null ? void 0 : c.marginHeader) != null, u = [{
1394
+ const editArea = docViewModel.getEditArea(), { documentStyle } = docDataModel.getSnapshot(), isUpdateMargin = (headerFooterProps == null ? void 0 : headerFooterProps.marginFooter) != null || (headerFooterProps == null ? void 0 : headerFooterProps.marginHeader) != null, textRanges = [{
1326
1395
  startOffset: 0,
1327
1396
  endOffset: 0,
1328
1397
  collapsed: !0
1329
- }], _ = {
1330
- id: ht.id,
1398
+ }], doMutation = {
1399
+ id: RichTextEditingMutation.id,
1331
1400
  params: {
1332
- unitId: i,
1401
+ unitId,
1333
1402
  actions: [],
1334
- textRanges: u,
1403
+ textRanges,
1335
1404
  debounce: !0
1336
1405
  }
1337
1406
  };
1338
- f && (_.params.noNeedSetTextRange = !0);
1339
- const m = Qe.getInstance(), R = [];
1340
- return a != null && Je(s, a, l, R), c != null && Object.keys(c).forEach((b) => {
1341
- const A = c[b], N = l[b];
1342
- if (A === N)
1407
+ isUpdateMargin && (doMutation.params.noNeedSetTextRange = !0);
1408
+ const jsonX = JSONX.getInstance(), rawActions = [];
1409
+ return createType != null && createHeaderFooterAction(segmentId, createType, documentStyle, rawActions), headerFooterProps != null && Object.keys(headerFooterProps).forEach((key) => {
1410
+ const value = headerFooterProps[key], oldValue = documentStyle[key];
1411
+ if (value === oldValue)
1343
1412
  return;
1344
- let Y;
1345
- if (N === void 0 ? Y = m.insertOp(["documentStyle", b], A) : Y = m.replaceOp(["documentStyle", b], N, A), R.push(Y), b === "useFirstPageHeaderFooter" && A === S.TRUE && !l.firstPageHeaderId) {
1346
- const G = p === F.HEADER ? U.FIRST_PAGE_HEADER : U.FIRST_PAGE_FOOTER;
1347
- Je(s, G, l, R);
1348
- } else if (b === "evenAndOddHeaders" && A === S.TRUE && !l.evenPageHeaderId) {
1349
- const G = p === F.HEADER ? U.EVEN_PAGE_HEADER : U.EVEN_PAGE_FOOTER;
1350
- Je(s, G, l, R);
1413
+ let action;
1414
+ if (oldValue === void 0 ? action = jsonX.insertOp(["documentStyle", key], value) : action = jsonX.replaceOp(["documentStyle", key], oldValue, value), rawActions.push(action), key === "useFirstPageHeaderFooter" && value === BooleanNumber.TRUE && !documentStyle.firstPageHeaderId) {
1415
+ const headerFooterType = editArea === DocumentEditArea.HEADER ? HeaderFooterType.FIRST_PAGE_HEADER : HeaderFooterType.FIRST_PAGE_FOOTER;
1416
+ createHeaderFooterAction(segmentId, headerFooterType, documentStyle, rawActions);
1417
+ } else if (key === "evenAndOddHeaders" && value === BooleanNumber.TRUE && !documentStyle.evenPageHeaderId) {
1418
+ const headerFooterType = editArea === DocumentEditArea.HEADER ? HeaderFooterType.EVEN_PAGE_HEADER : HeaderFooterType.EVEN_PAGE_FOOTER;
1419
+ createHeaderFooterAction(segmentId, headerFooterType, documentStyle, rawActions);
1351
1420
  }
1352
- }), R.length === 0 ? !1 : (_.params.actions = R.reduce((b, A) => Qe.compose(b, A), null), !!n.syncExecuteCommand(_.id, _.params));
1353
- }
1354
- }, mn = {
1421
+ }), rawActions.length === 0 ? !1 : (doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params));
1422
+ }, "handler")
1423
+ }, OpenHeaderFooterPanelCommand = {
1355
1424
  id: "doc.command.open-header-footer-panel",
1356
- type: de.COMMAND,
1357
- handler: async (t, e) => t.get(O).executeCommand(_n.id, { value: "open" })
1425
+ type: CommandType.COMMAND,
1426
+ handler: /* @__PURE__ */ __name(async (accessor, _params) => accessor.get(ICommandService).executeCommand(SidebarDocHeaderFooterPanelOperation.id, { value: "open" }), "handler")
1358
1427
  };
1359
- function Br(t) {
1360
- const e = t.get(O);
1428
+ function BoldMenuItemFactory(accessor) {
1429
+ const commandService = accessor.get(ICommandService);
1361
1430
  return {
1362
- id: Qn.id,
1363
- group: x.TOOLBAR_FORMAT,
1364
- type: y.BUTTON,
1431
+ id: SetInlineFormatBoldCommand.id,
1432
+ group: MenuGroup.TOOLBAR_FORMAT,
1433
+ type: MenuItemType.BUTTON,
1365
1434
  icon: "BoldSingle",
1366
1435
  title: "Set bold",
1367
1436
  tooltip: "toolbar.bold",
1368
- positions: [P.TOOLBAR_START],
1369
- activated$: new B((n) => {
1370
- const o = e.onCommandExecuted((r) => {
1371
- var s;
1372
- const i = r.id;
1373
- if (i === V.id || i === ue.id) {
1374
- const a = Z(t);
1375
- if (a == null)
1437
+ positions: [MenuPosition.TOOLBAR_START],
1438
+ activated$: new Observable((subscriber) => {
1439
+ const disposable = commandService.onCommandExecuted((c) => {
1440
+ var _a19;
1441
+ const id = c.id;
1442
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1443
+ const textRun = getFontStyleAtCursor(accessor);
1444
+ if (textRun == null)
1376
1445
  return;
1377
- const c = (s = a.ts) == null ? void 0 : s.bl;
1378
- n.next(c === S.TRUE);
1446
+ const bl = (_a19 = textRun.ts) == null ? void 0 : _a19.bl;
1447
+ subscriber.next(bl === BooleanNumber.TRUE);
1379
1448
  }
1380
1449
  });
1381
- return n.next(!1), o.dispose;
1450
+ return subscriber.next(!1), disposable.dispose;
1382
1451
  }),
1383
- hidden$: D(t, v.UNIVER_DOC)
1452
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1384
1453
  };
1385
1454
  }
1386
- function $r(t) {
1387
- const e = t.get(O);
1455
+ __name(BoldMenuItemFactory, "BoldMenuItemFactory");
1456
+ function ItalicMenuItemFactory(accessor) {
1457
+ const commandService = accessor.get(ICommandService);
1388
1458
  return {
1389
- id: eo.id,
1390
- group: x.TOOLBAR_FORMAT,
1391
- type: y.BUTTON,
1459
+ id: SetInlineFormatItalicCommand.id,
1460
+ group: MenuGroup.TOOLBAR_FORMAT,
1461
+ type: MenuItemType.BUTTON,
1392
1462
  icon: "ItalicSingle",
1393
1463
  title: "Set italic",
1394
1464
  tooltip: "toolbar.italic",
1395
- positions: [P.TOOLBAR_START],
1396
- activated$: new B((n) => {
1397
- const o = e.onCommandExecuted((r) => {
1398
- var s;
1399
- const i = r.id;
1400
- if (i === V.id || i === ue.id) {
1401
- const a = Z(t);
1402
- if (a == null)
1465
+ positions: [MenuPosition.TOOLBAR_START],
1466
+ activated$: new Observable((subscriber) => {
1467
+ const disposable = commandService.onCommandExecuted((c) => {
1468
+ var _a19;
1469
+ const id = c.id;
1470
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1471
+ const textRun = getFontStyleAtCursor(accessor);
1472
+ if (textRun == null)
1403
1473
  return;
1404
- const c = (s = a.ts) == null ? void 0 : s.it;
1405
- n.next(c === S.TRUE);
1474
+ const it = (_a19 = textRun.ts) == null ? void 0 : _a19.it;
1475
+ subscriber.next(it === BooleanNumber.TRUE);
1406
1476
  }
1407
1477
  });
1408
- return n.next(!1), o.dispose;
1478
+ return subscriber.next(!1), disposable.dispose;
1409
1479
  }),
1410
- hidden$: D(t, v.UNIVER_DOC)
1480
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1411
1481
  };
1412
1482
  }
1413
- function Hr(t) {
1414
- const e = t.get(O);
1483
+ __name(ItalicMenuItemFactory, "ItalicMenuItemFactory");
1484
+ function UnderlineMenuItemFactory(accessor) {
1485
+ const commandService = accessor.get(ICommandService);
1415
1486
  return {
1416
- id: to.id,
1417
- group: x.TOOLBAR_FORMAT,
1418
- type: y.BUTTON,
1487
+ id: SetInlineFormatUnderlineCommand.id,
1488
+ group: MenuGroup.TOOLBAR_FORMAT,
1489
+ type: MenuItemType.BUTTON,
1419
1490
  icon: "UnderlineSingle",
1420
1491
  title: "Set underline",
1421
1492
  tooltip: "toolbar.underline",
1422
- positions: [P.TOOLBAR_START],
1423
- activated$: new B((n) => {
1424
- const o = e.onCommandExecuted((r) => {
1425
- var s;
1426
- const i = r.id;
1427
- if (i === V.id || i === ue.id) {
1428
- const a = Z(t);
1429
- if (a == null)
1493
+ positions: [MenuPosition.TOOLBAR_START],
1494
+ activated$: new Observable((subscriber) => {
1495
+ const disposable = commandService.onCommandExecuted((c) => {
1496
+ var _a19;
1497
+ const id = c.id;
1498
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1499
+ const textRun = getFontStyleAtCursor(accessor);
1500
+ if (textRun == null)
1430
1501
  return;
1431
- const c = (s = a.ts) == null ? void 0 : s.ul;
1432
- n.next((c == null ? void 0 : c.s) === S.TRUE);
1502
+ const ul = (_a19 = textRun.ts) == null ? void 0 : _a19.ul;
1503
+ subscriber.next((ul == null ? void 0 : ul.s) === BooleanNumber.TRUE);
1433
1504
  }
1434
1505
  });
1435
- return n.next(!1), o.dispose;
1506
+ return subscriber.next(!1), disposable.dispose;
1436
1507
  }),
1437
- hidden$: D(t, v.UNIVER_DOC)
1508
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1438
1509
  };
1439
1510
  }
1440
- function Vr(t) {
1441
- const e = t.get(O);
1511
+ __name(UnderlineMenuItemFactory, "UnderlineMenuItemFactory");
1512
+ function StrikeThroughMenuItemFactory(accessor) {
1513
+ const commandService = accessor.get(ICommandService);
1442
1514
  return {
1443
- id: no.id,
1444
- group: x.TOOLBAR_FORMAT,
1445
- type: y.BUTTON,
1515
+ id: SetInlineFormatStrikethroughCommand.id,
1516
+ group: MenuGroup.TOOLBAR_FORMAT,
1517
+ type: MenuItemType.BUTTON,
1446
1518
  icon: "StrikethroughSingle",
1447
1519
  title: "Set strike through",
1448
1520
  tooltip: "toolbar.strikethrough",
1449
- positions: [P.TOOLBAR_START],
1450
- activated$: new B((n) => {
1451
- const o = e.onCommandExecuted((r) => {
1452
- var s;
1453
- const i = r.id;
1454
- if (i === V.id || i === ue.id) {
1455
- const a = Z(t);
1456
- if (a == null)
1521
+ positions: [MenuPosition.TOOLBAR_START],
1522
+ activated$: new Observable((subscriber) => {
1523
+ const disposable = commandService.onCommandExecuted((c) => {
1524
+ var _a19;
1525
+ const id = c.id;
1526
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1527
+ const textRun = getFontStyleAtCursor(accessor);
1528
+ if (textRun == null)
1457
1529
  return;
1458
- const c = (s = a.ts) == null ? void 0 : s.st;
1459
- n.next((c == null ? void 0 : c.s) === S.TRUE);
1530
+ const st = (_a19 = textRun.ts) == null ? void 0 : _a19.st;
1531
+ subscriber.next((st == null ? void 0 : st.s) === BooleanNumber.TRUE);
1460
1532
  }
1461
1533
  });
1462
- return n.next(!1), o.dispose;
1534
+ return subscriber.next(!1), disposable.dispose;
1463
1535
  }),
1464
- hidden$: D(t, v.UNIVER_DOC)
1536
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1465
1537
  };
1466
1538
  }
1467
- function jr(t) {
1468
- const e = t.get(O);
1539
+ __name(StrikeThroughMenuItemFactory, "StrikeThroughMenuItemFactory");
1540
+ function SubscriptMenuItemFactory(accessor) {
1541
+ const commandService = accessor.get(ICommandService);
1469
1542
  return {
1470
- id: oo.id,
1471
- group: x.TOOLBAR_FORMAT,
1472
- type: y.BUTTON,
1543
+ id: SetInlineFormatSubscriptCommand.id,
1544
+ group: MenuGroup.TOOLBAR_FORMAT,
1545
+ type: MenuItemType.BUTTON,
1473
1546
  icon: "SubscriptSingle",
1474
1547
  tooltip: "toolbar.subscript",
1475
- positions: [P.TOOLBAR_START],
1476
- activated$: new B((n) => {
1477
- const o = e.onCommandExecuted((r) => {
1478
- var s;
1479
- const i = r.id;
1480
- if (i === V.id || i === ue.id) {
1481
- const a = Z(t);
1482
- if (a == null)
1548
+ positions: [MenuPosition.TOOLBAR_START],
1549
+ activated$: new Observable((subscriber) => {
1550
+ const disposable = commandService.onCommandExecuted((c) => {
1551
+ var _a19;
1552
+ const id = c.id;
1553
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1554
+ const textRun = getFontStyleAtCursor(accessor);
1555
+ if (textRun == null)
1483
1556
  return;
1484
- const c = (s = a.ts) == null ? void 0 : s.va;
1485
- n.next(c === ae.SUBSCRIPT);
1557
+ const va = (_a19 = textRun.ts) == null ? void 0 : _a19.va;
1558
+ subscriber.next(va === BaselineOffset.SUBSCRIPT);
1486
1559
  }
1487
1560
  });
1488
- return n.next(!1), o.dispose;
1561
+ return subscriber.next(!1), disposable.dispose;
1489
1562
  }),
1490
- hidden$: D(t, v.UNIVER_DOC)
1563
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1491
1564
  };
1492
1565
  }
1493
- function Wr(t) {
1494
- const e = t.get(O);
1566
+ __name(SubscriptMenuItemFactory, "SubscriptMenuItemFactory");
1567
+ function SuperscriptMenuItemFactory(accessor) {
1568
+ const commandService = accessor.get(ICommandService);
1495
1569
  return {
1496
- id: ro.id,
1497
- group: x.TOOLBAR_FORMAT,
1498
- type: y.BUTTON,
1570
+ id: SetInlineFormatSuperscriptCommand.id,
1571
+ group: MenuGroup.TOOLBAR_FORMAT,
1572
+ type: MenuItemType.BUTTON,
1499
1573
  icon: "SuperscriptSingle",
1500
1574
  tooltip: "toolbar.superscript",
1501
- positions: [P.TOOLBAR_START],
1502
- activated$: new B((n) => {
1503
- const o = e.onCommandExecuted((r) => {
1504
- var s;
1505
- const i = r.id;
1506
- if (i === V.id || i === ue.id) {
1507
- const a = Z(t);
1508
- if (a == null)
1575
+ positions: [MenuPosition.TOOLBAR_START],
1576
+ activated$: new Observable((subscriber) => {
1577
+ const disposable = commandService.onCommandExecuted((c) => {
1578
+ var _a19;
1579
+ const id = c.id;
1580
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
1581
+ const textRun = getFontStyleAtCursor(accessor);
1582
+ if (textRun == null)
1509
1583
  return;
1510
- const c = (s = a.ts) == null ? void 0 : s.va;
1511
- n.next(c === ae.SUPERSCRIPT);
1584
+ const va = (_a19 = textRun.ts) == null ? void 0 : _a19.va;
1585
+ subscriber.next(va === BaselineOffset.SUPERSCRIPT);
1512
1586
  }
1513
1587
  });
1514
- return n.next(!1), o.dispose;
1588
+ return subscriber.next(!1), disposable.dispose;
1515
1589
  }),
1516
- hidden$: D(t, v.UNIVER_DOC)
1590
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1517
1591
  };
1518
1592
  }
1519
- function kr(t) {
1520
- const e = t.get(O);
1593
+ __name(SuperscriptMenuItemFactory, "SuperscriptMenuItemFactory");
1594
+ function FontFamilySelectorMenuItemFactory(accessor) {
1595
+ const commandService = accessor.get(ICommandService);
1521
1596
  return {
1522
- id: Rt.id,
1597
+ id: SetInlineFormatFontFamilyCommand.id,
1523
1598
  tooltip: "toolbar.font",
1524
- group: x.TOOLBAR_FORMAT,
1525
- type: y.SELECTOR,
1526
- label: dn,
1527
- positions: [P.TOOLBAR_START],
1528
- selections: vt.map((n) => ({
1599
+ group: MenuGroup.TOOLBAR_FORMAT,
1600
+ type: MenuItemType.SELECTOR,
1601
+ label: FONT_FAMILY_COMPONENT,
1602
+ positions: [MenuPosition.TOOLBAR_START],
1603
+ selections: FONT_FAMILY_LIST.map((item) => ({
1529
1604
  label: {
1530
- name: un,
1605
+ name: FONT_FAMILY_ITEM_COMPONENT,
1531
1606
  hoverable: !0
1532
1607
  },
1533
- value: n.value
1608
+ value: item.value
1534
1609
  })),
1535
1610
  // disabled$: getCurrentSheetDisabled$(accessor),
1536
- value$: new B((n) => {
1537
- const o = vt[0].value, r = e.onCommandExecuted((i) => {
1538
- var a;
1539
- const s = i.id;
1540
- if (s === V.id || s === Rt.id) {
1541
- const c = Z(t);
1542
- if (c == null)
1611
+ value$: new Observable((subscriber) => {
1612
+ const defaultValue = FONT_FAMILY_LIST[0].value, disposable = commandService.onCommandExecuted((c) => {
1613
+ var _a19;
1614
+ const id = c.id;
1615
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontFamilyCommand.id) {
1616
+ const textRun = getFontStyleAtCursor(accessor);
1617
+ if (textRun == null)
1543
1618
  return;
1544
- const d = (a = c.ts) == null ? void 0 : a.ff;
1545
- n.next(d != null ? d : o);
1619
+ const ff = (_a19 = textRun.ts) == null ? void 0 : _a19.ff;
1620
+ subscriber.next(ff != null ? ff : defaultValue);
1546
1621
  }
1547
1622
  });
1548
- return n.next(o), r.dispose;
1623
+ return subscriber.next(defaultValue), disposable.dispose;
1549
1624
  }),
1550
- hidden$: D(t, v.UNIVER_DOC)
1625
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1551
1626
  };
1552
1627
  }
1553
- function Gr(t) {
1554
- const e = t.get(O);
1628
+ __name(FontFamilySelectorMenuItemFactory, "FontFamilySelectorMenuItemFactory");
1629
+ function FontSizeSelectorMenuItemFactory(accessor) {
1630
+ const commandService = accessor.get(ICommandService);
1555
1631
  return {
1556
- id: Ot.id,
1557
- group: x.TOOLBAR_FORMAT,
1558
- type: y.SELECTOR,
1632
+ id: SetInlineFormatFontSizeCommand.id,
1633
+ group: MenuGroup.TOOLBAR_FORMAT,
1634
+ type: MenuItemType.SELECTOR,
1559
1635
  tooltip: "toolbar.fontSize",
1560
1636
  label: {
1561
- name: hn,
1637
+ name: FONT_SIZE_COMPONENT,
1562
1638
  props: {
1563
1639
  min: 1,
1564
1640
  max: 400
1565
1641
  // disabled$,
1566
1642
  }
1567
1643
  },
1568
- positions: [P.TOOLBAR_START],
1569
- selections: Un,
1644
+ positions: [MenuPosition.TOOLBAR_START],
1645
+ selections: FONT_SIZE_LIST,
1570
1646
  // disabled$,
1571
- value$: new B((n) => {
1572
- const r = e.onCommandExecuted((i) => {
1573
- var a;
1574
- const s = i.id;
1575
- if (s === V.id || s === Ot.id) {
1576
- const c = Z(t);
1577
- if (c == null)
1647
+ value$: new Observable((subscriber) => {
1648
+ const disposable = commandService.onCommandExecuted((c) => {
1649
+ var _a19;
1650
+ const id = c.id;
1651
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontSizeCommand.id) {
1652
+ const textRun = getFontStyleAtCursor(accessor);
1653
+ if (textRun == null)
1578
1654
  return;
1579
- const d = (a = c.ts) == null ? void 0 : a.fs;
1580
- n.next(d != null ? d : 14);
1655
+ const fs = (_a19 = textRun.ts) == null ? void 0 : _a19.fs;
1656
+ subscriber.next(fs != null ? fs : 14);
1581
1657
  }
1582
1658
  });
1583
- return n.next(14), r.dispose;
1659
+ return subscriber.next(14), disposable.dispose;
1584
1660
  }),
1585
- hidden$: D(t, v.UNIVER_DOC)
1661
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1586
1662
  };
1587
1663
  }
1588
- function zr(t) {
1589
- const e = t.get(O), n = t.get(Qt);
1664
+ __name(FontSizeSelectorMenuItemFactory, "FontSizeSelectorMenuItemFactory");
1665
+ function TextColorSelectorMenuItemFactory(accessor) {
1666
+ const commandService = accessor.get(ICommandService), themeService = accessor.get(ThemeService);
1590
1667
  return {
1591
- id: Ct.id,
1668
+ id: SetInlineFormatTextColorCommand.id,
1592
1669
  icon: "FontColor",
1593
1670
  tooltip: "toolbar.textColor.main",
1594
- group: x.TOOLBAR_FORMAT,
1595
- type: y.BUTTON_SELECTOR,
1596
- positions: [P.TOOLBAR_START],
1671
+ group: MenuGroup.TOOLBAR_FORMAT,
1672
+ type: MenuItemType.BUTTON_SELECTOR,
1673
+ positions: [MenuPosition.TOOLBAR_START],
1597
1674
  selections: [
1598
1675
  {
1599
1676
  label: {
1600
- name: pt,
1677
+ name: COLOR_PICKER_COMPONENT,
1601
1678
  hoverable: !1
1602
1679
  }
1603
1680
  }
1604
1681
  ],
1605
- value$: new B((o) => {
1606
- const r = n.getCurrentTheme().textColor, i = e.onCommandExecuted((s) => {
1607
- if (s.id === Ct.id) {
1608
- const a = s.params.value;
1609
- o.next(a != null ? a : r);
1682
+ value$: new Observable((subscriber) => {
1683
+ const defaultColor = themeService.getCurrentTheme().textColor, disposable = commandService.onCommandExecuted((c) => {
1684
+ if (c.id === SetInlineFormatTextColorCommand.id) {
1685
+ const color = c.params.value;
1686
+ subscriber.next(color != null ? color : defaultColor);
1610
1687
  }
1611
1688
  });
1612
- return o.next(r), i.dispose;
1689
+ return subscriber.next(defaultColor), disposable.dispose;
1613
1690
  }),
1614
- hidden$: D(t, v.UNIVER_DOC)
1691
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1615
1692
  // disabled$: getCurrentSheetDisabled$(accessor),
1616
1693
  };
1617
1694
  }
1618
- function Yr(t) {
1695
+ __name(TextColorSelectorMenuItemFactory, "TextColorSelectorMenuItemFactory");
1696
+ function HeaderFooterMenuItemFactory(accessor) {
1619
1697
  return {
1620
- id: mn.id,
1621
- group: x.TOOLBAR_OTHERS,
1622
- type: y.BUTTON,
1698
+ id: OpenHeaderFooterPanelCommand.id,
1699
+ group: MenuGroup.TOOLBAR_OTHERS,
1700
+ type: MenuItemType.BUTTON,
1623
1701
  icon: "FreezeRowSingle",
1624
1702
  tooltip: "toolbar.headerFooter",
1625
- positions: [P.TOOLBAR_START],
1626
- hidden$: yo(D(t, v.UNIVER_DOC), Ln(t), (e, n) => e || n)
1703
+ positions: [MenuPosition.TOOLBAR_START],
1704
+ hidden$: combineLatest(getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC), getHeaderFooterMenuHiddenObservable(accessor), (one, two) => one || two)
1627
1705
  };
1628
1706
  }
1629
- function Xr(t) {
1630
- const e = t.get(O);
1707
+ __name(HeaderFooterMenuItemFactory, "HeaderFooterMenuItemFactory");
1708
+ function AlignLeftMenuItemFactory(accessor) {
1709
+ const commandService = accessor.get(ICommandService);
1631
1710
  return {
1632
- id: io.id,
1633
- group: x.TOOLBAR_LAYOUT,
1634
- type: y.BUTTON,
1711
+ id: AlignLeftCommand.id,
1712
+ group: MenuGroup.TOOLBAR_LAYOUT,
1713
+ type: MenuItemType.BUTTON,
1635
1714
  icon: "LeftJustifyingSingle",
1636
1715
  tooltip: "toolbar.alignLeft",
1637
- positions: [P.TOOLBAR_START],
1638
- activated$: new B((n) => {
1639
- const o = e.onCommandExecuted((r) => {
1640
- var s;
1641
- const i = r.id;
1642
- if (i === V.id || i === je.id) {
1643
- const a = Ge(t);
1644
- if (a == null)
1716
+ positions: [MenuPosition.TOOLBAR_START],
1717
+ activated$: new Observable((subscriber) => {
1718
+ const disposable = commandService.onCommandExecuted((c) => {
1719
+ var _a19;
1720
+ const id = c.id;
1721
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
1722
+ const paragraph = getParagraphStyleAtCursor(accessor);
1723
+ if (paragraph == null)
1645
1724
  return;
1646
- const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
1647
- n.next(c === Le.LEFT);
1725
+ const alignType = (_a19 = paragraph.paragraphStyle) == null ? void 0 : _a19.horizontalAlign;
1726
+ subscriber.next(alignType === HorizontalAlign.LEFT);
1648
1727
  }
1649
1728
  });
1650
- return n.next(!1), o.dispose;
1729
+ return subscriber.next(!1), disposable.dispose;
1651
1730
  }),
1652
- hidden$: D(t, v.UNIVER_DOC)
1731
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1653
1732
  };
1654
1733
  }
1655
- function Kr(t) {
1656
- const e = t.get(O);
1734
+ __name(AlignLeftMenuItemFactory, "AlignLeftMenuItemFactory");
1735
+ function AlignCenterMenuItemFactory(accessor) {
1736
+ const commandService = accessor.get(ICommandService);
1657
1737
  return {
1658
- id: so.id,
1659
- group: x.TOOLBAR_LAYOUT,
1660
- type: y.BUTTON,
1738
+ id: AlignCenterCommand.id,
1739
+ group: MenuGroup.TOOLBAR_LAYOUT,
1740
+ type: MenuItemType.BUTTON,
1661
1741
  icon: "HorizontallySingle",
1662
1742
  tooltip: "toolbar.alignCenter",
1663
- positions: [P.TOOLBAR_START],
1664
- activated$: new B((n) => {
1665
- const o = e.onCommandExecuted((r) => {
1666
- var s;
1667
- const i = r.id;
1668
- if (i === V.id || i === je.id) {
1669
- const a = Ge(t);
1670
- if (a == null)
1743
+ positions: [MenuPosition.TOOLBAR_START],
1744
+ activated$: new Observable((subscriber) => {
1745
+ const disposable = commandService.onCommandExecuted((c) => {
1746
+ var _a19;
1747
+ const id = c.id;
1748
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
1749
+ const paragraph = getParagraphStyleAtCursor(accessor);
1750
+ if (paragraph == null)
1671
1751
  return;
1672
- const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
1673
- n.next(c === Le.CENTER);
1752
+ const alignType = (_a19 = paragraph.paragraphStyle) == null ? void 0 : _a19.horizontalAlign;
1753
+ subscriber.next(alignType === HorizontalAlign.CENTER);
1674
1754
  }
1675
1755
  });
1676
- return n.next(!1), o.dispose;
1756
+ return subscriber.next(!1), disposable.dispose;
1677
1757
  }),
1678
- hidden$: D(t, v.UNIVER_DOC)
1758
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1679
1759
  };
1680
1760
  }
1681
- function Zr(t) {
1682
- const e = t.get(O);
1761
+ __name(AlignCenterMenuItemFactory, "AlignCenterMenuItemFactory");
1762
+ function AlignRightMenuItemFactory(accessor) {
1763
+ const commandService = accessor.get(ICommandService);
1683
1764
  return {
1684
- id: ao.id,
1685
- group: x.TOOLBAR_LAYOUT,
1686
- type: y.BUTTON,
1765
+ id: AlignRightCommand.id,
1766
+ group: MenuGroup.TOOLBAR_LAYOUT,
1767
+ type: MenuItemType.BUTTON,
1687
1768
  icon: "RightJustifyingSingle",
1688
1769
  tooltip: "toolbar.alignRight",
1689
- positions: [P.TOOLBAR_START],
1690
- activated$: new B((n) => {
1691
- const o = e.onCommandExecuted((r) => {
1692
- var s;
1693
- const i = r.id;
1694
- if (i === V.id || i === je.id) {
1695
- const a = Ge(t);
1696
- if (a == null)
1770
+ positions: [MenuPosition.TOOLBAR_START],
1771
+ activated$: new Observable((subscriber) => {
1772
+ const disposable = commandService.onCommandExecuted((c) => {
1773
+ var _a19;
1774
+ const id = c.id;
1775
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
1776
+ const paragraph = getParagraphStyleAtCursor(accessor);
1777
+ if (paragraph == null)
1697
1778
  return;
1698
- const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
1699
- n.next(c === Le.RIGHT);
1779
+ const alignType = (_a19 = paragraph.paragraphStyle) == null ? void 0 : _a19.horizontalAlign;
1780
+ subscriber.next(alignType === HorizontalAlign.RIGHT);
1700
1781
  }
1701
1782
  });
1702
- return n.next(!1), o.dispose;
1783
+ return subscriber.next(!1), disposable.dispose;
1703
1784
  }),
1704
- hidden$: D(t, v.UNIVER_DOC)
1785
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1705
1786
  };
1706
1787
  }
1707
- function Jr(t) {
1708
- const e = t.get(O);
1788
+ __name(AlignRightMenuItemFactory, "AlignRightMenuItemFactory");
1789
+ function AlignJustifyMenuItemFactory(accessor) {
1790
+ const commandService = accessor.get(ICommandService);
1709
1791
  return {
1710
- id: co.id,
1711
- group: x.TOOLBAR_LAYOUT,
1712
- type: y.BUTTON,
1792
+ id: AlignJustifyCommand.id,
1793
+ group: MenuGroup.TOOLBAR_LAYOUT,
1794
+ type: MenuItemType.BUTTON,
1713
1795
  icon: "AlignTextBothSingle",
1714
1796
  tooltip: "toolbar.alignJustify",
1715
- positions: [P.TOOLBAR_START],
1716
- activated$: new B((n) => {
1717
- const o = e.onCommandExecuted((r) => {
1718
- var s;
1719
- const i = r.id;
1720
- if (i === V.id || i === je.id) {
1721
- const a = Ge(t);
1722
- if (a == null)
1797
+ positions: [MenuPosition.TOOLBAR_START],
1798
+ activated$: new Observable((subscriber) => {
1799
+ const disposable = commandService.onCommandExecuted((c) => {
1800
+ var _a19;
1801
+ const id = c.id;
1802
+ if (id === SetTextSelectionsOperation.id || id === AlignOperationCommand.id) {
1803
+ const paragraph = getParagraphStyleAtCursor(accessor);
1804
+ if (paragraph == null)
1723
1805
  return;
1724
- const c = (s = a.paragraphStyle) == null ? void 0 : s.horizontalAlign;
1725
- n.next(c === Le.JUSTIFIED);
1806
+ const alignType = (_a19 = paragraph.paragraphStyle) == null ? void 0 : _a19.horizontalAlign;
1807
+ subscriber.next(alignType === HorizontalAlign.JUSTIFIED);
1726
1808
  }
1727
1809
  });
1728
- return n.next(!1), o.dispose;
1810
+ return subscriber.next(!1), disposable.dispose;
1729
1811
  }),
1730
- hidden$: D(t, v.UNIVER_DOC)
1812
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1731
1813
  };
1732
1814
  }
1733
- function qr(t) {
1815
+ __name(AlignJustifyMenuItemFactory, "AlignJustifyMenuItemFactory");
1816
+ function OrderListMenuItemFactory(accessor) {
1734
1817
  return {
1735
- id: lo.id,
1736
- group: x.TOOLBAR_LAYOUT,
1737
- type: y.BUTTON,
1818
+ id: OrderListCommand.id,
1819
+ group: MenuGroup.TOOLBAR_LAYOUT,
1820
+ type: MenuItemType.BUTTON,
1738
1821
  icon: "OrderSingle",
1739
1822
  tooltip: "toolbar.order",
1740
- positions: [P.TOOLBAR_START],
1741
- hidden$: D(t, v.UNIVER_DOC)
1823
+ positions: [MenuPosition.TOOLBAR_START],
1824
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1742
1825
  };
1743
1826
  }
1744
- function Qr(t) {
1827
+ __name(OrderListMenuItemFactory, "OrderListMenuItemFactory");
1828
+ function BulletListMenuItemFactory(accessor) {
1745
1829
  return {
1746
- id: uo.id,
1747
- group: x.TOOLBAR_LAYOUT,
1748
- type: y.BUTTON,
1830
+ id: BulletListCommand.id,
1831
+ group: MenuGroup.TOOLBAR_LAYOUT,
1832
+ type: MenuItemType.BUTTON,
1749
1833
  icon: "UnorderSingle",
1750
1834
  tooltip: "toolbar.unorder",
1751
- positions: [P.TOOLBAR_START],
1752
- hidden$: D(t, v.UNIVER_DOC)
1835
+ positions: [MenuPosition.TOOLBAR_START],
1836
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1753
1837
  };
1754
1838
  }
1755
- function ei(t) {
1839
+ __name(BulletListMenuItemFactory, "BulletListMenuItemFactory");
1840
+ function ResetBackgroundColorMenuItemFactory(accessor) {
1756
1841
  return {
1757
- id: ho.id,
1758
- type: y.BUTTON,
1842
+ id: ResetInlineFormatTextBackgroundColorCommand.id,
1843
+ type: MenuItemType.BUTTON,
1759
1844
  title: "toolbar.resetColor",
1760
1845
  icon: "NoColor",
1761
- positions: et.id
1846
+ positions: SetInlineFormatTextBackgroundColorCommand.id
1762
1847
  };
1763
1848
  }
1764
- function ti(t) {
1765
- const e = t.get(O), n = t.get(Qt);
1849
+ __name(ResetBackgroundColorMenuItemFactory, "ResetBackgroundColorMenuItemFactory");
1850
+ function BackgroundColorSelectorMenuItemFactory(accessor) {
1851
+ const commandService = accessor.get(ICommandService), themeService = accessor.get(ThemeService);
1766
1852
  return {
1767
- id: et.id,
1853
+ id: SetInlineFormatTextBackgroundColorCommand.id,
1768
1854
  tooltip: "toolbar.fillColor.main",
1769
- group: x.TOOLBAR_FORMAT,
1770
- type: y.BUTTON_SELECTOR,
1771
- positions: [P.TOOLBAR_START],
1855
+ group: MenuGroup.TOOLBAR_FORMAT,
1856
+ type: MenuItemType.BUTTON_SELECTOR,
1857
+ positions: [MenuPosition.TOOLBAR_START],
1772
1858
  icon: "PaintBucket",
1773
1859
  selections: [
1774
1860
  {
1775
1861
  label: {
1776
- name: pt,
1862
+ name: COLOR_PICKER_COMPONENT,
1777
1863
  hoverable: !1
1778
1864
  }
1779
1865
  }
1780
1866
  ],
1781
- value$: new B((o) => {
1782
- const r = n.getCurrentTheme().primaryColor, i = e.onCommandExecuted((s) => {
1783
- if (s.id === et.id) {
1784
- const a = s.params.value;
1785
- o.next(a != null ? a : r);
1867
+ value$: new Observable((subscriber) => {
1868
+ const defaultColor = themeService.getCurrentTheme().primaryColor, disposable = commandService.onCommandExecuted((c) => {
1869
+ if (c.id === SetInlineFormatTextBackgroundColorCommand.id) {
1870
+ const color = c.params.value;
1871
+ subscriber.next(color != null ? color : defaultColor);
1786
1872
  }
1787
1873
  });
1788
- return o.next(r), i.dispose;
1874
+ return subscriber.next(defaultColor), disposable.dispose;
1789
1875
  }),
1790
- hidden$: D(t, v.UNIVER_DOC)
1876
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1791
1877
  };
1792
1878
  }
1793
- function Z(t) {
1794
- var d;
1795
- const e = t.get(w), n = t.get(te), o = e.getCurrentUniverDocInstance(), r = n.getActiveRange();
1796
- if (o == null || r == null)
1879
+ __name(BackgroundColorSelectorMenuItemFactory, "BackgroundColorSelectorMenuItemFactory");
1880
+ function getFontStyleAtCursor(accessor) {
1881
+ var _a19;
1882
+ const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveRange();
1883
+ if (docDataModel == null || activeTextRange == null)
1797
1884
  return;
1798
- const { startOffset: i, segmentId: s } = r, a = (d = o.getSelfOrHeaderFooterModel(s).getBody()) == null ? void 0 : d.textRuns;
1799
- if (a == null)
1885
+ const { startOffset, segmentId } = activeTextRange, textRuns = (_a19 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a19.textRuns;
1886
+ if (textRuns == null)
1800
1887
  return;
1801
- let c;
1802
- for (let g = 0; g < a.length; g++) {
1803
- const h = a[g], p = a[g + 1];
1804
- if (p && p.st === p.ed && i === p.st) {
1805
- c = p;
1888
+ let textRun;
1889
+ for (let i = 0; i < textRuns.length; i++) {
1890
+ const curTextRun = textRuns[i], nextTextRun = textRuns[i + 1];
1891
+ if (nextTextRun && nextTextRun.st === nextTextRun.ed && startOffset === nextTextRun.st) {
1892
+ textRun = nextTextRun;
1806
1893
  break;
1807
1894
  }
1808
- if (h.st <= i && i <= h.ed) {
1809
- c = h;
1895
+ if (curTextRun.st <= startOffset && startOffset <= curTextRun.ed) {
1896
+ textRun = curTextRun;
1810
1897
  break;
1811
1898
  }
1812
1899
  }
1813
- return c;
1900
+ return textRun;
1814
1901
  }
1815
- function Ge(t) {
1816
- var d;
1817
- const e = t.get(w), n = t.get(te), o = e.getCurrentUniverDocInstance(), r = n.getActiveRange();
1818
- if (o == null || r == null)
1902
+ __name(getFontStyleAtCursor, "getFontStyleAtCursor");
1903
+ function getParagraphStyleAtCursor(accessor) {
1904
+ var _a19;
1905
+ const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionService.getActiveRange();
1906
+ if (docDataModel == null || activeTextRange == null)
1819
1907
  return;
1820
- const { startOffset: i, segmentId: s } = r, a = (d = o.getSelfOrHeaderFooterModel(s).getBody()) == null ? void 0 : d.paragraphs;
1821
- if (a == null)
1908
+ const { startOffset, segmentId } = activeTextRange, paragraphs = (_a19 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a19.paragraphs;
1909
+ if (paragraphs == null)
1822
1910
  return;
1823
- let c = -1;
1824
- for (const g of a) {
1825
- const { startIndex: h } = g;
1826
- if (i > c && i <= h)
1827
- return g;
1828
- c = h;
1911
+ let prevIndex = -1;
1912
+ for (const paragraph of paragraphs) {
1913
+ const { startIndex } = paragraph;
1914
+ if (startOffset > prevIndex && startOffset <= startIndex)
1915
+ return paragraph;
1916
+ prevIndex = startIndex;
1829
1917
  }
1830
1918
  return null;
1831
1919
  }
1832
- var ni = Object.defineProperty, oi = Object.getOwnPropertyDescriptor, ri = (t, e, n, o) => {
1833
- for (var r = o > 1 ? void 0 : o ? oi(e, n) : e, i = t.length - 1, s; i >= 0; i--)
1834
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
1835
- return o && r && ni(e, n, r), r;
1836
- }, Ee = (t, e) => (n, o) => e(n, o, t);
1837
- let me = class extends Q {
1838
- constructor(t, e, n, o, r) {
1839
- super(), this._config = t, this._injector = e, this._componentManager = n, this._layoutService = o, this._menuService = r, this._init();
1920
+ __name(getParagraphStyleAtCursor, "getParagraphStyleAtCursor");
1921
+ function whenDocOrEditor(contextService) {
1922
+ return contextService.getContextValue(FOCUSING_DOC) || contextService.getContextValue(EDITOR_ACTIVATED);
1923
+ }
1924
+ __name(whenDocOrEditor, "whenDocOrEditor");
1925
+ const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
1926
+ id: CopyCommand.id,
1927
+ name: "doc.command.copy",
1928
+ type: CommandType.COMMAND,
1929
+ multi: !0,
1930
+ priority: DOC_CLIPBOARD_PRIORITY,
1931
+ preconditions: whenDocOrEditor,
1932
+ handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(IDocClipboardService).copy(), "handler")
1933
+ }, DocCutCommand = {
1934
+ id: CutCommand.id,
1935
+ name: "doc.command.cut",
1936
+ type: CommandType.COMMAND,
1937
+ multi: !0,
1938
+ priority: DOC_CLIPBOARD_PRIORITY,
1939
+ preconditions: whenDocOrEditor,
1940
+ handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(IDocClipboardService).cut(), "handler")
1941
+ }, DocPasteCommand = {
1942
+ id: PasteCommand.id,
1943
+ name: "doc.command.paste",
1944
+ type: CommandType.COMMAND,
1945
+ multi: !0,
1946
+ priority: DOC_CLIPBOARD_PRIORITY,
1947
+ preconditions: whenDocOrEditor,
1948
+ handler: /* @__PURE__ */ __name(async (accessor) => {
1949
+ const docClipboardService = accessor.get(IDocClipboardService), clipboardItems = await accessor.get(IClipboardInterfaceService).read();
1950
+ return clipboardItems.length === 0 ? !1 : docClipboardService.paste(clipboardItems);
1951
+ }, "handler")
1952
+ }, getDisableOnCollapsedObservable = /* @__PURE__ */ __name((accessor) => {
1953
+ const textSelectionManagerService = accessor.get(TextSelectionManagerService);
1954
+ return new Observable((subscriber) => {
1955
+ const observable = textSelectionManagerService.textSelection$.subscribe((selections) => {
1956
+ const range = textSelectionManagerService.getActiveRange();
1957
+ range && !range.collapsed ? subscriber.next(!1) : subscriber.next(!0);
1958
+ });
1959
+ return () => observable.unsubscribe();
1960
+ });
1961
+ }, "getDisableOnCollapsedObservable"), CopyMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1962
+ id: DocCopyCommand.id,
1963
+ group: MenuGroup.CONTEXT_MENU_FORMAT,
1964
+ type: MenuItemType.BUTTON,
1965
+ icon: "Copy",
1966
+ title: "rightClick.copy",
1967
+ positions: [MenuPosition.CONTEXT_MENU],
1968
+ disabled$: getDisableOnCollapsedObservable(accessor),
1969
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1970
+ }), "CopyMenuFactory"), CutMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1971
+ id: DocCutCommand.id,
1972
+ group: MenuGroup.CONTEXT_MENU_FORMAT,
1973
+ type: MenuItemType.BUTTON,
1974
+ icon: "Copy",
1975
+ title: "rightClick.cut",
1976
+ positions: [MenuPosition.CONTEXT_MENU],
1977
+ disabled$: getDisableOnCollapsedObservable(accessor),
1978
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1979
+ }), "CutMenuFactory"), PasteMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1980
+ id: DocPasteCommand.id,
1981
+ group: MenuGroup.CONTEXT_MENU_FORMAT,
1982
+ type: MenuItemType.BUTTON,
1983
+ icon: "PasteSpecial",
1984
+ title: "rightClick.paste",
1985
+ positions: [MenuPosition.CONTEXT_MENU],
1986
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1987
+ }), "PasteMenuFactory"), DeleteMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1988
+ id: DeleteLeftCommand.id,
1989
+ group: MenuGroup.CONTEXT_MENU_FORMAT,
1990
+ type: MenuItemType.BUTTON,
1991
+ icon: "PasteSpecial",
1992
+ title: "rightClick.delete",
1993
+ positions: [MenuPosition.CONTEXT_MENU],
1994
+ disabled$: getDisableOnCollapsedObservable(accessor),
1995
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC)
1996
+ }), "DeleteMenuFactory"), BoldShortCut = {
1997
+ id: SetInlineFormatBoldCommand.id,
1998
+ binding: KeyCode.B | MetaKeys.CTRL_COMMAND,
1999
+ preconditions: whenDocAndEditorFocused
2000
+ }, ItalicShortCut = {
2001
+ id: SetInlineFormatItalicCommand.id,
2002
+ binding: KeyCode.I | MetaKeys.CTRL_COMMAND,
2003
+ preconditions: whenDocAndEditorFocused
2004
+ }, UnderlineShortCut = {
2005
+ id: SetInlineFormatUnderlineCommand.id,
2006
+ binding: KeyCode.U | MetaKeys.CTRL_COMMAND,
2007
+ preconditions: whenDocAndEditorFocused
2008
+ }, StrikeThroughShortCut = {
2009
+ id: SetInlineFormatStrikethroughCommand.id,
2010
+ binding: KeyCode.X | MetaKeys.SHIFT | MetaKeys.CTRL_COMMAND,
2011
+ preconditions: whenDocAndEditorFocused
2012
+ }, SubscriptShortCut = {
2013
+ id: SetInlineFormatSubscriptCommand.id,
2014
+ binding: KeyCode.COMMA | MetaKeys.CTRL_COMMAND,
2015
+ preconditions: whenDocAndEditorFocused
2016
+ }, SuperscriptShortCut = {
2017
+ id: SetInlineFormatSuperscriptCommand.id,
2018
+ binding: KeyCode.PERIOD | MetaKeys.CTRL_COMMAND,
2019
+ preconditions: whenDocAndEditorFocused
2020
+ }, AlignLeftShortCut = {
2021
+ id: AlignLeftCommand.id,
2022
+ binding: KeyCode.L | MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT,
2023
+ preconditions: whenDocAndEditorFocused
2024
+ }, AlignRightShortCut = {
2025
+ id: AlignRightCommand.id,
2026
+ binding: KeyCode.R | MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT,
2027
+ preconditions: whenDocAndEditorFocused
2028
+ }, AlignCenterShortCut = {
2029
+ id: AlignCenterCommand.id,
2030
+ binding: KeyCode.E | MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT,
2031
+ preconditions: whenDocAndEditorFocused
2032
+ }, AlignJustifyShortCut = {
2033
+ id: AlignJustifyCommand.id,
2034
+ binding: KeyCode.J | MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT,
2035
+ preconditions: whenDocAndEditorFocused
2036
+ }, OrderListShortCut = {
2037
+ id: OrderListCommand.id,
2038
+ binding: KeyCode.Digit7 | MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT,
2039
+ preconditions: whenDocAndEditorFocused
2040
+ }, BulletListShortCut = {
2041
+ id: BulletListCommand.id,
2042
+ binding: KeyCode.Digit8 | MetaKeys.CTRL_COMMAND | MetaKeys.SHIFT,
2043
+ preconditions: whenDocAndEditorFocused
2044
+ };
2045
+ var __defProp$c = Object.defineProperty, __getOwnPropDesc$c = Object.getOwnPropertyDescriptor, __decorateClass$c = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2046
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2047
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2048
+ return kind && result && __defProp$c(target, key, result), result;
2049
+ }, "__decorateClass$c"), __decorateParam$c = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$c"), _a6;
2050
+ let DocUIController = (_a6 = class extends Disposable {
2051
+ constructor(_config, _injector, _componentManager, _layoutService, _menuService, _uiPartsService, _univerInstanceService, _shortcutService) {
2052
+ super(), this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._layoutService = _layoutService, this._menuService = _menuService, this._uiPartsService = _uiPartsService, this._univerInstanceService = _univerInstanceService, this._shortcutService = _shortcutService, this._init();
1840
2053
  }
1841
2054
  _initCustomComponents() {
1842
- const t = this._componentManager;
1843
- this.disposeWithMe(t.register(pt, Ao)), this.disposeWithMe(t.register(dn, wn)), this.disposeWithMe(t.register(un, Bn)), this.disposeWithMe(t.register(hn, $n));
2055
+ const componentManager = this._componentManager;
2056
+ this.disposeWithMe(componentManager.register(COLOR_PICKER_COMPONENT, ColorPicker)), this.disposeWithMe(componentManager.register(FONT_FAMILY_COMPONENT, FontFamily)), this.disposeWithMe(componentManager.register(FONT_FAMILY_ITEM_COMPONENT, FontFamilyItem)), this.disposeWithMe(componentManager.register(FONT_SIZE_COMPONENT, FontSize));
2057
+ }
2058
+ _initUiParts() {
2059
+ var _a19, _b;
2060
+ const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
2061
+ (_b = (_a19 = this._config.layout) == null ? void 0 : _a19.docContainerConfig) != null && _b.footer && !workbook && this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));
1844
2062
  }
1845
2063
  _initMenus() {
1846
- const { menu: t = {} } = this._config;
2064
+ const { menu = {} } = this._config;
2065
+ [
2066
+ BoldMenuItemFactory,
2067
+ ItalicMenuItemFactory,
2068
+ UnderlineMenuItemFactory,
2069
+ StrikeThroughMenuItemFactory,
2070
+ SubscriptMenuItemFactory,
2071
+ SuperscriptMenuItemFactory,
2072
+ FontSizeSelectorMenuItemFactory,
2073
+ FontFamilySelectorMenuItemFactory,
2074
+ TextColorSelectorMenuItemFactory,
2075
+ HeaderFooterMenuItemFactory,
2076
+ AlignLeftMenuItemFactory,
2077
+ AlignCenterMenuItemFactory,
2078
+ AlignRightMenuItemFactory,
2079
+ AlignJustifyMenuItemFactory,
2080
+ OrderListMenuItemFactory,
2081
+ BulletListMenuItemFactory,
2082
+ ResetBackgroundColorMenuItemFactory,
2083
+ BackgroundColorSelectorMenuItemFactory
2084
+ ].forEach((factory) => {
2085
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
2086
+ }), [
2087
+ CopyMenuFactory,
2088
+ CutMenuFactory,
2089
+ PasteMenuFactory,
2090
+ DeleteMenuFactory
2091
+ ].forEach((factory) => {
2092
+ try {
2093
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
2094
+ } catch {
2095
+ }
2096
+ });
2097
+ }
2098
+ _initShortCut() {
1847
2099
  [
1848
- Br,
1849
- $r,
1850
- Hr,
1851
- Vr,
1852
- jr,
1853
- Wr,
1854
- Gr,
1855
- kr,
1856
- zr,
1857
- Yr,
1858
- Xr,
1859
- Kr,
1860
- Zr,
1861
- Jr,
1862
- qr,
1863
- Qr,
1864
- ei,
1865
- ti
1866
- ].forEach((e) => {
1867
- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(e), t));
2100
+ BoldShortCut,
2101
+ ItalicShortCut,
2102
+ UnderlineShortCut,
2103
+ StrikeThroughShortCut,
2104
+ SubscriptShortCut,
2105
+ SuperscriptShortCut,
2106
+ AlignCenterShortCut,
2107
+ AlignJustifyShortCut,
2108
+ AlignRightShortCut,
2109
+ AlignLeftShortCut,
2110
+ OrderListShortCut,
2111
+ BulletListShortCut
2112
+ ].forEach((shortcut) => {
2113
+ this.disposeWithMe(this._shortcutService.registerShortcut(shortcut));
1868
2114
  });
1869
2115
  }
1870
2116
  _init() {
1871
- this._initCustomComponents(), this._initMenus(), this._initFocusHandler();
2117
+ this._initCustomComponents(), this._initMenus(), this._initFocusHandler(), this._initUiParts(), this._initShortCut();
1872
2118
  }
1873
2119
  _initFocusHandler() {
1874
2120
  this.disposeWithMe(
1875
- this._layoutService.registerFocusHandler(v.UNIVER_DOC, () => {
1876
- this._injector.get(ne).focus();
2121
+ this._layoutService.registerFocusHandler(UniverInstanceType.UNIVER_DOC, () => {
2122
+ this._injector.get(ITextSelectionRenderManager).focus();
1877
2123
  })
1878
2124
  );
1879
2125
  }
2126
+ }, __name(_a6, "DocUIController"), _a6);
2127
+ DocUIController = __decorateClass$c([
2128
+ OnLifecycle(LifecycleStages.Rendered, DocUIController),
2129
+ __decorateParam$c(1, Inject(Injector)),
2130
+ __decorateParam$c(2, Inject(ComponentManager)),
2131
+ __decorateParam$c(3, ILayoutService),
2132
+ __decorateParam$c(4, IMenuService),
2133
+ __decorateParam$c(5, IUIPartsService),
2134
+ __decorateParam$c(6, IUniverInstanceService),
2135
+ __decorateParam$c(7, IShortcutService)
2136
+ ], DocUIController);
2137
+ const BreakLineShortcut = {
2138
+ id: BreakLineCommand.id,
2139
+ preconditions: whenDocAndEditorFocusedWithBreakLine,
2140
+ binding: KeyCode.ENTER
2141
+ }, DeleteLeftShortcut = {
2142
+ id: DeleteLeftCommand.id,
2143
+ preconditions: whenDocAndEditorFocused,
2144
+ binding: KeyCode.BACKSPACE
2145
+ }, DeleteRightShortcut = {
2146
+ id: DeleteRightCommand.id,
2147
+ preconditions: whenDocAndEditorFocused,
2148
+ binding: KeyCode.DELETE
1880
2149
  };
1881
- me = ri([
1882
- we(Be.Rendered, me),
1883
- Ee(1, I($e)),
1884
- Ee(2, I(tn)),
1885
- Ee(3, en),
1886
- Ee(4, Hn)
1887
- ], me);
1888
- const ii = {
1889
- id: go.id,
1890
- preconditions: Fo,
1891
- binding: H.ENTER
1892
- }, si = {
1893
- id: po.id,
1894
- preconditions: k,
1895
- binding: H.BACKSPACE
1896
- }, ai = {
1897
- id: fo.id,
1898
- preconditions: k,
1899
- binding: H.DELETE
1900
- };
1901
- function ze(t) {
1902
- return t.getContextValue(Ue) || t.getContextValue(qt);
1903
- }
1904
- const ft = 999, ci = {
1905
- id: Vn.id,
1906
- name: "doc.command.copy",
1907
- type: de.COMMAND,
1908
- multi: !0,
1909
- priority: ft,
1910
- preconditions: ze,
1911
- handler: async (t) => t.get(Re).copy()
1912
- }, li = {
1913
- id: jn.id,
1914
- name: "doc.command.cut",
1915
- type: de.COMMAND,
1916
- multi: !0,
1917
- priority: ft,
1918
- preconditions: ze,
1919
- handler: async (t) => t.get(Re).cut()
1920
- }, di = {
1921
- id: Wn.id,
1922
- name: "doc.command.paste",
1923
- type: de.COMMAND,
1924
- multi: !0,
1925
- priority: ft,
1926
- preconditions: ze,
1927
- handler: async (t) => {
1928
- const e = t.get(Re), o = await t.get(ut).read();
1929
- return o.length === 0 ? !1 : e.paste(o);
1930
- }
1931
- };
1932
- var ui = Object.defineProperty, hi = Object.getOwnPropertyDescriptor, gi = (t, e, n, o) => {
1933
- for (var r = o > 1 ? void 0 : o ? hi(e, n) : e, i = t.length - 1, s; i >= 0; i--)
1934
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
1935
- return o && r && ui(e, n, r), r;
1936
- }, he = (t, e) => (n, o) => e(n, o, t);
1937
- let Me = class extends Se {
1938
- constructor(t, e, n, o, r) {
1939
- super(), this._commandService = t, this._clipboardInterfaceService = e, this._docClipboardService = n, this._textSelectionRenderManager = o, this._contextService = r, this._init();
2150
+ var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2151
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2152
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2153
+ return kind && result && __defProp$b(target, key, result), result;
2154
+ }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b"), _a7;
2155
+ let DocClipboardController = (_a7 = class extends RxDisposable {
2156
+ constructor(_commandService, _clipboardInterfaceService, _docClipboardService, _textSelectionRenderManager, _contextService) {
2157
+ super(), this._commandService = _commandService, this._clipboardInterfaceService = _clipboardInterfaceService, this._docClipboardService = _docClipboardService, this._textSelectionRenderManager = _textSelectionRenderManager, this._contextService = _contextService, this._init();
1940
2158
  }
1941
2159
  _init() {
1942
- [ci, li, di].forEach((t) => this.disposeWithMe(this._commandService.registerMultipleCommand(t))), [on, nn].forEach((t) => this.disposeWithMe(this._commandService.registerCommand(t))), this._initLegacyPasteCommand();
2160
+ [DocCopyCommand, DocCutCommand, DocPasteCommand].forEach((command) => this.disposeWithMe(this._commandService.registerMultipleCommand(command))), [InnerPasteCommand, CutContentCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command))), this._initLegacyPasteCommand();
1943
2161
  }
1944
2162
  _initLegacyPasteCommand() {
1945
- var t;
1946
- (t = this._textSelectionRenderManager) == null || t.onPaste$.pipe(se(this.dispose$)).subscribe((e) => {
1947
- var i, s;
1948
- if (!ze(this._contextService))
2163
+ var _a19;
2164
+ (_a19 = this._textSelectionRenderManager) == null || _a19.onPaste$.pipe(takeUntil(this.dispose$)).subscribe((config) => {
2165
+ var _a20, _b;
2166
+ if (!whenDocOrEditor(this._contextService))
1949
2167
  return;
1950
- e.event.preventDefault();
1951
- const n = e.event, o = (i = n.clipboardData) == null ? void 0 : i.getData("text/html"), r = (s = n.clipboardData) == null ? void 0 : s.getData("text/plain");
1952
- this._docClipboardService.legacyPaste(o, r);
2168
+ config.event.preventDefault();
2169
+ const clipboardEvent = config.event, htmlContent = (_a20 = clipboardEvent.clipboardData) == null ? void 0 : _a20.getData("text/html"), textContent = (_b = clipboardEvent.clipboardData) == null ? void 0 : _b.getData("text/plain");
2170
+ this._docClipboardService.legacyPaste(htmlContent, textContent);
1953
2171
  });
1954
2172
  }
1955
- };
1956
- Me = gi([
1957
- we(Be.Rendered, Me),
1958
- he(0, O),
1959
- he(1, ut),
1960
- he(2, Re),
1961
- he(3, ne),
1962
- he(4, In)
1963
- ], Me);
1964
- var pi = Object.defineProperty, fi = Object.getOwnPropertyDescriptor, _i = (t, e, n, o) => {
1965
- for (var r = o > 1 ? void 0 : o ? fi(e, n) : e, i = t.length - 1, s; i >= 0; i--)
1966
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
1967
- return o && r && pi(e, n, r), r;
1968
- }, ge = (t, e) => (n, o) => e(n, o, t);
1969
- let ye = class extends Q {
1970
- constructor(e, n, o, r, i) {
2173
+ }, __name(_a7, "DocClipboardController"), _a7);
2174
+ DocClipboardController = __decorateClass$b([
2175
+ OnLifecycle(LifecycleStages.Rendered, DocClipboardController),
2176
+ __decorateParam$b(0, ICommandService),
2177
+ __decorateParam$b(1, IClipboardInterfaceService),
2178
+ __decorateParam$b(2, IDocClipboardService),
2179
+ __decorateParam$b(3, ITextSelectionRenderManager),
2180
+ __decorateParam$b(4, IContextService)
2181
+ ], DocClipboardController);
2182
+ var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2183
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2184
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2185
+ return kind && result && __defProp$a(target, key, result), result;
2186
+ }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a8;
2187
+ let DocEditorBridgeController = (_a8 = class extends Disposable {
2188
+ constructor(_univerInstanceService, _editorService, _commandService, _textSelectionRenderManager, _renderManagerService) {
1971
2189
  super();
1972
- T(this, "_initialEditors", /* @__PURE__ */ new Set());
1973
- this._univerInstanceService = e, this._editorService = n, this._commandService = o, this._textSelectionRenderManager = r, this._renderManagerService = i, this._initialize();
2190
+ __publicField(this, "_initialEditors", /* @__PURE__ */ new Set());
2191
+ this._univerInstanceService = _univerInstanceService, this._editorService = _editorService, this._commandService = _commandService, this._textSelectionRenderManager = _textSelectionRenderManager, this._renderManagerService = _renderManagerService, this._initialize();
1974
2192
  }
1975
2193
  _initialize() {
1976
2194
  this.disposeWithMe(
1977
- this._editorService.resize$.subscribe((e) => {
1978
- this._resize(e);
2195
+ this._editorService.resize$.subscribe((unitId) => {
2196
+ this._resize(unitId);
1979
2197
  })
1980
- ), this._editorService.getAllEditor().forEach((e) => {
1981
- const n = e.editorUnitId;
1982
- this._initialEditors.has(n) || (this._initialEditors.add(n), this._resize(n));
2198
+ ), this._editorService.getAllEditor().forEach((editor) => {
2199
+ const unitId = editor.editorUnitId;
2200
+ this._initialEditors.has(unitId) || (this._initialEditors.add(unitId), this._resize(unitId));
1983
2201
  }), this._commandExecutedListener(), this._initialSetValue(), this._initialBlur(), this._initialFocus(), this._initialValueChange();
1984
2202
  }
1985
- _resize(e) {
1986
- var C, E, b;
1987
- if (e == null)
2203
+ _resize(unitId) {
2204
+ var _a19, _b, _c;
2205
+ if (unitId == null)
1988
2206
  return;
1989
- const n = this._editorService.getEditor(e);
1990
- if ((n == null ? void 0 : n.cancelDefaultResizeListener) === !0)
2207
+ const editor = this._editorService.getEditor(unitId);
2208
+ if ((editor == null ? void 0 : editor.cancelDefaultResizeListener) === !0)
1991
2209
  return;
1992
- const o = this._univerInstanceService.getUniverDocInstance(e);
1993
- if (!o)
2210
+ const editorDataModel = this._univerInstanceService.getUniverDocInstance(unitId);
2211
+ if (!editorDataModel)
1994
2212
  return;
1995
- const r = (C = this._renderManagerService.getRenderById(o.getUnitId())) == null ? void 0 : C.with(L).getSkeleton();
1996
- if (n == null || n.render == null || r == null || o == null)
2213
+ const skeleton = (_a19 = this._renderManagerService.getRenderById(editorDataModel.getUnitId())) == null ? void 0 : _a19.with(DocSkeletonManagerService).getSkeleton();
2214
+ if (editor == null || editor.render == null || skeleton == null || editorDataModel == null)
1997
2215
  return;
1998
- r.calculate();
1999
- const { marginTop: i = 0, marginBottom: s = 0, marginLeft: a = 0, marginRight: c = 0 } = o.getSnapshot().documentStyle, { scene: d, mainComponent: g } = n.render;
2000
- let { actualHeight: h, actualWidth: p } = r.getActualSize();
2001
- h += i + s, p += a + c;
2002
- const { width: l, height: f } = n.getBoundingClientRect(), u = d.getViewport(q.VIEW_MAIN);
2003
- let _ = u == null ? void 0 : u.getScrollBar();
2004
- const m = Math.max(p, l), R = Math.max(h, f);
2005
- d.transformByState({
2006
- width: m,
2007
- height: R
2008
- }), g == null || g.resize(m, R), n.isSingle() ? p > l ? _ == null ? u && new tt(u, { barSize: 8, enableVertical: !1 }) : u == null || u.resetCanvasSizeAndUpdateScrollBar() : (_ = null, u == null || u.scrollTo({ x: 0, y: 0 }), (b = u == null ? void 0 : u.getScrollBar()) == null || b.dispose()) : h > f ? _ == null ? u && new tt(u, { enableHorizontal: !1, barSize: 8 }) : u == null || u.resetCanvasSizeAndUpdateScrollBar() : (_ = null, u == null || u.scrollTo({ x: 0, y: 0 }), (E = u == null ? void 0 : u.getScrollBar()) == null || E.dispose());
2216
+ skeleton.calculate();
2217
+ const { marginTop = 0, marginBottom = 0, marginLeft = 0, marginRight = 0 } = editorDataModel.getSnapshot().documentStyle, { scene, mainComponent } = editor.render;
2218
+ let { actualHeight, actualWidth } = skeleton.getActualSize();
2219
+ actualHeight += marginTop + marginBottom, actualWidth += marginLeft + marginRight;
2220
+ const { width, height } = editor.getBoundingClientRect(), viewportMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
2221
+ let scrollBar = viewportMain == null ? void 0 : viewportMain.getScrollBar();
2222
+ const contentWidth = Math.max(actualWidth, width), contentHeight = Math.max(actualHeight, height);
2223
+ scene.transformByState({
2224
+ width: contentWidth,
2225
+ height: contentHeight
2226
+ }), mainComponent == null || mainComponent.resize(contentWidth, contentHeight), editor.isSingle() ? actualWidth > width ? scrollBar == null ? viewportMain && new ScrollBar(viewportMain, { barSize: 8, enableVertical: !1 }) : viewportMain == null || viewportMain.resetCanvasSizeAndUpdateScroll() : (scrollBar = null, viewportMain == null || viewportMain.scrollToBarPos({ x: 0, y: 0 }), (_c = viewportMain == null ? void 0 : viewportMain.getScrollBar()) == null || _c.dispose()) : actualHeight > height ? scrollBar == null ? viewportMain && new ScrollBar(viewportMain, { enableHorizontal: !1, barSize: 8 }) : viewportMain == null || viewportMain.resetCanvasSizeAndUpdateScroll() : (scrollBar = null, viewportMain == null || viewportMain.scrollToBarPos({ x: 0, y: 0 }), (_b = viewportMain == null ? void 0 : viewportMain.getScrollBar()) == null || _b.dispose());
2009
2227
  }
2010
2228
  _initialSetValue() {
2011
2229
  this.disposeWithMe(
2012
- this._editorService.setValue$.subscribe((e) => {
2013
- this._commandService.executeCommand(_o.id, {
2014
- unitId: e.editorUnitId,
2015
- body: e.body,
2230
+ this._editorService.setValue$.subscribe((param) => {
2231
+ this._commandService.executeCommand(CoverContentCommand.id, {
2232
+ unitId: param.editorUnitId,
2233
+ body: param.body,
2016
2234
  segmentId: null
2017
2235
  });
2018
2236
  })
@@ -2025,40 +2243,40 @@ let ye = class extends Q {
2025
2243
  })
2026
2244
  ), this.disposeWithMe(
2027
2245
  this._textSelectionRenderManager.onBlur$.subscribe(() => {
2028
- var r;
2029
- const e = (r = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : r.getUnitId();
2030
- if (e == null)
2246
+ var _a19;
2247
+ const unitId = (_a19 = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a19.getUnitId();
2248
+ if (unitId == null)
2031
2249
  return;
2032
- const n = this._editorService.getEditor(e), o = this._editorService.getFocusEditor();
2033
- n == null || n.isSheetEditor() || o && o.editorUnitId === e || this._editorService.blur();
2250
+ const editor = this._editorService.getEditor(unitId), focusEditor = this._editorService.getFocusEditor();
2251
+ editor == null || editor.isSheetEditor() || focusEditor && focusEditor.editorUnitId === unitId || this._editorService.blur();
2034
2252
  })
2035
2253
  );
2036
2254
  }
2037
2255
  _initialFocus() {
2038
2256
  this.disposeWithMe(
2039
- this._editorService.focus$.subscribe((o) => {
2040
- this._textSelectionRenderManager.removeAllTextRanges(), this._textSelectionRenderManager.addTextRanges([o]);
2257
+ this._editorService.focus$.subscribe((textRange) => {
2258
+ this._textSelectionRenderManager.removeAllTextRanges(), this._textSelectionRenderManager.addTextRanges([textRange]);
2041
2259
  })
2042
2260
  );
2043
- const e = [
2261
+ const focusExcepts = [
2044
2262
  "univer-formula-search",
2045
2263
  "univer-formula-help",
2046
2264
  "formula-help-decorator",
2047
2265
  "univer-formula-help-param"
2048
2266
  ];
2049
2267
  this.disposeWithMe(
2050
- yt(window, "mousedown").subscribe((o) => {
2051
- const i = o.target.classList[0] || "";
2052
- if (bn(i, e)) {
2053
- this._editorService.changeSpreadsheetFocusState(!0), o.stopPropagation();
2268
+ fromEvent(window, "mousedown").subscribe((event) => {
2269
+ const hasSearch = event.target.classList[0] || "";
2270
+ if (checkForSubstrings(hasSearch, focusExcepts)) {
2271
+ this._editorService.changeSpreadsheetFocusState(!0), event.stopPropagation();
2054
2272
  return;
2055
2273
  }
2056
2274
  this._editorService.changeSpreadsheetFocusState(!1);
2057
2275
  })
2058
- ), this._univerInstanceService.getAllUnitsForType(v.UNIVER_SHEET).forEach((o) => {
2059
- const r = o.getUnitId(), i = this._renderManagerService.getRenderById(r), s = i == null ? void 0 : i.engine.getCanvas().getCanvasEle();
2060
- s != null && yt(s, "mousedown").subscribe((a) => {
2061
- this._editorService.changeSpreadsheetFocusState(!0), a.stopPropagation();
2276
+ ), this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).forEach((unit) => {
2277
+ const unitId = unit.getUnitId(), render = this._renderManagerService.getRenderById(unitId), canvasEle = render == null ? void 0 : render.engine.getCanvas().getCanvasEle();
2278
+ canvasEle != null && fromEvent(canvasEle, "mousedown").subscribe((evt) => {
2279
+ this._editorService.changeSpreadsheetFocusState(!0), evt.stopPropagation();
2062
2280
  });
2063
2281
  });
2064
2282
  }
@@ -2074,60 +2292,60 @@ let ye = class extends Q {
2074
2292
  );
2075
2293
  }
2076
2294
  _valueChange() {
2077
- var o;
2078
- const e = (o = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : o.getUnitId();
2079
- if (e == null)
2295
+ var _a19;
2296
+ const unitId = (_a19 = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a19.getUnitId();
2297
+ if (unitId == null)
2080
2298
  return;
2081
- const n = this._editorService.getEditor(e);
2082
- n == null || n.isSheetEditor() || this._editorService.refreshValueChange(e);
2299
+ const editor = this._editorService.getEditor(unitId);
2300
+ editor == null || editor.isSheetEditor() || this._editorService.refreshValueChange(unitId);
2083
2301
  }
2084
2302
  /**
2085
2303
  * Listen to document edits to refresh the size of the formula editor.
2086
2304
  */
2087
2305
  _commandExecutedListener() {
2088
- const e = [ht.id, kn.id];
2306
+ const updateCommandList = [RichTextEditingMutation.id, SetEditorResizeOperation.id];
2089
2307
  this.disposeWithMe(
2090
- this._commandService.onCommandExecuted((n) => {
2091
- if (e.includes(n.id)) {
2092
- const o = n.params, { unitId: r } = o;
2093
- if (this._editorService.isSheetEditor(r))
2308
+ this._commandService.onCommandExecuted((command) => {
2309
+ if (updateCommandList.includes(command.id)) {
2310
+ const params = command.params, { unitId } = params;
2311
+ if (this._editorService.isSheetEditor(unitId))
2094
2312
  return;
2095
- this._resize(r), this._valueChange();
2313
+ this._resize(unitId), this._valueChange();
2096
2314
  }
2097
2315
  })
2098
2316
  );
2099
2317
  }
2100
- };
2101
- ye = _i([
2102
- we(Be.Rendered, ye),
2103
- ge(0, w),
2104
- ge(1, ee),
2105
- ge(2, O),
2106
- ge(3, ne),
2107
- ge(4, W)
2108
- ], ye);
2109
- var mi = Object.defineProperty, Si = Object.getOwnPropertyDescriptor, vi = (t, e, n, o) => {
2110
- for (var r = o > 1 ? void 0 : o ? Si(e, n) : e, i = t.length - 1, s; i >= 0; i--)
2111
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
2112
- return o && r && mi(e, n, r), r;
2113
- }, pe = (t, e) => (n, o) => e(n, o, t);
2114
- let st = class extends Se {
2115
- constructor(t, e, n, o, r, i) {
2116
- super(), this._context = t, this._commandService = e, this._docSkeletonManagerService = n, this._configService = o, this._editorService = r, this._renderManagerService = i, this._addNewRender(), this._initRenderRefresh(), this._initCommandListener();
2117
- }
2118
- reRender(t) {
2119
- var r, i;
2120
- const e = (r = this._renderManagerService.getRenderById(t)) == null ? void 0 : r.with(L), n = e == null ? void 0 : e.getSkeleton();
2121
- if (!(!n || n.getViewModel().getDataModel().getSnapshot().disabled)) {
2122
- if (n.calculate(), this._editorService.isEditor(t)) {
2123
- (i = this._context.mainComponent) == null || i.makeDirty();
2318
+ }, __name(_a8, "DocEditorBridgeController"), _a8);
2319
+ DocEditorBridgeController = __decorateClass$a([
2320
+ OnLifecycle(LifecycleStages.Rendered, DocEditorBridgeController),
2321
+ __decorateParam$a(0, IUniverInstanceService),
2322
+ __decorateParam$a(1, IEditorService),
2323
+ __decorateParam$a(2, ICommandService),
2324
+ __decorateParam$a(3, ITextSelectionRenderManager),
2325
+ __decorateParam$a(4, IRenderManagerService)
2326
+ ], DocEditorBridgeController);
2327
+ var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2328
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2329
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2330
+ return kind && result && __defProp$9(target, key, result), result;
2331
+ }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a9;
2332
+ let DocRenderController = (_a9 = class extends RxDisposable {
2333
+ constructor(_context, _commandService, _docSkeletonManagerService, _configService, _editorService, _renderManagerService) {
2334
+ super(), this._context = _context, this._commandService = _commandService, this._docSkeletonManagerService = _docSkeletonManagerService, this._configService = _configService, this._editorService = _editorService, this._renderManagerService = _renderManagerService, this._addNewRender(), this._initRenderRefresh(), this._initCommandListener();
2335
+ }
2336
+ reRender(unitId) {
2337
+ var _a19, _b;
2338
+ const docSkeletonManagerService = (_a19 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a19.with(DocSkeletonManagerService), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
2339
+ if (!(!skeleton || skeleton.getViewModel().getDataModel().getSnapshot().disabled)) {
2340
+ if (skeleton.calculate(), this._editorService.isEditor(unitId)) {
2341
+ (_b = this._context.mainComponent) == null || _b.makeDirty();
2124
2342
  return;
2125
2343
  }
2126
- this._recalculateSizeBySkeleton(n);
2344
+ this._recalculateSizeBySkeleton(skeleton);
2127
2345
  }
2128
2346
  }
2129
2347
  _addNewRender() {
2130
- const { scene: t, engine: e, unit: n } = this._context, o = new To(q.VIEW_MAIN, t, {
2348
+ const { scene, engine, unit } = this._context, viewMain = new Viewport(VIEWPORT_KEY.VIEW_MAIN, scene, {
2131
2349
  left: 0,
2132
2350
  top: 0,
2133
2351
  bottom: 0,
@@ -2136,238 +2354,243 @@ let st = class extends Se {
2136
2354
  isRelativeY: !0,
2137
2355
  isWheelPreventDefaultX: !0
2138
2356
  });
2139
- t.attachControl(), t.onMouseWheel$.subscribeEvent((s, a) => {
2140
- const c = s;
2141
- if (c.ctrlKey) {
2142
- const d = Math.abs(c.deltaX);
2143
- let g = d < 40 ? 0.2 : d < 80 ? 0.4 : 0.2;
2144
- g *= c.deltaY > 0 ? -1 : 1, t.scaleX < 1 && (g /= 2), t.scaleX + g > 4 ? t.scale(4, 4) : t.scaleX + g < 0.1 ? t.scale(0.1, 0.1) : c.preventDefault();
2357
+ scene.attachControl(), scene.onMouseWheel$.subscribeEvent((evt, state) => {
2358
+ const e = evt;
2359
+ if (e.ctrlKey) {
2360
+ const deltaFactor = Math.abs(e.deltaX);
2361
+ let scrollNum = deltaFactor < 40 ? 0.2 : deltaFactor < 80 ? 0.4 : 0.2;
2362
+ scrollNum *= e.deltaY > 0 ? -1 : 1, scene.scaleX < 1 && (scrollNum /= 2), scene.scaleX + scrollNum > 4 ? scene.scale(4, 4) : scene.scaleX + scrollNum < 0.1 ? scene.scale(0.1, 0.1) : e.preventDefault();
2145
2363
  } else
2146
- o.onMouseWheel(c, a);
2147
- }), this._configService.getConfig("hasScroll") !== !1 && new tt(o), t.addLayer(
2148
- new bt(t, [], Ye),
2149
- new bt(t, [], mo)
2150
- ), this._addComponent(), n.getShouldRenderLoopImmediately() && e.runRenderLoop(() => {
2151
- t.render();
2364
+ viewMain.onMouseWheel(e, state);
2365
+ }), this._configService.getConfig("hasScroll") !== !1 && new ScrollBar(viewMain), scene.addLayer(
2366
+ new Layer(scene, [], DOCS_COMPONENT_MAIN_LAYER_INDEX),
2367
+ new Layer(scene, [], DOCS_COMPONENT_HEADER_LAYER_INDEX)
2368
+ ), this._addComponent(), unit.getShouldRenderLoopImmediately() && engine.runRenderLoop(() => {
2369
+ scene.render();
2152
2370
  });
2153
2371
  }
2154
2372
  _addComponent() {
2155
- const { scene: t, unit: e, components: n } = this._context, o = {
2156
- pageMarginLeft: e.documentStyle.marginLeft || 0,
2157
- pageMarginTop: e.documentStyle.marginTop || 0
2158
- }, r = new Io(oe.MAIN, void 0, o);
2159
- r.zIndex = Et;
2160
- const i = new bo(oe.BACKGROUND, void 0, o);
2161
- i.zIndex = Et, this._context.mainComponent = r, n.set(oe.MAIN, r), n.set(oe.BACKGROUND, i), t.addObjects([r], Ye), t.addObjects([i], So), this._editorService.getEditor(e.getUnitId()) == null && t.enableLayerCache(Ye);
2373
+ const { scene, unit: documentModel, components } = this._context, config = {
2374
+ pageMarginLeft: documentModel.documentStyle.marginLeft || 0,
2375
+ pageMarginTop: documentModel.documentStyle.marginTop || 0
2376
+ }, documents = new Documents(DOCS_VIEW_KEY.MAIN, void 0, config);
2377
+ documents.zIndex = DOCS_COMPONENT_DEFAULT_Z_INDEX;
2378
+ const docBackground = new DocBackground(DOCS_VIEW_KEY.BACKGROUND, void 0, config);
2379
+ docBackground.zIndex = DOCS_COMPONENT_DEFAULT_Z_INDEX, this._context.mainComponent = documents, components.set(DOCS_VIEW_KEY.MAIN, documents), components.set(DOCS_VIEW_KEY.BACKGROUND, docBackground), scene.addObjects([documents], DOCS_COMPONENT_MAIN_LAYER_INDEX), scene.addObjects([docBackground], DOCS_COMPONENT_BACKGROUND_LAYER_INDEX), this._editorService.getEditor(documentModel.getUnitId()) == null && scene.enableLayerCache(DOCS_COMPONENT_MAIN_LAYER_INDEX);
2162
2380
  }
2163
2381
  _initRenderRefresh() {
2164
- this._docSkeletonManagerService.currentSkeletonBefore$.pipe(se(this.dispose$)).subscribe((t) => {
2165
- this._create(t);
2382
+ this._docSkeletonManagerService.currentSkeletonBefore$.pipe(takeUntil(this.dispose$)).subscribe((param) => {
2383
+ this._create(param);
2166
2384
  });
2167
2385
  }
2168
- _create(t) {
2169
- if (!t)
2386
+ _create(skeleton) {
2387
+ if (!skeleton)
2170
2388
  return;
2171
- const { mainComponent: e, components: n } = this._context, o = e, r = n.get(oe.BACKGROUND);
2172
- o.changeSkeleton(t), r.changeSkeleton(t), this._recalculateSizeBySkeleton(t);
2389
+ const { mainComponent, components } = this._context, docsComponent = mainComponent, docBackground = components.get(DOCS_VIEW_KEY.BACKGROUND);
2390
+ docsComponent.changeSkeleton(skeleton), docBackground.changeSkeleton(skeleton), this._recalculateSizeBySkeleton(skeleton);
2173
2391
  }
2174
2392
  _initCommandListener() {
2175
- const t = [ht.id];
2176
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
2177
- if (t.includes(e.id)) {
2178
- const n = e.params, { unitId: o } = n;
2179
- this.reRender(o);
2393
+ const updateCommandList = [RichTextEditingMutation.id];
2394
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2395
+ if (updateCommandList.includes(command.id)) {
2396
+ const params = command.params, { unitId } = params;
2397
+ this.reRender(unitId);
2180
2398
  }
2181
2399
  }));
2182
2400
  }
2183
- _recalculateSizeBySkeleton(t) {
2184
- var g;
2185
- const { mainComponent: e, scene: n, unitId: o, components: r } = this._context, i = e, s = r.get(oe.BACKGROUND), a = (g = t.getSkeletonData()) == null ? void 0 : g.pages;
2186
- if (a == null)
2401
+ _recalculateSizeBySkeleton(skeleton) {
2402
+ var _a19;
2403
+ const { mainComponent, scene, unitId, components } = this._context, docsComponent = mainComponent, docBackground = components.get(DOCS_VIEW_KEY.BACKGROUND), pages = (_a19 = skeleton.getSkeletonData()) == null ? void 0 : _a19.pages;
2404
+ if (pages == null)
2187
2405
  return;
2188
- let c = 0, d = 0;
2189
- for (let h = 0, p = a.length; h < p; h++) {
2190
- const l = a[h], { pageWidth: f, pageHeight: u } = l;
2191
- i.pageLayoutType === Ae.VERTICAL ? (d += u, d += i.pageMarginTop, h === p - 1 && (d += i.pageMarginTop), c = Math.max(c, f)) : i.pageLayoutType === Ae.HORIZONTAL && (c += f, h !== p - 1 && (c += i.pageMarginLeft), d = Math.max(d, u));
2406
+ let width = 0, height = 0;
2407
+ for (let i = 0, len = pages.length; i < len; i++) {
2408
+ const page = pages[i], { pageWidth, pageHeight } = page;
2409
+ docsComponent.pageLayoutType === PageLayoutType.VERTICAL ? (height += pageHeight, height += docsComponent.pageMarginTop, i === len - 1 && (height += docsComponent.pageMarginTop), width = Math.max(width, pageWidth)) : docsComponent.pageLayoutType === PageLayoutType.HORIZONTAL && (width += pageWidth, i !== len - 1 && (width += docsComponent.pageMarginLeft), height = Math.max(height, pageHeight));
2192
2410
  }
2193
- i.resize(c, d), s.resize(c, d), this._editorService.isEditor(o) || n.resize(c, d);
2411
+ docsComponent.resize(width, height), docBackground.resize(width, height), this._editorService.isEditor(unitId) || scene.resize(width, height);
2412
+ }
2413
+ }, __name(_a9, "DocRenderController"), _a9);
2414
+ DocRenderController = __decorateClass$9([
2415
+ __decorateParam$9(1, ICommandService),
2416
+ __decorateParam$9(2, Inject(DocSkeletonManagerService)),
2417
+ __decorateParam$9(3, IConfigService),
2418
+ __decorateParam$9(4, IEditorService),
2419
+ __decorateParam$9(5, IRenderManagerService)
2420
+ ], DocRenderController);
2421
+ const _DocPageLayoutService = class _DocPageLayoutService extends Disposable {
2422
+ constructor(_context) {
2423
+ super(), this._context = _context;
2424
+ }
2425
+ calculatePagePosition() {
2426
+ var _a19, _b;
2427
+ const docObject = neoGetDocObject(this._context), zoomRatio = (_b = (_a19 = this._context.unit.getSettings()) == null ? void 0 : _a19.zoomRatio) != null ? _b : 1, { document: docsComponent, scene, docBackground } = docObject, parent = scene == null ? void 0 : scene.getParent(), { width: docsWidth, height: docsHeight, pageMarginLeft, pageMarginTop } = docsComponent;
2428
+ if (parent == null || docsWidth === Number.POSITIVE_INFINITY || docsHeight === Number.POSITIVE_INFINITY)
2429
+ return;
2430
+ const { width: engineWidth, height: engineHeight } = parent;
2431
+ let docsLeft = 0, docsTop = 0, sceneWidth = 0, sceneHeight = 0, scrollToX = Number.POSITIVE_INFINITY;
2432
+ engineWidth > (docsWidth + pageMarginLeft * 2) * zoomRatio ? (docsLeft = engineWidth / 2 - docsWidth * zoomRatio / 2, docsLeft /= zoomRatio, sceneWidth = (engineWidth - pageMarginLeft * 2) / zoomRatio, scrollToX = 0) : (docsLeft = pageMarginLeft, sceneWidth = docsWidth + pageMarginLeft * 2, scrollToX = (sceneWidth - engineWidth / zoomRatio) / 2), engineHeight > docsHeight ? (docsTop = engineHeight / 2 - docsHeight / 2, sceneHeight = (engineHeight - pageMarginTop * 2) / zoomRatio) : (docsTop = pageMarginTop, sceneHeight = docsHeight + pageMarginTop * 2), scene.resize(sceneWidth, sceneHeight + 200), docsComponent.translate(docsLeft, docsTop), docBackground.translate(docsLeft, docsTop);
2433
+ const viewport = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
2434
+ return scrollToX !== Number.POSITIVE_INFINITY && viewport != null && viewport.scrollToViewportPos({
2435
+ viewportScrollX: scrollToX
2436
+ }), this;
2194
2437
  }
2195
2438
  };
2196
- st = vi([
2197
- pe(1, O),
2198
- pe(2, I(L)),
2199
- pe(3, Mn),
2200
- pe(4, ee),
2201
- pe(5, W)
2202
- ], st);
2203
- var Ri = Object.defineProperty, Oi = Object.getOwnPropertyDescriptor, Ci = (t, e, n, o) => {
2204
- for (var r = o > 1 ? void 0 : o ? Oi(e, n) : e, i = t.length - 1, s; i >= 0; i--)
2205
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
2206
- return o && r && Ri(e, n, r), r;
2207
- }, fe = (t, e) => (n, o) => e(n, o, t);
2208
- let at = class extends Q {
2209
- constructor(t, e, n, o, r, i) {
2210
- super(), this._context = t, this._docSkeletonManagerService = e, this._univerInstanceService = n, this._commandService = o, this._textSelectionManagerService = r, this._editorService = i, this._init();
2439
+ __name(_DocPageLayoutService, "DocPageLayoutService");
2440
+ let DocPageLayoutService = _DocPageLayoutService;
2441
+ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2442
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2443
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2444
+ return kind && result && __defProp$8(target, key, result), result;
2445
+ }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a10;
2446
+ let DocZoomRenderController = (_a10 = class extends Disposable {
2447
+ constructor(_context, _docSkeletonManagerService, _univerInstanceService, _commandService, _textSelectionManagerService, _editorService, _docPageLayoutService) {
2448
+ super(), this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._editorService = _editorService, this._docPageLayoutService = _docPageLayoutService, this._init();
2211
2449
  }
2212
2450
  _init() {
2213
- this._initSkeletonListener(), this._initCommandExecutedListener(), this._initRenderRefresher(), setTimeout(() => this._updateViewZoom(1, !0), 20);
2451
+ this._initSkeletonListener(), this._initCommandExecutedListener(), this._initRenderRefresher(), setTimeout(() => this.updateViewZoom(1, !0), 20);
2214
2452
  }
2215
2453
  _initRenderRefresher() {
2216
- this._docSkeletonManagerService.currentSkeleton$.subscribe((t) => {
2217
- if (t == null)
2454
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((param) => {
2455
+ if (param == null)
2218
2456
  return;
2219
- const { unitId: e, scene: n } = this._context;
2220
- this._editorService.isEditor(e) || this.disposeWithMe(n.onMouseWheel$.subscribeEvent((o) => {
2221
- if (!o.ctrlKey)
2457
+ const { unitId, scene } = this._context;
2458
+ this._editorService.isEditor(unitId) || this.disposeWithMe(scene.onMouseWheel$.subscribeEvent((e) => {
2459
+ if (!e.ctrlKey)
2222
2460
  return;
2223
- const r = this._univerInstanceService.getCurrentUniverDocInstance();
2224
- if (!r)
2461
+ const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
2462
+ if (!documentModel)
2225
2463
  return;
2226
- const i = Math.abs(o.deltaX);
2227
- let s = i < 40 ? 0.2 : i < 80 ? 0.4 : 0.2;
2228
- s *= o.deltaY > 0 ? -1 : 1, n.scaleX < 1 && (s /= 2);
2229
- const a = r.zoomRatio;
2230
- let c = +Number.parseFloat(`${a + s}`).toFixed(1);
2231
- c = c >= 4 ? 4 : c <= 0.1 ? 0.1 : c, this._commandService.executeCommand(vo.id, {
2232
- zoomRatio: c,
2233
- unitId: r.getUnitId()
2234
- }), o.preventDefault();
2464
+ const deltaFactor = Math.abs(e.deltaX);
2465
+ let ratioDelta = deltaFactor < 40 ? 0.2 : deltaFactor < 80 ? 0.4 : 0.2;
2466
+ ratioDelta *= e.deltaY > 0 ? -1 : 1, scene.scaleX < 1 && (ratioDelta /= 2);
2467
+ const currentRatio = documentModel.zoomRatio;
2468
+ let nextRatio = +Number.parseFloat(`${currentRatio + ratioDelta}`).toFixed(1);
2469
+ nextRatio = nextRatio >= 4 ? 4 : nextRatio <= 0.1 ? 0.1 : nextRatio, this._commandService.executeCommand(SetDocZoomRatioCommand.id, {
2470
+ zoomRatio: nextRatio,
2471
+ unitId: documentModel.getUnitId()
2472
+ }), e.preventDefault();
2235
2473
  }));
2236
2474
  });
2237
2475
  }
2238
2476
  _initSkeletonListener() {
2239
- this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((t) => {
2240
- if (t == null)
2477
+ this.disposeWithMe(this._docSkeletonManagerService.currentSkeleton$.subscribe((param) => {
2478
+ if (param == null)
2241
2479
  return;
2242
- const e = this._univerInstanceService.getCurrentUniverDocInstance();
2243
- if (!e) return;
2244
- const n = e.zoomRatio || 1;
2245
- this._updateViewZoom(n, !1);
2480
+ const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
2481
+ if (!documentModel) return;
2482
+ const zoomRatio = documentModel.zoomRatio || 1;
2483
+ this.updateViewZoom(zoomRatio, !1);
2246
2484
  }));
2247
2485
  }
2248
2486
  _initCommandExecutedListener() {
2249
- const t = [De.id];
2250
- this.disposeWithMe(this._commandService.onCommandExecuted((e) => {
2251
- if (t.includes(e.id)) {
2252
- const n = this._univerInstanceService.getCurrentUniverDocInstance();
2253
- if (!n) return;
2254
- const o = e.params, { unitId: r } = o;
2255
- if (r !== n.getUnitId())
2487
+ const updateCommandList = [SetDocZoomRatioOperation.id];
2488
+ this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
2489
+ if (updateCommandList.includes(command.id)) {
2490
+ const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
2491
+ if (!documentModel) return;
2492
+ const params = command.params, { unitId } = params;
2493
+ if (unitId !== documentModel.getUnitId())
2256
2494
  return;
2257
- const i = n.zoomRatio || 1;
2258
- this._updateViewZoom(i);
2495
+ const zoomRatio = documentModel.zoomRatio || 1;
2496
+ this.updateViewZoom(zoomRatio);
2259
2497
  }
2260
2498
  }));
2261
2499
  }
2262
- _updateViewZoom(t, e = !0) {
2263
- var o;
2264
- const n = J(this._context);
2265
- n.scene.scale(t, t), this._calculatePagePosition(n, t), e && this._textSelectionManagerService.refreshSelection(), (o = n.scene.getTransformer()) == null || o.clearSelectedObjects();
2266
- }
2267
- _calculatePagePosition(t, e) {
2268
- const { document: n, scene: o, docBackground: r } = t, i = o == null ? void 0 : o.getParent(), { width: s, height: a, pageMarginLeft: c, pageMarginTop: d } = n;
2269
- if (i == null || s === Number.POSITIVE_INFINITY || a === Number.POSITIVE_INFINITY)
2270
- return;
2271
- const { width: g, height: h } = i;
2272
- let p = 0, l = 0, f = 0, u = 0, _ = Number.POSITIVE_INFINITY;
2273
- g > (s + c * 2) * e ? (p = g / 2 - s * e / 2, p /= e, f = (g - c * 2) / e, _ = 0) : (p = c, f = s + c * 2, _ = (f - g / e) / 2), h > a ? (l = h / 2 - a / 2, u = (h - d * 2) / e) : (l = d, u = a + d * 2), o.resize(f, u + 200), n.translate(p, l), r.translate(p, l);
2274
- const m = o.getViewport(q.VIEW_MAIN);
2275
- if (_ !== Number.POSITIVE_INFINITY && m != null) {
2276
- const R = m.transViewportScroll2ScrollValue(_, 0).x;
2277
- m.scrollTo({
2278
- x: R
2279
- });
2280
- }
2281
- return this;
2282
- }
2283
- };
2284
- at = Ci([
2285
- fe(1, I(L)),
2286
- fe(2, w),
2287
- fe(3, O),
2288
- fe(4, I(te)),
2289
- fe(5, ee)
2290
- ], at);
2291
- var Ei = Object.defineProperty, Ti = Object.getOwnPropertyDescriptor, Ii = (t, e, n, o) => {
2292
- for (var r = o > 1 ? void 0 : o ? Ti(e, n) : e, i = t.length - 1, s; i >= 0; i--)
2293
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
2294
- return o && r && Ei(e, n, r), r;
2295
- }, ie = (t, e) => (n, o) => e(n, o, t);
2296
- let ct = class extends Q {
2297
- constructor(e, n, o, r, i, s, a) {
2500
+ updateViewZoom(zoomRatio, needRefreshSelection = !0) {
2501
+ var _a19;
2502
+ const docObject = neoGetDocObject(this._context);
2503
+ docObject.scene.scale(zoomRatio, zoomRatio), this._docPageLayoutService.calculatePagePosition(), needRefreshSelection && !this._editorService.isEditor(this._context.unitId) && this._textSelectionManagerService.refreshSelection(), (_a19 = docObject.scene.getTransformer()) == null || _a19.clearSelectedObjects();
2504
+ }
2505
+ }, __name(_a10, "DocZoomRenderController"), _a10);
2506
+ DocZoomRenderController = __decorateClass$8([
2507
+ __decorateParam$8(1, Inject(DocSkeletonManagerService)),
2508
+ __decorateParam$8(2, IUniverInstanceService),
2509
+ __decorateParam$8(3, ICommandService),
2510
+ __decorateParam$8(4, Inject(TextSelectionManagerService)),
2511
+ __decorateParam$8(5, IEditorService),
2512
+ __decorateParam$8(6, Inject(DocPageLayoutService))
2513
+ ], DocZoomRenderController);
2514
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2515
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2516
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2517
+ return kind && result && __defProp$7(target, key, result), result;
2518
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a11;
2519
+ let DocTextSelectionRenderController = (_a11 = class extends Disposable {
2520
+ constructor(_context, _commandService, _editorService, _instanceSrv, _textSelectionRenderManager, _docSkeletonManagerService, _textSelectionManagerService) {
2298
2521
  super();
2299
- T(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
2300
- this._context = e, this._commandService = n, this._editorService = o, this._instanceSrv = r, this._textSelectionRenderManager = i, this._docSkeletonManagerService = s, this._textSelectionManagerService = a, this._initialize();
2522
+ __publicField(this, "_loadedMap", /* @__PURE__ */ new WeakSet());
2523
+ this._context = _context, this._commandService = _commandService, this._editorService = _editorService, this._instanceSrv = _instanceSrv, this._textSelectionRenderManager = _textSelectionRenderManager, this._docSkeletonManagerService = _docSkeletonManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._initialize();
2301
2524
  }
2302
2525
  _initialize() {
2303
2526
  this._init(), this._skeletonListener(), this._commandExecutedListener();
2304
2527
  }
2305
2528
  _init() {
2306
- const { unitId: e } = this._context, n = J(this._context);
2307
- n == null || n.document == null || this._loadedMap.has(n.document) || (this._initialMain(e), this._loadedMap.add(n.document));
2529
+ const { unitId } = this._context, docObject = neoGetDocObject(this._context);
2530
+ docObject == null || docObject.document == null || this._loadedMap.has(docObject.document) || (this._initialMain(unitId), this._loadedMap.add(docObject.document));
2308
2531
  }
2309
2532
  // eslint-disable-next-line max-lines-per-function
2310
- _initialMain(e) {
2311
- const n = J(this._context), { document: o, scene: r } = n;
2312
- this.disposeWithMe(o.onPointerEnter$.subscribeEvent(() => {
2313
- this._isEditorReadOnly(e) || (o.cursor = Mt.TEXT);
2314
- })), this.disposeWithMe(o.onPointerLeave$.subscribeEvent(() => {
2315
- o.cursor = Mt.DEFAULT, r.resetCursor();
2316
- })), this.disposeWithMe(o.onPointerDown$.subscribeEvent((i, s) => {
2317
- if (this._isEditorReadOnly(e))
2533
+ _initialMain(unitId) {
2534
+ const docObject = neoGetDocObject(this._context), { document, scene } = docObject;
2535
+ this.disposeWithMe(document.onPointerEnter$.subscribeEvent(() => {
2536
+ this._isEditorReadOnly(unitId) || (document.cursor = CURSOR_TYPE.TEXT);
2537
+ })), this.disposeWithMe(document.onPointerLeave$.subscribeEvent(() => {
2538
+ document.cursor = CURSOR_TYPE.DEFAULT, scene.resetCursor();
2539
+ })), this.disposeWithMe(document.onPointerDown$.subscribeEvent((evt, state) => {
2540
+ if (this._isEditorReadOnly(unitId))
2318
2541
  return;
2319
- const a = this._instanceSrv.getCurrentUnitForType(v.UNIVER_DOC);
2320
- (a == null ? void 0 : a.getUnitId()) !== e && this._instanceSrv.setCurrentUnitForType(e);
2321
- const c = this._docSkeletonManagerService.getSkeleton(), { offsetX: d, offsetY: g } = i, h = this._getTransformCoordForDocumentOffset(d, g);
2322
- if (h != null) {
2542
+ const docDataModel = this._instanceSrv.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
2543
+ (docDataModel == null ? void 0 : docDataModel.getUnitId()) !== unitId && this._instanceSrv.setCurrentUnitForType(unitId);
2544
+ const skeleton = this._docSkeletonManagerService.getSkeleton(), { offsetX, offsetY } = evt, coord = this._getTransformCoordForDocumentOffset(offsetX, offsetY);
2545
+ if (coord != null) {
2323
2546
  const {
2324
- pageLayoutType: p = Ae.VERTICAL,
2325
- pageMarginLeft: l,
2326
- pageMarginTop: f
2327
- } = o.getOffsetConfig(), { editArea: u } = c.findEditAreaByCoord(
2328
- h,
2329
- p,
2330
- l,
2331
- f
2332
- ), _ = this._docSkeletonManagerService.getViewModel(), m = _.getEditArea();
2333
- m !== F.BODY && u !== F.BODY && u !== m && _.setEditArea(u);
2547
+ pageLayoutType = PageLayoutType.VERTICAL,
2548
+ pageMarginLeft,
2549
+ pageMarginTop
2550
+ } = document.getOffsetConfig(), { editArea } = skeleton.findEditAreaByCoord(
2551
+ coord,
2552
+ pageLayoutType,
2553
+ pageMarginLeft,
2554
+ pageMarginTop
2555
+ ), viewModel = this._docSkeletonManagerService.getViewModel(), preEditArea = viewModel.getEditArea();
2556
+ preEditArea !== DocumentEditArea.BODY && editArea !== DocumentEditArea.BODY && editArea !== preEditArea && viewModel.setEditArea(editArea);
2334
2557
  }
2335
- if (this._textSelectionRenderManager.eventTrigger(i), this._editorService.getEditor(e)) {
2336
- this._setEditorFocus(e);
2337
- const { offsetX: p, offsetY: l } = i;
2558
+ if (this._textSelectionRenderManager.eventTrigger(evt), this._editorService.getEditor(unitId)) {
2559
+ this._setEditorFocus(unitId);
2560
+ const { offsetX: offsetX2, offsetY: offsetY2 } = evt;
2338
2561
  setTimeout(() => {
2339
- this._setEditorFocus(e), this._textSelectionRenderManager.setCursorManually(p, l);
2562
+ this._setEditorFocus(unitId), this._textSelectionRenderManager.setCursorManually(offsetX2, offsetY2);
2340
2563
  }, 0);
2341
2564
  }
2342
- i.button !== 2 && s.stopPropagation();
2343
- })), this.disposeWithMe(o.onDblclick$.subscribeEvent((i) => {
2344
- this._isEditorReadOnly(e) || this._textSelectionRenderManager.handleDblClick(i);
2345
- })), this.disposeWithMe(o.onTripleClick$.subscribeEvent((i) => {
2346
- this._isEditorReadOnly(e) || this._textSelectionRenderManager.handleTripleClick(i);
2565
+ evt.button !== 2 && state.stopPropagation();
2566
+ })), this.disposeWithMe(document.onDblclick$.subscribeEvent((evt) => {
2567
+ this._isEditorReadOnly(unitId) || this._textSelectionRenderManager.handleDblClick(evt);
2568
+ })), this.disposeWithMe(document.onTripleClick$.subscribeEvent((evt) => {
2569
+ this._isEditorReadOnly(unitId) || this._textSelectionRenderManager.handleTripleClick(evt);
2347
2570
  }));
2348
2571
  }
2349
- _getTransformCoordForDocumentOffset(e, n) {
2350
- const o = J(this._context), { document: r, scene: i } = o, { documentTransform: s } = r.getOffsetConfig(), a = i.getViewports()[0];
2351
- if (a == null)
2572
+ _getTransformCoordForDocumentOffset(evtOffsetX, evtOffsetY) {
2573
+ const docObject = neoGetDocObject(this._context), { document, scene } = docObject, { documentTransform } = document.getOffsetConfig(), activeViewport = scene.getViewports()[0];
2574
+ if (activeViewport == null)
2352
2575
  return;
2353
- const c = a.transformVector2SceneCoord(sn.FromArray([e, n]));
2354
- return s.clone().invert().applyPoint(c);
2576
+ const originCoord = activeViewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
2577
+ return documentTransform.clone().invert().applyPoint(originCoord);
2355
2578
  }
2356
- _isEditorReadOnly(e) {
2357
- const n = this._editorService.getEditor(e);
2358
- return n ? n.isReadOnly() : !1;
2579
+ _isEditorReadOnly(unitId) {
2580
+ const editor = this._editorService.getEditor(unitId);
2581
+ return editor ? editor.isReadOnly() : !1;
2359
2582
  }
2360
- _setEditorFocus(e) {
2361
- this._editorService.focusStyle(e);
2583
+ _setEditorFocus(unitId) {
2584
+ this._editorService.focusStyle(unitId);
2362
2585
  }
2363
2586
  _commandExecutedListener() {
2364
- const e = [De.id];
2587
+ const updateCommandList = [SetDocZoomRatioOperation.id];
2365
2588
  this.disposeWithMe(
2366
- this._commandService.onCommandExecuted((n) => {
2367
- var o;
2368
- if (e.includes(n.id)) {
2369
- const r = n.params, { unitId: i } = r, s = (o = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : o.unitId;
2370
- if (i !== s)
2589
+ this._commandService.onCommandExecuted((command) => {
2590
+ var _a19;
2591
+ if (updateCommandList.includes(command.id)) {
2592
+ const params = command.params, { unitId: documentId } = params, unitId = (_a19 = this._textSelectionManagerService.getCurrentSelection()) == null ? void 0 : _a19.unitId;
2593
+ if (documentId !== unitId)
2371
2594
  return;
2372
2595
  this._textSelectionManagerService.refreshSelection();
2373
2596
  }
@@ -2376,14 +2599,14 @@ let ct = class extends Q {
2376
2599
  }
2377
2600
  _skeletonListener() {
2378
2601
  this.disposeWithMe(
2379
- this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
2380
- if (e == null)
2602
+ this._docSkeletonManagerService.currentSkeleton$.subscribe((skeleton) => {
2603
+ if (skeleton == null)
2381
2604
  return;
2382
- const { scene: n, mainComponent: o, unitId: r } = this._context;
2383
- this._textSelectionRenderManager.changeRuntime(e, n, o), this._textSelectionManagerService.setCurrentSelectionNotRefresh({
2384
- unitId: r,
2605
+ const { scene, mainComponent, unitId } = this._context;
2606
+ this._textSelectionRenderManager.changeRuntime(skeleton, scene, mainComponent), this._textSelectionManagerService.setCurrentSelectionNotRefresh({
2607
+ unitId,
2385
2608
  subUnitId: ""
2386
- }), yn(r) || this._textSelectionManagerService.replaceTextRanges([
2609
+ }), isInternalEditorID(unitId) || this._textSelectionManagerService.replaceTextRanges([
2387
2610
  {
2388
2611
  startOffset: 0,
2389
2612
  endOffset: 0
@@ -2392,102 +2615,105 @@ let ct = class extends Q {
2392
2615
  })
2393
2616
  );
2394
2617
  }
2395
- };
2396
- ct = Ii([
2397
- ie(1, O),
2398
- ie(2, ee),
2399
- ie(3, w),
2400
- ie(4, ne),
2401
- ie(5, I(L)),
2402
- ie(6, I(te))
2403
- ], ct);
2404
- var bi = Object.defineProperty, Mi = Object.getOwnPropertyDescriptor, yi = (t, e, n, o) => {
2405
- for (var r = o > 1 ? void 0 : o ? Mi(e, n) : e, i = t.length - 1, s; i >= 0; i--)
2406
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
2407
- return o && r && bi(e, n, r), r;
2408
- }, Te = (t, e) => (n, o) => e(n, o, t);
2409
- function kt(t, e) {
2410
- const n = Gt(t.left, t.top, e), o = Gt(t.right, t.bottom, e);
2618
+ }, __name(_a11, "DocTextSelectionRenderController"), _a11);
2619
+ DocTextSelectionRenderController = __decorateClass$7([
2620
+ __decorateParam$7(1, ICommandService),
2621
+ __decorateParam$7(2, IEditorService),
2622
+ __decorateParam$7(3, IUniverInstanceService),
2623
+ __decorateParam$7(4, ITextSelectionRenderManager),
2624
+ __decorateParam$7(5, Inject(DocSkeletonManagerService)),
2625
+ __decorateParam$7(6, Inject(TextSelectionManagerService))
2626
+ ], DocTextSelectionRenderController);
2627
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2628
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2629
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2630
+ return kind && result && __defProp$6(target, key, result), result;
2631
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6");
2632
+ function transformBound2OffsetBound(originBound, scene) {
2633
+ const topLeft = transformPosition2Offset(originBound.left, originBound.top, scene), bottomRight = transformPosition2Offset(originBound.right, originBound.bottom, scene);
2411
2634
  return {
2412
- left: n.x,
2413
- top: n.y,
2414
- right: o.x,
2415
- bottom: o.y
2635
+ left: topLeft.x,
2636
+ top: topLeft.y,
2637
+ right: bottomRight.x,
2638
+ bottom: bottomRight.y
2416
2639
  };
2417
2640
  }
2418
- function Gt(t, e, n) {
2419
- const { scaleX: o, scaleY: r } = n.getAncestorScale(), i = n.getViewport(q.VIEW_MAIN);
2420
- if (!i)
2641
+ __name(transformBound2OffsetBound, "transformBound2OffsetBound");
2642
+ function transformPosition2Offset(x, y, scene) {
2643
+ const { scaleX, scaleY } = scene.getAncestorScale(), viewMain = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
2644
+ if (!viewMain)
2421
2645
  return {
2422
- x: t,
2423
- y: e
2646
+ x,
2647
+ y
2424
2648
  };
2425
- const { viewportScrollX: s, viewportScrollY: a } = i, c = (t - s) * o, d = (e - a) * r;
2649
+ const { viewportScrollX: actualScrollX, viewportScrollY: actualScrollY } = viewMain, offsetX = (x - actualScrollX) * scaleX, offsetY = (y - actualScrollY) * scaleY;
2426
2650
  return {
2427
- x: c,
2428
- y: d
2651
+ x: offsetX,
2652
+ y: offsetY
2429
2653
  };
2430
2654
  }
2431
- let lt = class extends Q {
2432
- constructor(t, e, n, o) {
2433
- super(), this._globalPopupManagerService = t, this._renderManagerService = e, this._univerInstanceService = n, this._commandService = o;
2655
+ __name(transformPosition2Offset, "transformPosition2Offset");
2656
+ var _a12;
2657
+ let DocCanvasPopManagerService = (_a12 = class extends Disposable {
2658
+ constructor(_globalPopupManagerService, _renderManagerService, _univerInstanceService, _commandService) {
2659
+ super(), this._globalPopupManagerService = _globalPopupManagerService, this._renderManagerService = _renderManagerService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService;
2434
2660
  }
2435
2661
  // #region attach to object
2436
- _createObjectPositionObserver(t, e) {
2437
- const n = () => {
2438
- const { scene: a, engine: c } = e, { left: d, top: g, width: h, height: p } = t, l = {
2439
- left: d,
2440
- right: d + h,
2441
- top: g,
2442
- bottom: g + p
2443
- }, f = kt(l, a), u = c.getCanvasElement().getBoundingClientRect().top;
2662
+ _createObjectPositionObserver(targetObject, currentRender) {
2663
+ const calc = /* @__PURE__ */ __name(() => {
2664
+ const { scene, engine } = currentRender, { left, top, width, height } = targetObject, bound = {
2665
+ left,
2666
+ right: left + width,
2667
+ top,
2668
+ bottom: top + height
2669
+ }, canvasElement = engine.getCanvasElement(), canvasClientRect = canvasElement.getBoundingClientRect(), widthOfCanvas = pxToNum(canvasElement.style.width), offsetBound = transformBound2OffsetBound(bound, scene), { top: topOffset, left: leftOffset, width: domWidth } = canvasClientRect, scaleAdjust = domWidth / widthOfCanvas;
2444
2670
  return {
2445
- left: f.left,
2446
- right: f.right,
2447
- top: f.top + u,
2448
- bottom: f.bottom + u
2671
+ left: offsetBound.left * scaleAdjust + leftOffset,
2672
+ right: offsetBound.right * scaleAdjust + leftOffset,
2673
+ top: offsetBound.top * scaleAdjust + topOffset,
2674
+ bottom: offsetBound.bottom * scaleAdjust + topOffset
2449
2675
  };
2450
- }, o = n(), r = new xt(o), i = new St();
2451
- i.add(this._commandService.onCommandExecuted((a) => {
2452
- a.id === De.id && r.next(n());
2676
+ }, "calc"), position = calc(), position$ = new BehaviorSubject(position), disposable = new DisposableCollection();
2677
+ disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
2678
+ commandInfo.id === SetDocZoomRatioOperation.id && position$.next(calc());
2453
2679
  }));
2454
- const s = e.scene.getViewport(q.VIEW_MAIN);
2455
- return s && i.add(s.onScrollAfter$.subscribeEvent(() => {
2456
- r.next(n());
2680
+ const viewMain = currentRender.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
2681
+ return viewMain && disposable.add(viewMain.onScrollAfter$.subscribeEvent(() => {
2682
+ position$.next(calc());
2457
2683
  })), {
2458
- position: o,
2459
- position$: r,
2460
- disposable: i
2684
+ position,
2685
+ position$,
2686
+ disposable
2461
2687
  };
2462
2688
  }
2463
- _createRangePositionObserver(t, e) {
2464
- var a;
2465
- const n = () => {
2466
- const { scene: c, mainComponent: d, engine: g } = e, h = e.with(L).getSkeleton(), p = h.findNodePositionByCharIndex(t.startOffset), l = h.findNodePositionByCharIndex(t.endOffset), f = d;
2467
- if (!l || !p)
2689
+ _createRangePositionObserver(range, currentRender) {
2690
+ var _a19;
2691
+ const calc = /* @__PURE__ */ __name(() => {
2692
+ const { scene, mainComponent, engine } = currentRender, skeleton = currentRender.with(DocSkeletonManagerService).getSkeleton(), startPosition = skeleton.findNodePositionByCharIndex(range.startOffset), endPosition = skeleton.findNodePositionByCharIndex(range.endOffset), document = mainComponent;
2693
+ if (!endPosition || !startPosition)
2468
2694
  return;
2469
- const u = f.getOffsetConfig(), { docsLeft: _, docsTop: m } = u, R = g.getCanvasElement().getBoundingClientRect().top, C = new rn(u, h), { borderBoxPointGroup: E } = C.getRangePointData(p, l);
2470
- return Mo(E).map((N) => kt(N, c)).map((N) => ({
2471
- left: N.left + _,
2472
- right: N.right + _,
2473
- top: N.top + m + R,
2474
- bottom: N.bottom + m + R
2695
+ const documentOffsetConfig = document.getOffsetConfig(), { docsLeft, docsTop } = documentOffsetConfig, canvasElement = engine.getCanvasElement(), canvasClientRect = canvasElement.getBoundingClientRect(), widthOfCanvas = pxToNum(canvasElement.style.width), { top, left, width } = canvasClientRect, scaleAdjust = width / widthOfCanvas, { scaleX, scaleY } = scene.getAncestorScale(), convertor = new NodePositionConvertToCursor(documentOffsetConfig, skeleton), { borderBoxPointGroup } = convertor.getRangePointData(startPosition, endPosition);
2696
+ return getLineBounding(borderBoxPointGroup).map((bound) => transformBound2OffsetBound(bound, scene)).map((i) => ({
2697
+ left: (i.left + docsLeft * scaleX) * scaleAdjust + left,
2698
+ right: (i.right + docsLeft * scaleX) * scaleAdjust + left,
2699
+ top: (i.top + docsTop * scaleY) * scaleAdjust + top,
2700
+ bottom: (i.bottom + docsTop * scaleY) * scaleAdjust + top
2475
2701
  }));
2476
- }, o = (a = n()) != null ? a : [], r = new xt(o), i = new St();
2477
- i.add(this._commandService.onCommandExecuted((c) => {
2478
- if (c.id === De.id) {
2479
- const d = n();
2480
- d && r.next(d);
2702
+ }, "calc"), positions = (_a19 = calc()) != null ? _a19 : [], positions$ = new BehaviorSubject(positions), disposable = new DisposableCollection();
2703
+ disposable.add(this._commandService.onCommandExecuted((commandInfo) => {
2704
+ if (commandInfo.id === SetDocZoomRatioOperation.id) {
2705
+ const position = calc();
2706
+ position && positions$.next(position);
2481
2707
  }
2482
2708
  }));
2483
- const s = e.scene.getViewport(q.VIEW_MAIN);
2484
- return s && i.add(s.onScrollAfter$.subscribeEvent(() => {
2485
- const c = n();
2486
- c && r.next(c);
2709
+ const viewMain = currentRender.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
2710
+ return viewMain && disposable.add(viewMain.onScrollAfter$.subscribeEvent(() => {
2711
+ const position = calc();
2712
+ position && positions$.next(position);
2487
2713
  })), {
2488
- positions: o,
2489
- positions$: r,
2490
- disposable: i
2714
+ positions,
2715
+ positions$,
2716
+ disposable
2491
2717
  };
2492
2718
  }
2493
2719
  /**
@@ -2496,211 +2722,390 @@ let lt = class extends Q {
2496
2722
  * @param popup popup item
2497
2723
  * @returns disposable
2498
2724
  */
2499
- attachPopupToObject(t, e) {
2500
- const o = this._univerInstanceService.getCurrentUnitForType(v.UNIVER_DOC).getUnitId(), r = this._renderManagerService.getRenderById(o);
2501
- if (!r)
2725
+ attachPopupToObject(targetObject, popup) {
2726
+ const unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC).getUnitId(), currentRender = this._renderManagerService.getRenderById(unitId);
2727
+ if (!currentRender)
2502
2728
  return {
2503
- dispose: () => {
2504
- }
2729
+ dispose: /* @__PURE__ */ __name(() => {
2730
+ }, "dispose")
2505
2731
  };
2506
- const { position: i, position$: s, disposable: a } = this._createObjectPositionObserver(t, r), c = this._globalPopupManagerService.addPopup({
2507
- ...e,
2508
- unitId: o,
2732
+ const { position, position$, disposable } = this._createObjectPositionObserver(targetObject, currentRender), id = this._globalPopupManagerService.addPopup({
2733
+ ...popup,
2734
+ unitId,
2509
2735
  subUnitId: "default",
2510
- anchorRect: i,
2511
- anchorRect$: s
2736
+ anchorRect: position,
2737
+ anchorRect$: position$
2512
2738
  });
2513
2739
  return {
2514
- dispose: () => {
2515
- this._globalPopupManagerService.removePopup(c), s.complete(), a.dispose();
2516
- }
2740
+ dispose: /* @__PURE__ */ __name(() => {
2741
+ this._globalPopupManagerService.removePopup(id), position$.complete(), disposable.dispose();
2742
+ }, "dispose")
2517
2743
  };
2518
2744
  }
2519
- attachPopupToRange(t, e) {
2520
- const o = this._univerInstanceService.getCurrentUnitForType(v.UNIVER_DOC).getUnitId(), { direction: r = "top" } = e, i = this._renderManagerService.getRenderById(o);
2521
- if (!i)
2745
+ attachPopupToRange(range, popup) {
2746
+ const unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC).getUnitId(), { direction = "top" } = popup, currentRender = this._renderManagerService.getRenderById(unitId);
2747
+ if (!currentRender)
2522
2748
  return {
2523
- dispose: () => {
2524
- }
2749
+ dispose: /* @__PURE__ */ __name(() => {
2750
+ }, "dispose")
2525
2751
  };
2526
- const { positions: s, positions$: a, disposable: c } = this._createRangePositionObserver(t, i), d = a.pipe(xo((h) => r === "top" ? h[0] : h[h.length - 1])), g = this._globalPopupManagerService.addPopup({
2527
- ...e,
2528
- unitId: o,
2752
+ const { positions: bounds, positions$: bounds$, disposable } = this._createRangePositionObserver(range, currentRender), position$ = bounds$.pipe(map((bounds2) => direction === "top" ? bounds2[0] : bounds2[bounds2.length - 1])), id = this._globalPopupManagerService.addPopup({
2753
+ ...popup,
2754
+ unitId,
2529
2755
  subUnitId: "default",
2530
- anchorRect: r === "top" ? s[0] : s[s.length - 1],
2531
- anchorRect$: d,
2532
- excludeRects: s,
2533
- excludeRects$: a,
2534
- direction: r === "top" ? "top" : "bottom"
2756
+ anchorRect: direction === "top" ? bounds[0] : bounds[bounds.length - 1],
2757
+ anchorRect$: position$,
2758
+ excludeRects: bounds,
2759
+ excludeRects$: bounds$,
2760
+ direction: direction === "top" ? "top" : "bottom"
2535
2761
  });
2536
2762
  return {
2537
- dispose: () => {
2538
- this._globalPopupManagerService.removePopup(g), a.complete(), c.dispose();
2539
- }
2763
+ dispose: /* @__PURE__ */ __name(() => {
2764
+ this._globalPopupManagerService.removePopup(id), bounds$.complete(), disposable.dispose();
2765
+ }, "dispose")
2540
2766
  };
2541
2767
  }
2542
- };
2543
- lt = yi([
2544
- Te(0, I(Gn)),
2545
- Te(1, W),
2546
- Te(2, w),
2547
- Te(3, O)
2548
- ], lt);
2549
- var xi = Object.defineProperty, Pi = Object.getOwnPropertyDescriptor, Di = (t, e, n, o) => {
2550
- for (var r = o > 1 ? void 0 : o ? Pi(e, n) : e, i = t.length - 1, s; i >= 0; i--)
2551
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
2552
- return o && r && xi(e, n, r), r;
2553
- }, zt = (t, e) => (n, o) => e(n, o, t);
2554
- let xe = class extends Se {
2555
- constructor(t, e) {
2556
- super(), this._instanceSrv = t, this._renderManagerService = e, this._init();
2768
+ }, __name(_a12, "DocCanvasPopManagerService"), _a12);
2769
+ DocCanvasPopManagerService = __decorateClass$6([
2770
+ __decorateParam$6(0, Inject(ICanvasPopupService)),
2771
+ __decorateParam$6(1, IRenderManagerService),
2772
+ __decorateParam$6(2, IUniverInstanceService),
2773
+ __decorateParam$6(3, ICommandService)
2774
+ ], DocCanvasPopManagerService);
2775
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2776
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2777
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2778
+ return kind && result && __defProp$5(target, key, result), result;
2779
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a13;
2780
+ let DocsRenderService = (_a13 = class extends RxDisposable {
2781
+ constructor(_instanceSrv, _renderManagerService) {
2782
+ super(), this._instanceSrv = _instanceSrv, this._renderManagerService = _renderManagerService, this._init();
2557
2783
  }
2558
2784
  _init() {
2559
- this._renderManagerService.createRender$.pipe(se(this.dispose$)).subscribe((t) => this._createRenderWithId(t)), this._instanceSrv.getTypeOfUnitAdded$(v.UNIVER_DOC).pipe(se(this.dispose$)).subscribe((t) => this._createRenderer(t)), this._instanceSrv.getAllUnitsForType(v.UNIVER_DOC).forEach((t) => this._createRenderer(t)), this._instanceSrv.getTypeOfUnitDisposed$(v.UNIVER_DOC).pipe(se(this.dispose$)).subscribe((t) => this._disposeRenderer(t));
2785
+ this._renderManagerService.createRender$.pipe(takeUntil(this.dispose$)).subscribe((unitId) => this._createRenderWithId(unitId)), this._instanceSrv.getTypeOfUnitAdded$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((doc) => this._createRenderer(doc)), this._instanceSrv.getAllUnitsForType(UniverInstanceType.UNIVER_DOC).forEach((documentModel) => this._createRenderer(documentModel)), this._instanceSrv.getTypeOfUnitDisposed$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((doc) => this._disposeRenderer(doc));
2786
+ }
2787
+ _createRenderer(doc) {
2788
+ const unitId = doc.getUnitId();
2789
+ this._renderManagerService.has(unitId) || (this._createRenderWithId(unitId), this._renderManagerService.setCurrent(unitId));
2790
+ }
2791
+ _createRenderWithId(unitId) {
2792
+ this._renderManagerService.createRender(unitId);
2793
+ }
2794
+ _disposeRenderer(doc) {
2795
+ const unitId = doc.getUnitId();
2796
+ this._renderManagerService.removeRender(unitId);
2797
+ }
2798
+ }, __name(_a13, "DocsRenderService"), _a13);
2799
+ DocsRenderService = __decorateClass$5([
2800
+ OnLifecycle(LifecycleStages.Ready, DocsRenderService),
2801
+ __decorateParam$5(0, IUniverInstanceService),
2802
+ __decorateParam$5(1, IRenderManagerService)
2803
+ ], DocsRenderService);
2804
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2805
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2806
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2807
+ return kind && result && __defProp$4(target, key, result), result;
2808
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4");
2809
+ const SKIP_UNIT_IDS$1 = [
2810
+ DEFAULT_EMPTY_DOCUMENT_VALUE,
2811
+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
2812
+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
2813
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY
2814
+ ];
2815
+ var _a14;
2816
+ let DocContextMenuRenderController = (_a14 = class extends Disposable {
2817
+ constructor(_context, _contextMenuService, _textSelectionManagerService, _commandService) {
2818
+ super(), this._context = _context, this._contextMenuService = _contextMenuService, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, SKIP_UNIT_IDS$1.includes(this._context.unitId) || (this._initPointerDown(), this._initEditChange());
2819
+ }
2820
+ _initPointerDown() {
2821
+ var _a19, _b;
2822
+ const documentsSubscription = ((_b = (_a19 = this._context) == null ? void 0 : _a19.mainComponent) == null ? void 0 : _b.onPointerDown$).subscribeEvent((event) => {
2823
+ event.button === 2 && this._contextMenuService.triggerContextMenu(event, MenuPosition.CONTEXT_MENU);
2824
+ });
2825
+ this.disposeWithMe(documentsSubscription);
2560
2826
  }
2561
- _createRenderer(t) {
2562
- const e = t.getUnitId();
2563
- this._renderManagerService.has(e) || (this._createRenderWithId(e), this._renderManagerService.setCurrent(e));
2827
+ _initEditChange() {
2828
+ this.disposeWithMe(
2829
+ this._commandService.onCommandExecuted((command) => {
2830
+ command.id === RichTextEditingMutation.id && this._contextMenuService.visible && this._contextMenuService.hideContextMenu();
2831
+ })
2832
+ );
2564
2833
  }
2565
- _createRenderWithId(t) {
2566
- this._renderManagerService.createRender(t);
2834
+ }, __name(_a14, "DocContextMenuRenderController"), _a14);
2835
+ DocContextMenuRenderController = __decorateClass$4([
2836
+ __decorateParam$4(1, IContextMenuService),
2837
+ __decorateParam$4(2, Inject(TextSelectionManagerService)),
2838
+ __decorateParam$4(3, ICommandService)
2839
+ ], DocContextMenuRenderController);
2840
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2841
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2842
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2843
+ return kind && result && __defProp$3(target, key, result), result;
2844
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3");
2845
+ const SKIP_UNIT_IDS = [
2846
+ DEFAULT_EMPTY_DOCUMENT_VALUE,
2847
+ DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
2848
+ DOCS_NORMAL_EDITOR_UNIT_ID_KEY
2849
+ ];
2850
+ var _a15;
2851
+ let DocResizeRenderController = (_a15 = class extends Disposable {
2852
+ constructor(_context, _docPageLayoutService, _textSelectionManagerService) {
2853
+ super(), this._context = _context, this._docPageLayoutService = _docPageLayoutService, this._textSelectionManagerService = _textSelectionManagerService, SKIP_UNIT_IDS.includes(this._context.unitId) || this._initResize();
2854
+ }
2855
+ _initResize() {
2856
+ this.disposeWithMe(
2857
+ fromEventSubject(this._context.engine.onTransformChange$).pipe(
2858
+ filter((evt) => evt.type === TRANSFORM_CHANGE_OBSERVABLE_TYPE.resize),
2859
+ throttleTime(16)
2860
+ ).subscribe(() => {
2861
+ this._docPageLayoutService.calculatePagePosition(), this._textSelectionManagerService.refreshSelection();
2862
+ })
2863
+ );
2567
2864
  }
2568
- _disposeRenderer(t) {
2569
- const e = t.getUnitId();
2570
- this._renderManagerService.removeRender(e);
2865
+ }, __name(_a15, "DocResizeRenderController"), _a15);
2866
+ DocResizeRenderController = __decorateClass$3([
2867
+ __decorateParam$3(1, Inject(DocPageLayoutService)),
2868
+ __decorateParam$3(2, Inject(TextSelectionManagerService))
2869
+ ], DocResizeRenderController);
2870
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2871
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2872
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2873
+ return kind && result && __defProp$2(target, key, result), result;
2874
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a16;
2875
+ let DocHoverManagerService = (_a16 = class extends Disposable {
2876
+ constructor(_univerInstanceService, _renderManagerService) {
2877
+ super();
2878
+ __publicField(this, "_activeCustomRanges$", new BehaviorSubject([]));
2879
+ __publicField(this, "activeCustomRanges$", this._activeCustomRanges$.asObservable());
2880
+ __publicField(this, "_activeIndex$", new BehaviorSubject(null));
2881
+ __publicField(this, "activeIndex$", this._activeIndex$.asObservable());
2882
+ __publicField(this, "_scrolling", !1);
2883
+ this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this.disposeWithMe(() => {
2884
+ this._activeCustomRanges$.complete(), this._activeIndex$.complete();
2885
+ });
2571
2886
  }
2572
- };
2573
- xe = Di([
2574
- we(Be.Ready, xe),
2575
- zt(0, w),
2576
- zt(1, W)
2577
- ], xe);
2578
- var Ai = Object.defineProperty, Ni = Object.getOwnPropertyDescriptor, Fi = (t, e, n, o) => {
2579
- for (var r = o > 1 ? void 0 : o ? Ni(e, n) : e, i = t.length - 1, s; i >= 0; i--)
2580
- (s = t[i]) && (r = (o ? s(e, n, r) : s(r)) || r);
2581
- return o && r && Ai(e, n, r), r;
2582
- }, qe = (t, e) => (n, o) => e(n, o, t), Ie;
2583
- let Yt = (Ie = class extends xn {
2584
- constructor(t, e, n, o) {
2585
- super(), this._config = t, this._injector = e, this._renderManagerSrv = n, this._logService = o, this._config = j.deepMerge({}, nr, this._config), this._initDependencies(e), this._initializeCommands();
2887
+ _getTransformCoordForDocumentOffset(document, viewport, evtOffsetX, evtOffsetY) {
2888
+ const { documentTransform } = document.getOffsetConfig(), originCoord = viewport.transformVector2SceneCoord(Vector2.FromArray([evtOffsetX, evtOffsetY]));
2889
+ if (originCoord)
2890
+ return documentTransform.clone().invert().applyPoint(originCoord);
2891
+ }
2892
+ _calcActiveCustomRanges(offsetX, offsetY) {
2893
+ var _a19, _b;
2894
+ const document = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
2895
+ if (!document) {
2896
+ this._activeCustomRanges$.next([]);
2897
+ return;
2898
+ }
2899
+ const currentRender = this._renderManagerService.getRenderById(document.getUnitId());
2900
+ if (!currentRender)
2901
+ return null;
2902
+ const documentComponent = currentRender.mainComponent, skeleton = currentRender.with(DocSkeletonManagerService).getSkeleton(), { pageLayoutType = PageLayoutType.VERTICAL, pageMarginLeft, pageMarginTop, docsLeft, docsTop } = documentComponent.getOffsetConfig(), coord = this._getTransformCoordForDocumentOffset(
2903
+ documentComponent,
2904
+ currentRender.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN),
2905
+ offsetX,
2906
+ offsetY
2907
+ );
2908
+ if (!coord)
2909
+ return;
2910
+ const node = skeleton.findNodeByCoord(
2911
+ coord,
2912
+ pageLayoutType,
2913
+ pageMarginLeft,
2914
+ pageMarginTop
2915
+ );
2916
+ if (node && node.node) {
2917
+ const left = node.node.left + pageMarginLeft, right = node.node.left + node.node.width + pageMarginLeft;
2918
+ if (coord.x < left || coord.x > right) {
2919
+ this._activeIndex$.next(null), this._activeCustomRanges$.next([]);
2920
+ return;
2921
+ }
2922
+ const index = node.node.parent.st + node.node.parent.glyphGroup.indexOf(node.node);
2923
+ index !== this._activeIndex$.value && this._activeIndex$.next(index);
2924
+ const ranges = (_b = (_a19 = document.getCustomRanges()) == null ? void 0 : _a19.filter((range) => range.startIndex <= index && range.endIndex >= index)) != null ? _b : [], currentRanges = this._activeCustomRanges$.value;
2925
+ if (currentRanges.length === ranges.length && currentRanges.every((range, i) => range.rangeId === ranges[i].rangeId))
2926
+ return;
2927
+ this._activeCustomRanges$.next(ranges);
2928
+ }
2929
+ }
2930
+ onMouseMove(evt) {
2931
+ if (this._scrolling)
2932
+ return;
2933
+ const { offsetX, offsetY } = evt;
2934
+ this._calcActiveCustomRanges(offsetX, offsetY);
2935
+ }
2936
+ startScroll() {
2937
+ this._scrolling || (this._scrolling = !0);
2938
+ }
2939
+ endScroll() {
2940
+ this._scrolling = !1;
2941
+ }
2942
+ }, __name(_a16, "DocHoverManagerService"), _a16);
2943
+ DocHoverManagerService = __decorateClass$2([
2944
+ __decorateParam$2(0, IUniverInstanceService),
2945
+ __decorateParam$2(1, IRenderManagerService)
2946
+ ], DocHoverManagerService);
2947
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2948
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2949
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2950
+ return kind && result && __defProp$1(target, key, result), result;
2951
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a17;
2952
+ let DocHoverRenderController = (_a17 = class extends Disposable {
2953
+ constructor(_context, _docHoverManagerService) {
2954
+ super(), this._context = _context, this._docHoverManagerService = _docHoverManagerService, this._initPointerDown(), this._initScroll();
2955
+ }
2956
+ _initPointerDown() {
2957
+ this.disposeWithMe(
2958
+ fromEventSubject(this._context.scene.onPointerMove$).pipe(debounceTime(200)).subscribe((evt) => {
2959
+ this._docHoverManagerService.onMouseMove(evt);
2960
+ })
2961
+ );
2962
+ }
2963
+ _initScroll() {
2964
+ const viewMain = this._context.scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
2965
+ viewMain && (this.disposeWithMe(fromEventSubject(viewMain.onScrollAfter$).pipe(debounceTime(60)).subscribe(() => {
2966
+ this._docHoverManagerService.endScroll();
2967
+ })), this.disposeWithMe(viewMain.onScrollBefore$.subscribeEvent(() => {
2968
+ this._docHoverManagerService.startScroll();
2969
+ })));
2970
+ }
2971
+ }, __name(_a17, "DocHoverRenderController"), _a17);
2972
+ DocHoverRenderController = __decorateClass$1([
2973
+ __decorateParam$1(1, Inject(DocHoverManagerService))
2974
+ ], DocHoverRenderController);
2975
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2976
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2977
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2978
+ return kind && result && __defProp2(target, key, result), result;
2979
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a18;
2980
+ let UniverDocsUIPlugin = (_a18 = class extends Plugin {
2981
+ constructor(_config, _injector, _renderManagerSrv, _logService) {
2982
+ super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._logService = _logService, this._config = Tools.deepMerge({}, DefaultDocUiConfig, this._config), this._initDependencies(_injector), this._initializeCommands();
2586
2983
  }
2587
2984
  onReady() {
2588
- this._initRenderBasics();
2985
+ this._initRenderBasics(), this._markDocAsFocused();
2589
2986
  }
2590
2987
  onRendered() {
2591
- this._initUI(), this._initRenderModules(), this._markDocAsFocused();
2988
+ this._initUI(), this._initRenderModules();
2592
2989
  }
2593
2990
  _initializeCommands() {
2594
2991
  [
2595
- rr,
2596
- ir,
2597
- ar,
2598
- sr,
2599
- cr,
2600
- lr,
2601
- dr,
2602
- ur,
2603
- hr,
2604
- si,
2605
- ai,
2606
- ii
2607
- ].forEach((t) => {
2608
- this._injector.get(zn).registerShortcut(t);
2992
+ MoveCursorUpShortcut,
2993
+ MoveCursorDownShortcut,
2994
+ MoveCursorRightShortcut,
2995
+ MoveCursorLeftShortcut,
2996
+ MoveSelectionUpShortcut,
2997
+ MoveSelectionDownShortcut,
2998
+ MoveSelectionLeftShortcut,
2999
+ MoveSelectionRightShortcut,
3000
+ SelectAllShortcut,
3001
+ DeleteLeftShortcut,
3002
+ DeleteRightShortcut,
3003
+ BreakLineShortcut
3004
+ ].forEach((shortcut) => {
3005
+ this._injector.get(IShortcutService).registerShortcut(shortcut);
2609
3006
  });
2610
3007
  }
2611
- _initDependencies(t) {
3008
+ _initDependencies(injector) {
2612
3009
  [
2613
- [me, { useFactory: () => this._injector.createInstance(me, this._config) }],
2614
- [Me],
2615
- [ye],
2616
- [xe],
2617
- [_e, { useFactory: () => this._injector.createInstance(_e, this._config) }],
2618
- [Re, { useClass: nt }],
2619
- [lt]
2620
- ].forEach((n) => t.add(n));
3010
+ [DocUIController, { useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(DocUIController, this._config), "useFactory") }],
3011
+ [DocClipboardController],
3012
+ [DocEditorBridgeController],
3013
+ [DocsRenderService],
3014
+ [AppUIController, { useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(AppUIController, this._config), "useFactory") }],
3015
+ [IDocClipboardService, { useClass: DocClipboardService }],
3016
+ [DocCanvasPopManagerService],
3017
+ [DocHoverManagerService]
3018
+ ].forEach((d) => injector.add(d));
2621
3019
  }
2622
3020
  _markDocAsFocused() {
2623
- const t = this._injector.get(w), e = this._injector.get(ee);
3021
+ const currentService = this._injector.get(IUniverInstanceService), editorService = this._injector.get(IEditorService);
2624
3022
  try {
2625
- const n = t.getCurrentUnitForType(v.UNIVER_DOC);
2626
- if (!n) return;
2627
- const o = n.getUnitId();
2628
- e.isEditor(o) || t.focusUnit(n.getUnitId());
2629
- } catch (n) {
2630
- this._logService.warn(n);
3023
+ const doc = currentService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
3024
+ if (!doc) return;
3025
+ const id = doc.getUnitId();
3026
+ editorService.isEditor(id) || currentService.focusUnit(doc.getUnitId());
3027
+ } catch (err) {
3028
+ this._logService.warn(err);
2631
3029
  }
2632
3030
  }
2633
3031
  _initUI() {
2634
- this._injector.get(_e);
3032
+ this._injector.get(AppUIController);
2635
3033
  }
2636
3034
  _initRenderBasics() {
2637
3035
  [
2638
- [L],
2639
- [Ro],
2640
- [st],
2641
- [at]
2642
- ].forEach((t) => {
2643
- this._renderManagerSrv.registerRenderModule(v.UNIVER_DOC, t);
3036
+ [DocSkeletonManagerService],
3037
+ [DocInterceptorService],
3038
+ [DocPageLayoutService],
3039
+ [DocRenderController],
3040
+ [DocZoomRenderController]
3041
+ ].forEach((m2) => {
3042
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, m2);
2644
3043
  });
2645
3044
  }
2646
3045
  _initRenderModules() {
2647
3046
  [
2648
- [ot],
2649
- [ct],
2650
- [it]
2651
- ].forEach((t) => {
2652
- this._renderManagerSrv.registerRenderModule(v.UNIVER_DOC, t);
3047
+ [DocBackScrollRenderController],
3048
+ [DocTextSelectionRenderController],
3049
+ [DocHeaderFooterController],
3050
+ [DocResizeRenderController],
3051
+ [DocHoverRenderController],
3052
+ [DocContextMenuRenderController]
3053
+ ].forEach((m2) => {
3054
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, m2);
2653
3055
  });
2654
3056
  }
2655
- }, T(Ie, "pluginName", or), T(Ie, "type", v.UNIVER_DOC), Ie);
2656
- Yt = Fi([
2657
- qe(1, I($e)),
2658
- qe(2, W),
2659
- qe(3, Zt)
2660
- ], Yt);
2661
- function zi(t) {
3057
+ }, __name(_a18, "UniverDocsUIPlugin"), __publicField(_a18, "pluginName", DOC_UI_PLUGIN_NAME), __publicField(_a18, "type", UniverInstanceType.UNIVER_DOC), _a18);
3058
+ UniverDocsUIPlugin = __decorateClass([
3059
+ __decorateParam(1, Inject(Injector)),
3060
+ __decorateParam(2, IRenderManagerService),
3061
+ __decorateParam(3, ILogService)
3062
+ ], UniverDocsUIPlugin);
3063
+ function docDrawingPositionToTransform(position) {
2662
3064
  return {
2663
- left: t.positionH.posOffset,
2664
- top: t.positionV.posOffset,
2665
- width: t.size.width,
2666
- height: t.size.height
3065
+ left: position.positionH.posOffset,
3066
+ top: position.positionV.posOffset,
3067
+ width: position.size.width,
3068
+ height: position.size.height
2667
3069
  };
2668
3070
  }
2669
- function Yi(t, e = 0, n = 0) {
3071
+ __name(docDrawingPositionToTransform, "docDrawingPositionToTransform");
3072
+ function transformToDocDrawingPosition(transform, marginLeft = 0, marginTop = 0) {
2670
3073
  return {
2671
3074
  size: {
2672
- width: t.width,
2673
- height: t.height
3075
+ width: transform.width,
3076
+ height: transform.height
2674
3077
  },
2675
3078
  positionH: {
2676
- relativeFrom: Pn.MARGIN,
2677
- posOffset: (t.left || 0) - e
3079
+ relativeFrom: ObjectRelativeFromH.MARGIN,
3080
+ posOffset: (transform.left || 0) - marginLeft
2678
3081
  },
2679
3082
  positionV: {
2680
- relativeFrom: Dn.PAGE,
2681
- posOffset: (t.top || 0) - n
3083
+ relativeFrom: ObjectRelativeFromV.PAGE,
3084
+ posOffset: (transform.top || 0) - marginTop
2682
3085
  },
2683
- angle: t.angle || 0
3086
+ angle: transform.angle || 0
2684
3087
  };
2685
3088
  }
3089
+ __name(transformToDocDrawingPosition, "transformToDocDrawingPosition");
2686
3090
  export {
2687
- or as DOC_UI_PLUGIN_NAME,
2688
- tr as DefaultDocContainerConfig,
2689
- nr as DefaultDocUiConfig,
2690
- er as DefaultToolbarConfig,
2691
- ot as DocBackScrollRenderController,
2692
- lt as DocCanvasPopManagerService,
2693
- ci as DocCopyCommand,
2694
- li as DocCutCommand,
2695
- di as DocPasteCommand,
2696
- st as DocRenderController,
2697
- xe as DocsRenderService,
2698
- Re as IDocClipboardService,
2699
- jo as PastePluginLark,
2700
- zo as PastePluginUniver,
2701
- ko as PastePluginWord,
2702
- Yt as UniverDocsUIPlugin,
2703
- zi as docDrawingPositionToTransform,
2704
- Yi as transformToDocDrawingPosition,
2705
- k as whenDocAndEditorFocused
3091
+ DOC_UI_PLUGIN_NAME,
3092
+ DefaultDocContainerConfig,
3093
+ DefaultDocUiConfig,
3094
+ DefaultToolbarConfig,
3095
+ DocBackScrollRenderController,
3096
+ DocCanvasPopManagerService,
3097
+ DocCopyCommand,
3098
+ DocCutCommand,
3099
+ DocHoverManagerService,
3100
+ DocPasteCommand,
3101
+ DocRenderController,
3102
+ DocsRenderService,
3103
+ IDocClipboardService,
3104
+ PastePluginLark,
3105
+ PastePluginUniver,
3106
+ PastePluginWord,
3107
+ UniverDocsUIPlugin,
3108
+ docDrawingPositionToTransform,
3109
+ transformToDocDrawingPosition,
3110
+ whenDocAndEditorFocused
2706
3111
  };