123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- import {
- Ec,
- Ed,
- bb,
- tt,
- ue
- } from "./chunk-T4NNB5UY.js";
- import {
- Me,
- Pe,
- Te,
- ar as ar2,
- wn
- } from "./chunk-BW43Z7N3.js";
- import "./chunk-QRYBFJ3R.js";
- import {
- He as He2,
- Xe,
- kn
- } from "./chunk-MIOQ566M.js";
- import {
- $e,
- Ae,
- He,
- I1,
- P1,
- it,
- m1,
- rt,
- u3
- } from "./chunk-POAJ2YNP.js";
- import "./chunk-GBYP4PB2.js";
- import "./chunk-PZD7N4BC.js";
- import {
- Yx
- } from "./chunk-2MK3Q52E.js";
- import "./chunk-BSDDCPAW.js";
- import "./chunk-QG2HZMYH.js";
- import {
- BehaviorSubject,
- CR,
- Ct,
- Fe,
- Hd,
- J0,
- Nr,
- Ot,
- PR,
- Pt,
- RR,
- Ra,
- SE,
- W0,
- Wd,
- _n,
- ar,
- jt,
- ku,
- nt,
- nu,
- oE,
- ot,
- re,
- takeUntil
- } from "./chunk-23V3HWTR.js";
- import {
- require_react
- } from "./chunk-GNR2UJZM.js";
- import {
- __toESM
- } from "./chunk-2LSFTFF7.js";
- // node_modules/.pnpm/@univerjs+sheets-zen-editor@0.5.5_@grpc+grpc-js@1.13.4_react-dom@18.3.1_react@18.3.1_rxjs@7.8.1_typescript@5.4.5/node_modules/@univerjs/sheets-zen-editor/lib/es/index.js
- var import_react = __toESM(require_react());
- var ue2 = Object.defineProperty;
- var fe = (e, n, r) => n in e ? ue2(e, n, { enumerable: true, configurable: true, writable: true, value: r }) : e[n] = r;
- var S = (e, n, r) => fe(e, typeof n != "symbol" ? n + "" : n, r);
- var B = {
- id: "zen-editor.command.open-zen-editor",
- type: ar.COMMAND,
- handler: async (e) => {
- var O;
- const n = e.get(u3), r = e.get(He2), t = e.get(tt), i = e.get(_n), s = e.get(rt);
- s.visible && (s.close(), await PR()), n.open();
- const o = r.getEditor(Hd);
- if (o == null)
- return false;
- const a = t.getLatestEditCellState();
- if (a == null)
- return false;
- const c = (O = a.documentLayoutObject.documentModel) == null ? void 0 : O.getSnapshot();
- if (c == null)
- return false;
- i.focusUnit(Hd);
- const { body: u, drawings: d, drawingsOrder: l, tableSource: g, settings: h } = re.deepClone(c), E = {
- ...o.getDocumentData(),
- body: u,
- drawings: d,
- drawingsOrder: l,
- tableSource: g,
- settings: h
- }, _ = [
- {
- startOffset: 0,
- endOffset: 0,
- collapsed: true
- }
- ];
- return o.focus(), o.setDocumentData(E, _), o.clearUndoRedoHistory(), true;
- }
- };
- var k = {
- id: "zen-editor.command.cancel-zen-edit",
- type: ar.COMMAND,
- handler: async (e) => {
- const n = e.get(u3), r = e.get(tt), t = e.get(_n), i = e.get(rt);
- i.visible && (i.close(), await PR()), n.close();
- const s = t.getCurrentUnitForType(Fe.UNIVER_SHEET);
- return s ? (t.focusUnit(s.getUnitId()), r.refreshEditCellState(), true) : false;
- }
- };
- var F = {
- id: "zen-editor.command.confirm-zen-edit",
- type: ar.COMMAND,
- handler: async (e) => {
- var u;
- const n = e.get(u3), r = e.get(tt), t = e.get(_n), i = e.get(He2), s = e.get(rt);
- s.visible && (s.close(), await PR()), n.close();
- const o = i.getEditor(Hd);
- if (o == null)
- return false;
- const a = e.get(Yx), c = t.getCurrentUnitForType(Fe.UNIVER_SHEET);
- if (c) {
- const d = c.getUnitId(), l = (u = a.getRenderById(d)) == null ? void 0 : u.with(Ec);
- if (l) {
- const g = re.deepClone(o.getDocumentData());
- g.documentStyle.documentFlavor = ku.UNSPECIFIED, l.submitCellData(new jt(g));
- }
- return t.focusUnit(c.getUnitId()), r.refreshEditCellState(), true;
- }
- return false;
- }
- };
- var Ge = "sheets-zen-editor.config";
- var H = {};
- var P = { exports: {} };
- var I = {};
- var Y;
- function qe() {
- if (Y)
- return I;
- Y = 1;
- var e = import_react.default, 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: true, ref: true, __self: true, __source: true };
- 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();
- var 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);
- };
- var 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;
- };
- var V = (0, import_react.forwardRef)(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 = (0, import_react.useRef)("_".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 (0, import_react.createElement)(e.tag, f(f({ key: n }, Xe2(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 Xe2(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 tt2 = { 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" } }] };
- var se = (0, import_react.forwardRef)(function(e, n) {
- return (0, import_react.createElement)(V, Object.assign({}, e, {
- id: "check-mark-single",
- ref: n,
- icon: tt2
- }));
- });
- se.displayName = "CheckMarkSingle";
- var nt2 = { 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" } }] };
- var ce = (0, import_react.forwardRef)(function(e, n) {
- return (0, import_react.createElement)(V, Object.assign({}, e, {
- id: "close-single",
- ref: n,
- icon: nt2
- }));
- });
- 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;
- }
- var rt2 = class {
- constructor() {
- S(this, "_position", null);
- S(this, "_position$", new BehaviorSubject(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);
- }
- };
- var W = Ct(
- "univer.sheet-zen-editor-manager.service"
- );
- var it2 = "univer-zen-editor";
- var ot2 = "univer-zen-editor-icon-wrapper";
- var st = "univer-zen-editor-icon-container";
- var ct = "univer-zen-editor-icon-success";
- var at = "univer-zen-editor-icon-error";
- var dt = "univer-zen-editor-canvas-container";
- var v = {
- zenEditor: it2,
- zenEditorIconWrapper: ot2,
- zenEditorIconContainer: st,
- zenEditorIconSuccess: ct,
- zenEditorIconError: at,
- zenEditorCanvasContainer: dt
- };
- var lt = "ZEN_EDITOR_PLUGIN_";
- var ut = `${lt}ZEN_EDITOR_COMPONENT`;
- var ft = {
- id: Hd,
- body: {
- dataStream: `${Wd}`,
- textRuns: [],
- tables: [],
- customBlocks: [],
- paragraphs: [
- {
- startIndex: 0
- }
- ],
- sectionBreaks: [{
- startIndex: 1
- }]
- },
- tableSource: {},
- documentStyle: {
- pageSize: {
- width: 595,
- height: Number.POSITIVE_INFINITY
- },
- documentFlavor: ku.MODERN,
- marginTop: 0,
- marginBottom: 0,
- marginRight: 0,
- marginLeft: 0,
- renderConfig: {
- vertexAngle: 0,
- centerAngle: 0
- }
- },
- drawings: {},
- drawingsOrder: []
- };
- function gt() {
- const e = (0, import_react.useRef)(null), n = W0(W), r = W0(He2), t = W0(Pt);
- (0, import_react.useEffect)(() => {
- const o = e.current;
- if (!o)
- return;
- const a = r.register(
- {
- editorUnitId: Hd,
- initialSnapshot: ft,
- scrollBar: true,
- 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(Hd);
- o == null || o.blur(), t.executeCommand(k.id);
- }
- function s() {
- const o = r.getEditor(Hd);
- o == null || o.blur(), t.executeCommand(F.id);
- }
- return p.jsxs("div", { className: v.zenEditor, children: [
- p.jsxs("div", { className: v.zenEditorIconWrapper, children: [
- p.jsx(
- "span",
- {
- className: q(v.zenEditorIconContainer, v.zenEditorIconError),
- onClick: i,
- children: p.jsx(ce, { style: { fontSize: "22px" } })
- }
- ),
- p.jsx(
- "span",
- {
- className: q(v.zenEditorIconContainer, v.zenEditorIconSuccess),
- onClick: s,
- children: p.jsx(se, { style: { fontSize: "22px" } })
- }
- )
- ] }),
- p.jsx("div", { className: v.zenEditorCanvasContainer, ref: e })
- ] });
- }
- function ht(e) {
- return {
- id: B.id,
- type: $e.BUTTON,
- title: "rightClick.zenEditor",
- icon: "AmplifySingle",
- hidden$: bb(e),
- disabled$: ue(e, { workbookTypes: [Me], worksheetTypes: [Te, wn, ar2], rangeTypes: [Pe] })
- };
- }
- var mt = {
- [P1.MAIN_AREA]: {
- [He.OTHERS]: {
- [B.id]: {
- order: 2,
- menuItemFactory: ht
- }
- }
- }
- };
- var _t = {
- id: F.id,
- description: "shortcut.sheet.zen-edit-confirm",
- group: "4_sheet-edit",
- preconditions: (e) => de(e),
- binding: I1.ENTER | Ae.ALT
- };
- var pt = {
- id: k.id,
- description: "shortcut.sheet.zen-edit-cancel",
- group: "4_sheet-edit",
- preconditions: (e) => de(e),
- binding: I1.ESC
- };
- function de(e) {
- return e.getContextValue(Nr) && e.getContextValue(CR) && e.getContextValue(oE) && !e.getContextValue(RR);
- }
- var vt = Object.defineProperty;
- var Et = Object.getOwnPropertyDescriptor;
- var 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;
- };
- var y = (e, n) => (r, t) => n(r, t, e);
- var b = class extends nt {
- 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, u3),
- y(1, Pt),
- y(2, m1),
- y(3, it)
- ], b);
- var It = Object.defineProperty;
- var Ct2 = Object.getOwnPropertyDescriptor;
- var Ot2 = (e, n, r, t) => {
- for (var i = t > 1 ? void 0 : t ? Ct2(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;
- };
- var J = (e, n) => (r, t) => n(r, t, e);
- var T = class extends J0 {
- 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(takeUntil(this.dispose$)).subscribe((e) => {
- if (e == null)
- return;
- const { width: n, height: r } = e, t = Ed(Hd, 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(Xe.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(Hd)) == null ? void 0 : r.with(kn), n = {
- startOffset: 0,
- endOffset: 0
- };
- e && e.scrollToRange(n);
- }
- };
- T = Ot2([
- J(0, W),
- J(1, Yx)
- ], T);
- var yt = Object.defineProperty;
- var Nt = Object.getOwnPropertyDescriptor;
- var 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;
- };
- var K = (e, n) => (r, t) => n(r, t, e);
- var N;
- var X = (N = class extends Ra {
- constructor(e = H, n, r) {
- super(), this._config = e, this._injector = n, this._configService = r;
- const { menu: t, ...i } = nu(
- {},
- H,
- this._config
- );
- t && this._configService.setConfig("menu", t, { merge: true }), this._configService.setConfig(Ge, i), this._initializeDependencies(this._injector);
- }
- _initializeDependencies(e) {
- [
- [b],
- [T],
- [W, { useClass: rt2 }]
- ].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", Fe.UNIVER_SHEET), N);
- X = bt([
- K(1, ot(Ot)),
- K(2, SE)
- ], X);
- export {
- k as CancelZenEditCommand,
- F as ConfirmZenEditCommand,
- B as OpenZenEditorCommand,
- X as UniverSheetsZenEditorPlugin
- };
- /*! Bundled license information:
- @univerjs/sheets-zen-editor/lib/es/index.js:
- (**
- * @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.
- *)
- */
- //# sourceMappingURL=@univerjs_sheets-zen-editor.js.map
|