@univerjs/sheets-zen-editor 0.6.7 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/facade.js +134 -0
- package/lib/index.js +420 -0
- package/lib/locale/en-US.js +14 -0
- package/lib/locale/fa-IR.js +14 -0
- package/lib/locale/fr-FR.js +14 -0
- package/lib/locale/ru-RU.js +14 -0
- package/lib/locale/vi-VN.js +14 -0
- package/lib/locale/zh-CN.js +14 -0
- package/lib/locale/zh-TW.js +14 -0
- package/package.json +12 -12
package/lib/facade.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { ICommandService as u, CanceledError as k, IUniverInstanceService as p, RichTextValue as w, DOCS_ZEN_EDITOR_UNIT_ID_KEY as S } from "@univerjs/core";
|
|
2
|
+
import { FUniver as f } from "@univerjs/core/facade";
|
|
3
|
+
import { RichTextEditingMutation as T } from "@univerjs/docs";
|
|
4
|
+
import { IEditorBridgeService as v } from "@univerjs/sheets-ui";
|
|
5
|
+
import { OpenZenEditorCommand as l, CancelZenEditCommand as C, ConfirmZenEditCommand as m } from "@univerjs/sheets-zen-editor";
|
|
6
|
+
import { FWorkbook as x } from "@univerjs/sheets/facade";
|
|
7
|
+
class b extends f {
|
|
8
|
+
// eslint-disable-next-line max-lines-per-function
|
|
9
|
+
_initSheetZenEditorEvent(i) {
|
|
10
|
+
const h = i.get(u);
|
|
11
|
+
this.registerEventHandler(
|
|
12
|
+
this.Event.BeforeSheetEditStart,
|
|
13
|
+
() => h.beforeCommandExecuted((e) => {
|
|
14
|
+
if (e.id === l.id) {
|
|
15
|
+
const t = this.getCommandSheetTarget(e);
|
|
16
|
+
if (!t)
|
|
17
|
+
return;
|
|
18
|
+
const { workbook: s, worksheet: d } = t, o = i.get(v), c = e.params, { keycode: a, eventType: E } = c, r = o.getEditLocation(), n = {
|
|
19
|
+
row: r.row,
|
|
20
|
+
column: r.column,
|
|
21
|
+
eventType: E,
|
|
22
|
+
keycode: a,
|
|
23
|
+
workbook: s,
|
|
24
|
+
worksheet: d,
|
|
25
|
+
isZenEditor: !0
|
|
26
|
+
};
|
|
27
|
+
if (this.fireEvent(this.Event.BeforeSheetEditStart, n), n.cancel)
|
|
28
|
+
throw new k();
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
), this.registerEventHandler(
|
|
32
|
+
this.Event.BeforeSheetEditEnd,
|
|
33
|
+
() => h.beforeCommandExecuted((e) => {
|
|
34
|
+
if (e.id === C.id || e.id === m.id) {
|
|
35
|
+
const t = this.getCommandSheetTarget(e);
|
|
36
|
+
if (!t)
|
|
37
|
+
return;
|
|
38
|
+
const { workbook: s, worksheet: d } = t, o = i.get(v), c = i.get(p), a = e.params, { keycode: E, eventType: r } = a, n = o.getEditLocation(), g = {
|
|
39
|
+
row: n.row,
|
|
40
|
+
column: n.column,
|
|
41
|
+
eventType: r,
|
|
42
|
+
keycode: E,
|
|
43
|
+
workbook: s,
|
|
44
|
+
worksheet: d,
|
|
45
|
+
isZenEditor: !0,
|
|
46
|
+
value: w.create(c.getUnit(S).getSnapshot()),
|
|
47
|
+
isConfirm: e.id === m.id
|
|
48
|
+
};
|
|
49
|
+
if (this.fireEvent(this.Event.BeforeSheetEditEnd, g), g.cancel)
|
|
50
|
+
throw new k();
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
), this.registerEventHandler(
|
|
54
|
+
this.Event.SheetEditStarted,
|
|
55
|
+
() => h.onCommandExecuted((e) => {
|
|
56
|
+
if (e.id === l.id) {
|
|
57
|
+
const t = this.getCommandSheetTarget(e);
|
|
58
|
+
if (!t)
|
|
59
|
+
return;
|
|
60
|
+
const { workbook: s, worksheet: d } = t, o = i.get(v), c = e.params, { keycode: a, eventType: E } = c, r = o.getEditLocation(), n = {
|
|
61
|
+
row: r.row,
|
|
62
|
+
column: r.column,
|
|
63
|
+
eventType: E,
|
|
64
|
+
keycode: a,
|
|
65
|
+
workbook: s,
|
|
66
|
+
worksheet: d,
|
|
67
|
+
isZenEditor: !0
|
|
68
|
+
};
|
|
69
|
+
this.fireEvent(this.Event.SheetEditStarted, n);
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
), this.registerEventHandler(
|
|
73
|
+
this.Event.SheetEditEnded,
|
|
74
|
+
() => h.onCommandExecuted((e) => {
|
|
75
|
+
if (e.id === C.id || e.id === m.id) {
|
|
76
|
+
const t = this.getCommandSheetTarget(e);
|
|
77
|
+
if (!t)
|
|
78
|
+
return;
|
|
79
|
+
const { workbook: s, worksheet: d } = t, o = i.get(v), c = e.params, { keycode: a, eventType: E } = c, r = o.getEditLocation(), n = {
|
|
80
|
+
row: r.row,
|
|
81
|
+
column: r.column,
|
|
82
|
+
eventType: E,
|
|
83
|
+
keycode: a,
|
|
84
|
+
workbook: s,
|
|
85
|
+
worksheet: d,
|
|
86
|
+
isZenEditor: !0,
|
|
87
|
+
isConfirm: e.id === m.id
|
|
88
|
+
};
|
|
89
|
+
this.fireEvent(this.Event.SheetEditEnded, n);
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
), this.registerEventHandler(
|
|
93
|
+
this.Event.SheetEditChanging,
|
|
94
|
+
() => h.onCommandExecuted((e) => {
|
|
95
|
+
if (e.id === T.id) {
|
|
96
|
+
const t = this.getActiveSheet();
|
|
97
|
+
if (!t)
|
|
98
|
+
return;
|
|
99
|
+
const { workbook: s, worksheet: d } = t, o = i.get(v), c = i.get(p), a = e.params;
|
|
100
|
+
if (!o.isVisible().visible) return;
|
|
101
|
+
const { unitId: E } = a;
|
|
102
|
+
if (E === S) {
|
|
103
|
+
const { row: r, column: n } = o.getEditLocation(), g = {
|
|
104
|
+
workbook: s,
|
|
105
|
+
worksheet: d,
|
|
106
|
+
row: r,
|
|
107
|
+
column: n,
|
|
108
|
+
value: w.create(c.getUnit(S).getSnapshot()),
|
|
109
|
+
isZenEditor: !0
|
|
110
|
+
};
|
|
111
|
+
this.fireEvent(this.Event.SheetEditChanging, g);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @ignore
|
|
119
|
+
*/
|
|
120
|
+
_initialize(i) {
|
|
121
|
+
this._initSheetZenEditorEvent(i);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
f.extend(b);
|
|
125
|
+
class y extends x {
|
|
126
|
+
startZenEditingAsync() {
|
|
127
|
+
return this._injector.get(u).executeCommand(l.id);
|
|
128
|
+
}
|
|
129
|
+
endZenEditingAsync(i = !0) {
|
|
130
|
+
const h = this._injector.get(u);
|
|
131
|
+
return i ? h.executeCommand(m.id) : h.executeCommand(C.id);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
x.extend(y);
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
var ce = Object.defineProperty;
|
|
2
|
+
var ae = (e, t, i) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
+
var E = (e, t, i) => ae(e, typeof t != "symbol" ? t + "" : t, i);
|
|
4
|
+
import { CommandType as R, IUniverInstanceService as P, delayAnimationFrame as w, DOCS_ZEN_EDITOR_UNIT_ID_KEY as g, Tools as X, UniverInstanceType as x, DocumentFlavor as q, DocumentDataModel as de, createIdentifier as le, ICommandService as J, DEFAULT_EMPTY_DOCUMENT_VALUE as ue, FOCUSING_DOC as ge, FOCUSING_UNIVER_EDITOR as fe, EDITOR_ACTIVATED as he, FOCUSING_EDITOR_STANDALONE as me, Disposable as ve, RxDisposable as pe, Plugin as Se, merge as Ee, Inject as _e, Injector as Ie, IConfigService as Ce } from "@univerjs/core";
|
|
5
|
+
import { IEditorService as k, VIEWPORT_KEY as Oe, DocBackScrollRenderController as ye } from "@univerjs/docs-ui";
|
|
6
|
+
import { IRenderManagerService as Q } from "@univerjs/engine-render";
|
|
7
|
+
import { IEditorBridgeService as b, EditingRenderController as Ne, getCurrentExclusiveRangeInterest$ as Te, getCurrentRangeDisable$ as be, getEditorObject as ze } from "@univerjs/sheets-ui";
|
|
8
|
+
import { IZenZoneService as z, ISidebarService as U, useDependency as D, MenuItemType as Me, ContextMenuPosition as De, ContextMenuGroup as Re, KeyCode as ee, MetaKeys as Pe, IMenuManagerService as we, IShortcutService as xe } from "@univerjs/ui";
|
|
9
|
+
import { jsxs as F, jsx as _ } from "react/jsx-runtime";
|
|
10
|
+
import { clsx as W } from "@univerjs/design";
|
|
11
|
+
import { forwardRef as Z, useRef as te, createElement as j, useEffect as ke } from "react";
|
|
12
|
+
import { BehaviorSubject as Ue, switchMap as Ze, map as je, takeUntil as Be } from "rxjs";
|
|
13
|
+
import { RangeProtectionPermissionEditPoint as Le, WorksheetEditPermission as Ae, WorksheetSetCellValuePermission as $e, WorksheetSetCellStylePermission as Ve, WorkbookEditablePermission as Fe } from "@univerjs/sheets";
|
|
14
|
+
const B = {
|
|
15
|
+
id: "zen-editor.command.open-zen-editor",
|
|
16
|
+
type: R.COMMAND,
|
|
17
|
+
handler: async (e) => {
|
|
18
|
+
var C;
|
|
19
|
+
const t = e.get(z), i = e.get(k), n = e.get(b), r = e.get(P), s = e.get(U);
|
|
20
|
+
s.visible && (s.close(), await w()), t.open();
|
|
21
|
+
const o = i.getEditor(g);
|
|
22
|
+
if (o == null)
|
|
23
|
+
return !1;
|
|
24
|
+
const c = n.getLatestEditCellState();
|
|
25
|
+
if (c == null)
|
|
26
|
+
return !1;
|
|
27
|
+
const a = (C = c.documentLayoutObject.documentModel) == null ? void 0 : C.getSnapshot();
|
|
28
|
+
if (a == null)
|
|
29
|
+
return !1;
|
|
30
|
+
r.focusUnit(g);
|
|
31
|
+
const { body: u, drawings: v, drawingsOrder: l, tableSource: f, settings: p } = X.deepClone(a), S = {
|
|
32
|
+
...o.getDocumentData(),
|
|
33
|
+
body: u,
|
|
34
|
+
drawings: v,
|
|
35
|
+
drawingsOrder: l,
|
|
36
|
+
tableSource: f,
|
|
37
|
+
settings: p
|
|
38
|
+
}, h = [
|
|
39
|
+
{
|
|
40
|
+
startOffset: 0,
|
|
41
|
+
endOffset: 0,
|
|
42
|
+
collapsed: !0
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
return o.focus(), o.setDocumentData(S, h), o.clearUndoRedoHistory(), !0;
|
|
46
|
+
}
|
|
47
|
+
}, L = {
|
|
48
|
+
id: "zen-editor.command.cancel-zen-edit",
|
|
49
|
+
type: R.COMMAND,
|
|
50
|
+
handler: async (e) => {
|
|
51
|
+
const t = e.get(z), i = e.get(b), n = e.get(P), r = e.get(U);
|
|
52
|
+
r.visible && (r.close(), await w()), t.close();
|
|
53
|
+
const s = n.getCurrentUnitForType(x.UNIVER_SHEET);
|
|
54
|
+
return s ? (n.focusUnit(s.getUnitId()), i.refreshEditCellState(), !0) : !1;
|
|
55
|
+
}
|
|
56
|
+
}, A = {
|
|
57
|
+
id: "zen-editor.command.confirm-zen-edit",
|
|
58
|
+
type: R.COMMAND,
|
|
59
|
+
handler: async (e) => {
|
|
60
|
+
var u;
|
|
61
|
+
const t = e.get(z), i = e.get(b), n = e.get(P), r = e.get(k), s = e.get(U);
|
|
62
|
+
s.visible && (s.close(), await w()), t.close();
|
|
63
|
+
const o = r.getEditor(g);
|
|
64
|
+
if (o == null)
|
|
65
|
+
return !1;
|
|
66
|
+
const c = e.get(Q), a = n.getCurrentUnitForType(x.UNIVER_SHEET);
|
|
67
|
+
if (a) {
|
|
68
|
+
const v = a.getUnitId(), l = (u = c.getRenderById(v)) == null ? void 0 : u.with(Ne);
|
|
69
|
+
if (l) {
|
|
70
|
+
const f = X.deepClone(o.getDocumentData());
|
|
71
|
+
f.documentStyle.documentFlavor = q.UNSPECIFIED, l.submitCellData(new de(f));
|
|
72
|
+
}
|
|
73
|
+
return n.focusUnit(a.getUnitId()), i.refreshEditCellState(), !0;
|
|
74
|
+
}
|
|
75
|
+
return !1;
|
|
76
|
+
}
|
|
77
|
+
}, We = "sheets-zen-editor.config", H = {};
|
|
78
|
+
var d = function() {
|
|
79
|
+
return d = Object.assign || function(e) {
|
|
80
|
+
for (var t, i = 1, n = arguments.length; i < n; i++) {
|
|
81
|
+
t = arguments[i];
|
|
82
|
+
for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
|
|
83
|
+
}
|
|
84
|
+
return e;
|
|
85
|
+
}, d.apply(this, arguments);
|
|
86
|
+
}, He = function(e, t) {
|
|
87
|
+
var i = {};
|
|
88
|
+
for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (i[n] = e[n]);
|
|
89
|
+
if (e != null && typeof Object.getOwnPropertySymbols == "function")
|
|
90
|
+
for (var r = 0, n = Object.getOwnPropertySymbols(e); r < n.length; r++)
|
|
91
|
+
t.indexOf(n[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[r]) && (i[n[r]] = e[n[r]]);
|
|
92
|
+
return i;
|
|
93
|
+
}, $ = Z(function(e, t) {
|
|
94
|
+
var i = e.icon, n = e.id, r = e.className, s = e.extend, o = He(e, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(n, " ").concat(r || "").trim(), a = te("_".concat(Ke()));
|
|
95
|
+
return ne(i, "".concat(n), { defIds: i.defIds, idSuffix: a.current }, d({ ref: t, className: c }, o), s);
|
|
96
|
+
});
|
|
97
|
+
function ne(e, t, i, n, r) {
|
|
98
|
+
return j(e.tag, d(d({ key: t }, Ye(e, i, r)), n), (Ge(e, i).children || []).map(function(s, o) {
|
|
99
|
+
return ne(s, "".concat(t, "-").concat(e.tag, "-").concat(o), i, void 0, r);
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
function Ye(e, t, i) {
|
|
103
|
+
var n = d({}, e.attrs);
|
|
104
|
+
i != null && i.colorChannel1 && n.fill === "colorChannel1" && (n.fill = i.colorChannel1), e.tag === "mask" && n.id && (n.id = n.id + t.idSuffix), Object.entries(n).forEach(function(s) {
|
|
105
|
+
var o = s[0], c = s[1];
|
|
106
|
+
o === "mask" && typeof c == "string" && (n[o] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
|
|
107
|
+
});
|
|
108
|
+
var r = t.defIds;
|
|
109
|
+
return !r || r.length === 0 || (e.tag === "use" && n["xlink:href"] && (n["xlink:href"] = n["xlink:href"] + t.idSuffix), Object.entries(n).forEach(function(s) {
|
|
110
|
+
var o = s[0], c = s[1];
|
|
111
|
+
typeof c == "string" && (n[o] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
|
|
112
|
+
})), n;
|
|
113
|
+
}
|
|
114
|
+
function Ge(e, t) {
|
|
115
|
+
var i, n = t.defIds;
|
|
116
|
+
return !n || n.length === 0 ? e : e.tag === "defs" && (!((i = e.children) === null || i === void 0) && i.length) ? d(d({}, e), { children: e.children.map(function(r) {
|
|
117
|
+
return typeof r.attrs.id == "string" && n && n.indexOf(r.attrs.id) > -1 ? d(d({}, r), { attrs: d(d({}, r.attrs), { id: r.attrs.id + t.idSuffix }) }) : r;
|
|
118
|
+
}) }) : e;
|
|
119
|
+
}
|
|
120
|
+
function Ke() {
|
|
121
|
+
return Math.random().toString(36).substring(2, 8);
|
|
122
|
+
}
|
|
123
|
+
$.displayName = "UniverIcon";
|
|
124
|
+
var Xe = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, ie = Z(function(e, t) {
|
|
125
|
+
return j($, Object.assign({}, e, {
|
|
126
|
+
id: "check-mark-single",
|
|
127
|
+
ref: t,
|
|
128
|
+
icon: Xe
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
ie.displayName = "CheckMarkSingle";
|
|
132
|
+
var qe = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z" } }] }, re = Z(function(e, t) {
|
|
133
|
+
return j($, Object.assign({}, e, {
|
|
134
|
+
id: "close-single",
|
|
135
|
+
ref: t,
|
|
136
|
+
icon: qe
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
re.displayName = "CloseSingle";
|
|
140
|
+
class Je {
|
|
141
|
+
constructor() {
|
|
142
|
+
E(this, "_position", null);
|
|
143
|
+
E(this, "_position$", new Ue(null));
|
|
144
|
+
E(this, "position$", this._position$.asObservable());
|
|
145
|
+
}
|
|
146
|
+
dispose() {
|
|
147
|
+
this._position$.complete(), this._position = null;
|
|
148
|
+
}
|
|
149
|
+
setPosition(t) {
|
|
150
|
+
this._position = t, this._refresh(t);
|
|
151
|
+
}
|
|
152
|
+
getPosition() {
|
|
153
|
+
return this._position;
|
|
154
|
+
}
|
|
155
|
+
_refresh(t) {
|
|
156
|
+
this._position$.next(t);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const V = le(
|
|
160
|
+
"univer.sheet-zen-editor-manager.service"
|
|
161
|
+
), Qe = "univer-zen-editor", et = "univer-zen-editor-icon-wrapper", tt = "univer-zen-editor-icon-container", nt = "univer-zen-editor-icon-success", it = "univer-zen-editor-icon-error", rt = "univer-zen-editor-canvas-container", m = {
|
|
162
|
+
zenEditor: Qe,
|
|
163
|
+
zenEditorIconWrapper: et,
|
|
164
|
+
zenEditorIconContainer: tt,
|
|
165
|
+
zenEditorIconSuccess: nt,
|
|
166
|
+
zenEditorIconError: it,
|
|
167
|
+
zenEditorCanvasContainer: rt
|
|
168
|
+
}, ot = "ZEN_EDITOR_PLUGIN_", st = `${ot}ZEN_EDITOR_COMPONENT`, ct = {
|
|
169
|
+
id: g,
|
|
170
|
+
body: {
|
|
171
|
+
dataStream: `${ue}`,
|
|
172
|
+
textRuns: [],
|
|
173
|
+
tables: [],
|
|
174
|
+
customBlocks: [],
|
|
175
|
+
paragraphs: [
|
|
176
|
+
{
|
|
177
|
+
startIndex: 0
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
sectionBreaks: [{
|
|
181
|
+
startIndex: 1
|
|
182
|
+
}]
|
|
183
|
+
},
|
|
184
|
+
tableSource: {},
|
|
185
|
+
documentStyle: {
|
|
186
|
+
pageSize: {
|
|
187
|
+
width: 595,
|
|
188
|
+
height: Number.POSITIVE_INFINITY
|
|
189
|
+
},
|
|
190
|
+
documentFlavor: q.MODERN,
|
|
191
|
+
marginTop: 0,
|
|
192
|
+
marginBottom: 0,
|
|
193
|
+
marginRight: 0,
|
|
194
|
+
marginLeft: 0,
|
|
195
|
+
renderConfig: {
|
|
196
|
+
vertexAngle: 0,
|
|
197
|
+
centerAngle: 0
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
drawings: {},
|
|
201
|
+
drawingsOrder: []
|
|
202
|
+
};
|
|
203
|
+
function at() {
|
|
204
|
+
const e = te(null), t = D(V), i = D(k), n = D(J);
|
|
205
|
+
ke(() => {
|
|
206
|
+
const o = e.current;
|
|
207
|
+
if (!o)
|
|
208
|
+
return;
|
|
209
|
+
const c = i.register({
|
|
210
|
+
editorUnitId: g,
|
|
211
|
+
initialSnapshot: ct,
|
|
212
|
+
scrollBar: !0,
|
|
213
|
+
backScrollOffset: 100
|
|
214
|
+
}, o), a = new ResizeObserver(() => {
|
|
215
|
+
t.setPosition(o.getBoundingClientRect());
|
|
216
|
+
});
|
|
217
|
+
return a.observe(o), () => {
|
|
218
|
+
c.dispose(), a.unobserve(o);
|
|
219
|
+
};
|
|
220
|
+
}, []);
|
|
221
|
+
function r() {
|
|
222
|
+
const o = i.getEditor(g);
|
|
223
|
+
o == null || o.blur(), n.executeCommand(L.id);
|
|
224
|
+
}
|
|
225
|
+
function s() {
|
|
226
|
+
const o = i.getEditor(g);
|
|
227
|
+
o == null || o.blur(), n.executeCommand(A.id);
|
|
228
|
+
}
|
|
229
|
+
return /* @__PURE__ */ F("div", { className: m.zenEditor, children: [
|
|
230
|
+
/* @__PURE__ */ F("div", { className: m.zenEditorIconWrapper, children: [
|
|
231
|
+
/* @__PURE__ */ _(
|
|
232
|
+
"span",
|
|
233
|
+
{
|
|
234
|
+
className: W(m.zenEditorIconContainer, m.zenEditorIconError),
|
|
235
|
+
onClick: r,
|
|
236
|
+
children: /* @__PURE__ */ _(re, { style: { fontSize: "22px" } })
|
|
237
|
+
}
|
|
238
|
+
),
|
|
239
|
+
/* @__PURE__ */ _(
|
|
240
|
+
"span",
|
|
241
|
+
{
|
|
242
|
+
className: W(m.zenEditorIconContainer, m.zenEditorIconSuccess),
|
|
243
|
+
onClick: s,
|
|
244
|
+
children: /* @__PURE__ */ _(ie, { style: { fontSize: "22px" } })
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
] }),
|
|
248
|
+
/* @__PURE__ */ _("div", { className: m.zenEditorCanvasContainer, ref: e })
|
|
249
|
+
] });
|
|
250
|
+
}
|
|
251
|
+
function dt(e) {
|
|
252
|
+
const t = e.get(b);
|
|
253
|
+
return {
|
|
254
|
+
id: B.id,
|
|
255
|
+
type: Me.BUTTON,
|
|
256
|
+
title: "rightClick.zenEditor",
|
|
257
|
+
icon: "AmplifySingle",
|
|
258
|
+
hidden$: Te(e),
|
|
259
|
+
disabled$: t.currentEditCell$.pipe(
|
|
260
|
+
Ze((i) => be(e, { workbookTypes: [Fe], worksheetTypes: [Ae, $e, Ve], rangeTypes: [Le] }).pipe(je((n) => {
|
|
261
|
+
var r, s, o, c;
|
|
262
|
+
return n || ((c = (o = (s = (r = i == null ? void 0 : i.documentLayoutObject.documentModel) == null ? void 0 : r.getBody()) == null ? void 0 : s.customBlocks) == null ? void 0 : o.length) != null ? c : 0) > 0;
|
|
263
|
+
})))
|
|
264
|
+
)
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
const lt = {
|
|
268
|
+
[De.MAIN_AREA]: {
|
|
269
|
+
[Re.OTHERS]: {
|
|
270
|
+
[B.id]: {
|
|
271
|
+
order: 2,
|
|
272
|
+
menuItemFactory: dt
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}, ut = {
|
|
277
|
+
id: A.id,
|
|
278
|
+
description: "shortcut.sheet.zen-edit-confirm",
|
|
279
|
+
group: "4_sheet-edit",
|
|
280
|
+
preconditions: (e) => oe(e),
|
|
281
|
+
binding: ee.ENTER | Pe.ALT
|
|
282
|
+
}, gt = {
|
|
283
|
+
id: L.id,
|
|
284
|
+
description: "shortcut.sheet.zen-edit-cancel",
|
|
285
|
+
group: "4_sheet-edit",
|
|
286
|
+
preconditions: (e) => oe(e),
|
|
287
|
+
binding: ee.ESC
|
|
288
|
+
};
|
|
289
|
+
function oe(e) {
|
|
290
|
+
return e.getContextValue(ge) && e.getContextValue(fe) && e.getContextValue(he) && !e.getContextValue(me);
|
|
291
|
+
}
|
|
292
|
+
var ft = Object.getOwnPropertyDescriptor, ht = (e, t, i, n) => {
|
|
293
|
+
for (var r = n > 1 ? void 0 : n ? ft(t, i) : t, s = e.length - 1, o; s >= 0; s--)
|
|
294
|
+
(o = e[s]) && (r = o(r) || r);
|
|
295
|
+
return r;
|
|
296
|
+
}, O = (e, t) => (i, n) => t(i, n, e);
|
|
297
|
+
let N = class extends ve {
|
|
298
|
+
constructor(e, t, i, n) {
|
|
299
|
+
super(), this._zenZoneService = e, this._commandService = t, this._menuManagerService = i, this._shortcutService = n, this._initialize();
|
|
300
|
+
}
|
|
301
|
+
_initialize() {
|
|
302
|
+
this._initCustomComponents(), this._initCommands(), this._initMenus(), this._initShortcuts();
|
|
303
|
+
}
|
|
304
|
+
_initCustomComponents() {
|
|
305
|
+
this.disposeWithMe(this._zenZoneService.set(st, at));
|
|
306
|
+
}
|
|
307
|
+
_initCommands() {
|
|
308
|
+
[B, L, A].forEach((e) => {
|
|
309
|
+
this.disposeWithMe(this._commandService.registerCommand(e));
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
_initMenus() {
|
|
313
|
+
this._menuManagerService.mergeMenu(lt);
|
|
314
|
+
}
|
|
315
|
+
_initShortcuts() {
|
|
316
|
+
[ut, gt].forEach((e) => {
|
|
317
|
+
this.disposeWithMe(this._shortcutService.registerShortcut(e));
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
N = ht([
|
|
322
|
+
O(0, z),
|
|
323
|
+
O(1, J),
|
|
324
|
+
O(2, we),
|
|
325
|
+
O(3, xe)
|
|
326
|
+
], N);
|
|
327
|
+
var mt = Object.getOwnPropertyDescriptor, vt = (e, t, i, n) => {
|
|
328
|
+
for (var r = n > 1 ? void 0 : n ? mt(t, i) : t, s = e.length - 1, o; s >= 0; s--)
|
|
329
|
+
(o = e[s]) && (r = o(r) || r);
|
|
330
|
+
return r;
|
|
331
|
+
}, Y = (e, t) => (i, n) => t(i, n, e);
|
|
332
|
+
let T = class extends pe {
|
|
333
|
+
constructor(e, t) {
|
|
334
|
+
super(), this._zenEditorManagerService = e, this._renderManagerService = t, this._initialize();
|
|
335
|
+
}
|
|
336
|
+
_initialize() {
|
|
337
|
+
this._syncZenEditorSize();
|
|
338
|
+
}
|
|
339
|
+
// Listen to changes in the size of the zen editor container to set the size of the editor.
|
|
340
|
+
_syncZenEditorSize() {
|
|
341
|
+
this._zenEditorManagerService.position$.pipe(Be(this.dispose$)).subscribe((e) => {
|
|
342
|
+
if (e == null)
|
|
343
|
+
return;
|
|
344
|
+
const { width: t, height: i } = e, n = ze(g, this._renderManagerService);
|
|
345
|
+
n != null && requestIdleCallback(() => {
|
|
346
|
+
n.engine.resizeBySize(t, i), this._calculatePagePosition(n), this._scrollToTop();
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
_calculatePagePosition(e) {
|
|
351
|
+
const { document: t, scene: i, docBackground: n } = e, r = i == null ? void 0 : i.getParent(), { width: s, height: o, pageMarginLeft: c, pageMarginTop: a } = t;
|
|
352
|
+
if (r == null || s === Number.POSITIVE_INFINITY || o === Number.POSITIVE_INFINITY)
|
|
353
|
+
return;
|
|
354
|
+
const { width: u, height: v } = r;
|
|
355
|
+
let l = 0;
|
|
356
|
+
const f = a;
|
|
357
|
+
let p = 0, I = 0, S = Number.POSITIVE_INFINITY;
|
|
358
|
+
const { scaleX: h, scaleY: C } = i.getAncestorScale();
|
|
359
|
+
u > (s + c * 2) * h ? (l = u / 2 - s * h / 2, l /= h, p = (u - c * 2) / h, S = 0) : (l = c, p = s + c * 2, S = (p - u / h) / 2), v > o ? I = (v - a * 2) / C : I = o + a * 2, i.resize(p, I), t.translate(l, f), n.translate(l, f);
|
|
360
|
+
const M = i.getViewport(Oe.VIEW_MAIN);
|
|
361
|
+
if (S !== Number.POSITIVE_INFINITY && M != null) {
|
|
362
|
+
const se = M.transScroll2ViewportScrollValue(S, 0).x;
|
|
363
|
+
M.scrollToBarPos({
|
|
364
|
+
x: se
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
_scrollToTop() {
|
|
370
|
+
var i;
|
|
371
|
+
const e = (i = this._renderManagerService.getRenderById(g)) == null ? void 0 : i.with(ye), t = {
|
|
372
|
+
startOffset: 0,
|
|
373
|
+
endOffset: 0
|
|
374
|
+
};
|
|
375
|
+
e && e.scrollToRange(t);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
T = vt([
|
|
379
|
+
Y(0, V),
|
|
380
|
+
Y(1, Q)
|
|
381
|
+
], T);
|
|
382
|
+
var pt = Object.getOwnPropertyDescriptor, St = (e, t, i, n) => {
|
|
383
|
+
for (var r = n > 1 ? void 0 : n ? pt(t, i) : t, s = e.length - 1, o; s >= 0; s--)
|
|
384
|
+
(o = e[s]) && (r = o(r) || r);
|
|
385
|
+
return r;
|
|
386
|
+
}, G = (e, t) => (i, n) => t(i, n, e), y;
|
|
387
|
+
let K = (y = class extends Se {
|
|
388
|
+
constructor(e = H, t, i) {
|
|
389
|
+
super(), this._config = e, this._injector = t, this._configService = i;
|
|
390
|
+
const { menu: n, ...r } = Ee(
|
|
391
|
+
{},
|
|
392
|
+
H,
|
|
393
|
+
this._config
|
|
394
|
+
);
|
|
395
|
+
n && this._configService.setConfig("menu", n, { merge: !0 }), this._configService.setConfig(We, r), this._initializeDependencies(this._injector);
|
|
396
|
+
}
|
|
397
|
+
_initializeDependencies(e) {
|
|
398
|
+
[
|
|
399
|
+
[N],
|
|
400
|
+
[T],
|
|
401
|
+
[V, { useClass: Je }]
|
|
402
|
+
].forEach((i) => e.add(i));
|
|
403
|
+
}
|
|
404
|
+
onReady() {
|
|
405
|
+
this._injector.get(N);
|
|
406
|
+
}
|
|
407
|
+
onSteady() {
|
|
408
|
+
this._injector.get(T);
|
|
409
|
+
}
|
|
410
|
+
}, E(y, "pluginName", "SHEET_ZEN_EDITOR_PLUGIN"), E(y, "type", x.UNIVER_SHEET), y);
|
|
411
|
+
K = St([
|
|
412
|
+
G(1, _e(Ie)),
|
|
413
|
+
G(2, Ce)
|
|
414
|
+
], K);
|
|
415
|
+
export {
|
|
416
|
+
L as CancelZenEditCommand,
|
|
417
|
+
A as ConfirmZenEditCommand,
|
|
418
|
+
B as OpenZenEditorCommand,
|
|
419
|
+
K as UniverSheetsZenEditorPlugin
|
|
420
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
rightClick: {
|
|
3
|
+
zenEditor: "Chế độ chỉnh sửa Zen"
|
|
4
|
+
},
|
|
5
|
+
shortcut: {
|
|
6
|
+
sheet: {
|
|
7
|
+
"zen-edit-cancel": "Hủy chỉnh sửa (trạng thái Zen mode)",
|
|
8
|
+
"zen-edit-confirm": "Bỏ chỉnh sửa (trạng thái Zen mode)"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
e as default
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-zen-editor",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Zen Editor plugin for Univer Sheets.",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -55,19 +55,19 @@
|
|
|
55
55
|
"lib"
|
|
56
56
|
],
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"react": "
|
|
58
|
+
"react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc",
|
|
59
59
|
"rxjs": ">=7.0.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@univerjs/icons": "^0.2.
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/sheets": "0.6.
|
|
68
|
-
"@univerjs/
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/ui": "0.6.
|
|
62
|
+
"@univerjs/icons": "^0.2.31",
|
|
63
|
+
"@univerjs/core": "0.6.9",
|
|
64
|
+
"@univerjs/design": "0.6.9",
|
|
65
|
+
"@univerjs/engine-render": "0.6.9",
|
|
66
|
+
"@univerjs/docs": "0.6.9",
|
|
67
|
+
"@univerjs/sheets": "0.6.9",
|
|
68
|
+
"@univerjs/ui": "0.6.9",
|
|
69
|
+
"@univerjs/docs-ui": "0.6.9",
|
|
70
|
+
"@univerjs/sheets-ui": "0.6.9"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"less": "^4.2.2",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"typescript": "^5.8.2",
|
|
79
79
|
"vite": "^6.2.3",
|
|
80
80
|
"vitest": "^3.0.9",
|
|
81
|
-
"@univerjs-infra/shared": "0.6.
|
|
81
|
+
"@univerjs-infra/shared": "0.6.9"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
84
|
"test": "vitest run",
|