| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- var ue = Object.defineProperty;
- var fe = (e, n, r) => n in e ? ue(e, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[n] = r;
- var S = (e, n, r) => fe(e, typeof n != "symbol" ? n + "" : n, r);
- import { CommandType as M, IUniverInstanceService as D, delayAnimationFrame as w, DOCS_ZEN_EDITOR_UNIT_ID_KEY as m, Tools as Q, UniverInstanceType as j, DocumentFlavor as ee, DocumentDataModel as ge, createIdentifier as he, DEFAULT_EMPTY_DOCUMENT_VALUE as me, useDependency as x, ICommandService as te, FOCUSING_DOC as _e, FOCUSING_UNIVER_EDITOR as pe, EDITOR_ACTIVATED as ve, FOCUSING_EDITOR_STANDALONE as Ee, Disposable as Se, RxDisposable as Ie, Plugin as Ce, merge as Oe, Inject as ye, Injector as Ne, IConfigService as be } from "@univerjs/core";
- import { IEditorService as U, VIEWPORT_KEY as Te, DocBackScrollRenderController as Re } from "@univerjs/docs-ui";
- import { IRenderManagerService as ne } from "@univerjs/engine-render";
- import { IEditorBridgeService as Z, EditingRenderController as ze, getCurrentExclusiveRangeInterest$ as xe, getCurrentRangeDisable$ as Pe, getEditorObject as Me } from "@univerjs/sheets-ui";
- import { IZenZoneService as R, ISidebarService as L, MenuItemType as De, ContextMenuPosition as we, ContextMenuGroup as je, KeyCode as re, MetaKeys as Ue, IMenuManagerService as Ze, IShortcutService as Le } from "@univerjs/ui";
- import Ae, { forwardRef as A, useRef as ie, createElement as $, useEffect as $e } from "react";
- import { BehaviorSubject as Be, takeUntil as ke } from "rxjs";
- import { WorkbookEditablePermission as Fe, WorksheetEditPermission as Ve, WorksheetSetCellValuePermission as We, WorksheetSetCellStylePermission as He, RangeProtectionPermissionEditPoint as Ye } from "@univerjs/sheets";
- const B = {
- id: "zen-editor.command.open-zen-editor",
- type: M.COMMAND,
- handler: async (e) => {
- var O;
- const n = e.get(R), r = e.get(U), t = e.get(Z), i = e.get(D), s = e.get(L);
- s.visible && (s.close(), await w()), n.open();
- const o = r.getEditor(m);
- if (o == null)
- return !1;
- const a = t.getLatestEditCellState();
- if (a == null)
- return !1;
- const c = (O = a.documentLayoutObject.documentModel) == null ? void 0 : O.getSnapshot();
- if (c == null)
- return !1;
- i.focusUnit(m);
- const { body: u, drawings: d, drawingsOrder: l, tableSource: g, settings: h } = Q.deepClone(c), E = {
- ...o.getDocumentData(),
- body: u,
- drawings: d,
- drawingsOrder: l,
- tableSource: g,
- settings: h
- }, _ = [
- {
- startOffset: 0,
- endOffset: 0,
- collapsed: !0
- }
- ];
- return o.focus(), o.setDocumentData(E, _), o.clearUndoRedoHistory(), !0;
- }
- }, k = {
- id: "zen-editor.command.cancel-zen-edit",
- type: M.COMMAND,
- handler: async (e) => {
- const n = e.get(R), r = e.get(Z), t = e.get(D), i = e.get(L);
- i.visible && (i.close(), await w()), n.close();
- const s = t.getCurrentUnitForType(j.UNIVER_SHEET);
- return s ? (t.focusUnit(s.getUnitId()), r.refreshEditCellState(), !0) : !1;
- }
- }, F = {
- id: "zen-editor.command.confirm-zen-edit",
- type: M.COMMAND,
- handler: async (e) => {
- var u;
- const n = e.get(R), r = e.get(Z), t = e.get(D), i = e.get(U), s = e.get(L);
- s.visible && (s.close(), await w()), n.close();
- const o = i.getEditor(m);
- if (o == null)
- return !1;
- const a = e.get(ne), c = t.getCurrentUnitForType(j.UNIVER_SHEET);
- if (c) {
- const d = c.getUnitId(), l = (u = a.getRenderById(d)) == null ? void 0 : u.with(ze);
- if (l) {
- const g = Q.deepClone(o.getDocumentData());
- g.documentStyle.documentFlavor = ee.UNSPECIFIED, l.submitCellData(new ge(g));
- }
- return t.focusUnit(c.getUnitId()), r.refreshEditCellState(), !0;
- }
- return !1;
- }
- }, Ge = "sheets-zen-editor.config", H = {};
- var P = { exports: {} }, I = {};
- /**
- * @license React
- * react-jsx-runtime.production.min.js
- *
- * Copyright (c) Facebook, Inc. and its affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
- var Y;
- function qe() {
- if (Y) return I;
- Y = 1;
- var e = Ae, n = Symbol.for("react.element"), r = Symbol.for("react.fragment"), t = Object.prototype.hasOwnProperty, i = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: !0, ref: !0, __self: !0, __source: !0 };
- function o(a, c, u) {
- var d, l = {}, g = null, h = null;
- u !== void 0 && (g = "" + u), c.key !== void 0 && (g = "" + c.key), c.ref !== void 0 && (h = c.ref);
- for (d in c) t.call(c, d) && !s.hasOwnProperty(d) && (l[d] = c[d]);
- if (a && a.defaultProps) for (d in c = a.defaultProps, c) l[d] === void 0 && (l[d] = c[d]);
- return { $$typeof: n, type: a, key: g, ref: h, props: l, _owner: i.current };
- }
- return I.Fragment = r, I.jsx = o, I.jsxs = o, I;
- }
- var G;
- function Je() {
- return G || (G = 1, P.exports = qe()), P.exports;
- }
- var p = Je(), f = function() {
- return f = Object.assign || function(e) {
- for (var n, r = 1, t = arguments.length; r < t; r++) {
- n = arguments[r];
- for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (e[i] = n[i]);
- }
- return e;
- }, f.apply(this, arguments);
- }, Ke = function(e, n) {
- var r = {};
- for (var t in e) Object.prototype.hasOwnProperty.call(e, t) && n.indexOf(t) < 0 && (r[t] = e[t]);
- if (e != null && typeof Object.getOwnPropertySymbols == "function")
- for (var i = 0, t = Object.getOwnPropertySymbols(e); i < t.length; i++)
- n.indexOf(t[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, t[i]) && (r[t[i]] = e[t[i]]);
- return r;
- }, V = A(function(e, n) {
- var r = e.icon, t = e.id, i = e.className, s = e.extend, o = Ke(e, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(t, " ").concat(i || "").trim(), c = ie("_".concat(et()));
- return oe(r, "".concat(t), { defIds: r.defIds, idSuffix: c.current }, f({ ref: n, className: a }, o), s);
- });
- function oe(e, n, r, t, i) {
- return $(e.tag, f(f({ key: n }, Xe(e, r, i)), t), (Qe(e, r).children || []).map(function(s, o) {
- return oe(s, "".concat(n, "-").concat(e.tag, "-").concat(o), r, void 0, i);
- }));
- }
- function Xe(e, n, r) {
- var t = f({}, e.attrs);
- r != null && r.colorChannel1 && t.fill === "colorChannel1" && (t.fill = r.colorChannel1);
- var i = n.defIds;
- return !i || i.length === 0 || (e.tag === "use" && t["xlink:href"] && (t["xlink:href"] = t["xlink:href"] + n.idSuffix), Object.entries(t).forEach(function(s) {
- var o = s[0], a = s[1];
- typeof a == "string" && (t[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(n.idSuffix, ")")));
- })), t;
- }
- function Qe(e, n) {
- var r, t = n.defIds;
- return !t || t.length === 0 ? e : e.tag === "defs" && (!((r = e.children) === null || r === void 0) && r.length) ? f(f({}, e), { children: e.children.map(function(i) {
- return typeof i.attrs.id == "string" && t && t.indexOf(i.attrs.id) > -1 ? f(f({}, i), { attrs: f(f({}, i.attrs), { id: i.attrs.id + n.idSuffix }) }) : i;
- }) }) : e;
- }
- function et() {
- return Math.random().toString(36).substring(2, 8);
- }
- V.displayName = "UniverIcon";
- var tt = { 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" } }] }, se = A(function(e, n) {
- return $(V, Object.assign({}, e, {
- id: "check-mark-single",
- ref: n,
- icon: tt
- }));
- });
- se.displayName = "CheckMarkSingle";
- var nt = { 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" } }] }, ce = A(function(e, n) {
- return $(V, Object.assign({}, e, {
- id: "close-single",
- ref: n,
- icon: nt
- }));
- });
- ce.displayName = "CloseSingle";
- function ae(e) {
- var n, r, t = "";
- if (typeof e == "string" || typeof e == "number") t += e;
- else if (typeof e == "object") if (Array.isArray(e)) {
- var i = e.length;
- for (n = 0; n < i; n++) e[n] && (r = ae(e[n])) && (t && (t += " "), t += r);
- } else for (r in e) e[r] && (t && (t += " "), t += r);
- return t;
- }
- function q() {
- for (var e, n, r = 0, t = "", i = arguments.length; r < i; r++) (e = arguments[r]) && (n = ae(e)) && (t && (t += " "), t += n);
- return t;
- }
- class rt {
- constructor() {
- S(this, "_position", null);
- S(this, "_position$", new Be(null));
- S(this, "position$", this._position$.asObservable());
- }
- dispose() {
- this._position$.complete(), this._position = null;
- }
- setPosition(n) {
- this._position = n, this._refresh(n);
- }
- getPosition() {
- return this._position;
- }
- _refresh(n) {
- this._position$.next(n);
- }
- }
- const W = he(
- "univer.sheet-zen-editor-manager.service"
- ), it = "univer-zen-editor", ot = "univer-zen-editor-icon-wrapper", st = "univer-zen-editor-icon-container", ct = "univer-zen-editor-icon-success", at = "univer-zen-editor-icon-error", dt = "univer-zen-editor-canvas-container", v = {
- zenEditor: it,
- zenEditorIconWrapper: ot,
- zenEditorIconContainer: st,
- zenEditorIconSuccess: ct,
- zenEditorIconError: at,
- zenEditorCanvasContainer: dt
- }, lt = "ZEN_EDITOR_PLUGIN_", ut = `${lt}ZEN_EDITOR_COMPONENT`, ft = {
- id: m,
- body: {
- dataStream: `${me}`,
- textRuns: [],
- tables: [],
- customBlocks: [],
- paragraphs: [
- {
- startIndex: 0
- }
- ],
- sectionBreaks: [{
- startIndex: 1
- }]
- },
- tableSource: {},
- documentStyle: {
- pageSize: {
- width: 595,
- height: Number.POSITIVE_INFINITY
- },
- documentFlavor: ee.MODERN,
- marginTop: 0,
- marginBottom: 0,
- marginRight: 0,
- marginLeft: 0,
- renderConfig: {
- vertexAngle: 0,
- centerAngle: 0
- }
- },
- drawings: {},
- drawingsOrder: []
- };
- function gt() {
- const e = ie(null), n = x(W), r = x(U), t = x(te);
- $e(() => {
- const o = e.current;
- if (!o)
- return;
- const a = r.register(
- {
- editorUnitId: m,
- initialSnapshot: ft,
- scrollBar: !0,
- backScrollOffset: 100
- },
- o
- ), c = new ResizeObserver(() => {
- n.setPosition(o.getBoundingClientRect());
- });
- return c.observe(o), () => {
- a.dispose(), c.unobserve(o);
- };
- }, []);
- function i() {
- const o = r.getEditor(m);
- o == null || o.blur(), t.executeCommand(k.id);
- }
- function s() {
- const o = r.getEditor(m);
- o == null || o.blur(), t.executeCommand(F.id);
- }
- return /* @__PURE__ */ p.jsxs("div", { className: v.zenEditor, children: [
- /* @__PURE__ */ p.jsxs("div", { className: v.zenEditorIconWrapper, children: [
- /* @__PURE__ */ p.jsx(
- "span",
- {
- className: q(v.zenEditorIconContainer, v.zenEditorIconError),
- onClick: i,
- children: /* @__PURE__ */ p.jsx(ce, { style: { fontSize: "22px" } })
- }
- ),
- /* @__PURE__ */ p.jsx(
- "span",
- {
- className: q(v.zenEditorIconContainer, v.zenEditorIconSuccess),
- onClick: s,
- children: /* @__PURE__ */ p.jsx(se, { style: { fontSize: "22px" } })
- }
- )
- ] }),
- /* @__PURE__ */ p.jsx("div", { className: v.zenEditorCanvasContainer, ref: e })
- ] });
- }
- function ht(e) {
- return {
- id: B.id,
- type: De.BUTTON,
- title: "rightClick.zenEditor",
- icon: "AmplifySingle",
- hidden$: xe(e),
- disabled$: Pe(e, { workbookTypes: [Fe], worksheetTypes: [Ve, We, He], rangeTypes: [Ye] })
- };
- }
- const mt = {
- [we.MAIN_AREA]: {
- [je.OTHERS]: {
- [B.id]: {
- order: 2,
- menuItemFactory: ht
- }
- }
- }
- }, _t = {
- id: F.id,
- description: "shortcut.sheet.zen-edit-confirm",
- group: "4_sheet-edit",
- preconditions: (e) => de(e),
- binding: re.ENTER | Ue.ALT
- }, pt = {
- id: k.id,
- description: "shortcut.sheet.zen-edit-cancel",
- group: "4_sheet-edit",
- preconditions: (e) => de(e),
- binding: re.ESC
- };
- function de(e) {
- return e.getContextValue(_e) && e.getContextValue(pe) && e.getContextValue(ve) && !e.getContextValue(Ee);
- }
- var vt = Object.defineProperty, Et = Object.getOwnPropertyDescriptor, St = (e, n, r, t) => {
- for (var i = t > 1 ? void 0 : t ? Et(n, r) : n, s = e.length - 1, o; s >= 0; s--)
- (o = e[s]) && (i = (t ? o(n, r, i) : o(i)) || i);
- return t && i && vt(n, r, i), i;
- }, y = (e, n) => (r, t) => n(r, t, e);
- let b = class extends Se {
- constructor(e, n, r, t) {
- super(), this._zenZoneService = e, this._commandService = n, this._menuManagerService = r, this._shortcutService = t, this._initialize();
- }
- _initialize() {
- this._initCustomComponents(), this._initCommands(), this._initMenus(), this._initShortcuts();
- }
- _initCustomComponents() {
- this.disposeWithMe(this._zenZoneService.set(ut, gt));
- }
- _initCommands() {
- [B, k, F].forEach((e) => {
- this.disposeWithMe(this._commandService.registerCommand(e));
- });
- }
- _initMenus() {
- this._menuManagerService.mergeMenu(mt);
- }
- _initShortcuts() {
- [_t, pt].forEach((e) => {
- this.disposeWithMe(this._shortcutService.registerShortcut(e));
- });
- }
- };
- b = St([
- y(0, R),
- y(1, te),
- y(2, Ze),
- y(3, Le)
- ], b);
- var It = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, Ot = (e, n, r, t) => {
- for (var i = t > 1 ? void 0 : t ? Ct(n, r) : n, s = e.length - 1, o; s >= 0; s--)
- (o = e[s]) && (i = (t ? o(n, r, i) : o(i)) || i);
- return t && i && It(n, r, i), i;
- }, J = (e, n) => (r, t) => n(r, t, e);
- let T = class extends Ie {
- constructor(e, n) {
- super(), this._zenEditorManagerService = e, this._renderManagerService = n, this._initialize();
- }
- _initialize() {
- this._syncZenEditorSize();
- }
- // Listen to changes in the size of the zen editor container to set the size of the editor.
- _syncZenEditorSize() {
- this._zenEditorManagerService.position$.pipe(ke(this.dispose$)).subscribe((e) => {
- if (e == null)
- return;
- const { width: n, height: r } = e, t = Me(m, this._renderManagerService);
- t != null && requestIdleCallback(() => {
- t.engine.resizeBySize(n, r), this._calculatePagePosition(t), this._scrollToTop();
- });
- });
- }
- _calculatePagePosition(e) {
- const { document: n, scene: r, docBackground: t } = e, i = r == null ? void 0 : r.getParent(), { width: s, height: o, pageMarginLeft: a, pageMarginTop: c } = n;
- if (i == null || s === Number.POSITIVE_INFINITY || o === Number.POSITIVE_INFINITY)
- return;
- const { width: u, height: d } = i;
- let l = 0;
- const g = c;
- let h = 0, C = 0, E = Number.POSITIVE_INFINITY;
- const { scaleX: _, scaleY: O } = r.getAncestorScale();
- u > (s + a * 2) * _ ? (l = u / 2 - s * _ / 2, l /= _, h = (u - a * 2) / _, E = 0) : (l = a, h = s + a * 2, E = (h - u / _) / 2), d > o ? C = (d - c * 2) / O : C = o + c * 2, r.resize(h, C), n.translate(l, g), t.translate(l, g);
- const z = r.getViewport(Te.VIEW_MAIN);
- if (E !== Number.POSITIVE_INFINITY && z != null) {
- const le = z.transScroll2ViewportScrollValue(E, 0).x;
- z.scrollToBarPos({
- x: le
- });
- }
- return this;
- }
- _scrollToTop() {
- var r;
- const e = (r = this._renderManagerService.getRenderById(m)) == null ? void 0 : r.with(Re), n = {
- startOffset: 0,
- endOffset: 0
- };
- e && e.scrollToRange(n);
- }
- };
- T = Ot([
- J(0, W),
- J(1, ne)
- ], T);
- var yt = Object.defineProperty, Nt = Object.getOwnPropertyDescriptor, bt = (e, n, r, t) => {
- for (var i = t > 1 ? void 0 : t ? Nt(n, r) : n, s = e.length - 1, o; s >= 0; s--)
- (o = e[s]) && (i = (t ? o(n, r, i) : o(i)) || i);
- return t && i && yt(n, r, i), i;
- }, K = (e, n) => (r, t) => n(r, t, e), N;
- let X = (N = class extends Ce {
- constructor(e = H, n, r) {
- super(), this._config = e, this._injector = n, this._configService = r;
- const { menu: t, ...i } = Oe(
- {},
- H,
- this._config
- );
- t && this._configService.setConfig("menu", t, { merge: !0 }), this._configService.setConfig(Ge, i), this._initializeDependencies(this._injector);
- }
- _initializeDependencies(e) {
- [
- [b],
- [T],
- [W, { useClass: rt }]
- ].forEach((r) => e.add(r));
- }
- onReady() {
- this._injector.get(b);
- }
- onSteady() {
- this._injector.get(T);
- }
- }, S(N, "pluginName", "SHEET_ZEN_EDITOR_PLUGIN"), S(N, "type", j.UNIVER_SHEET), N);
- X = bt([
- K(1, ye(Ne)),
- K(2, be)
- ], X);
- export {
- k as CancelZenEditCommand,
- F as ConfirmZenEditCommand,
- B as OpenZenEditorCommand,
- X as UniverSheetsZenEditorPlugin
- };
|