| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563 |
- var Pt = Object.defineProperty;
- var Tt = (i, e, n) => e in i ? Pt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n;
- var Se = (i, e, n) => Tt(i, typeof e != "symbol" ? e + "" : e, n);
- import { Disposable as Xe, UndoCommand as yt, RedoCommand as bt, IUniverInstanceService as J, ICommandService as z, JSONX as q, PositionedObjectLayoutType as k, CommandType as X, BooleanNumber as re, ObjectRelativeFromH as ee, ObjectRelativeFromV as G, Tools as Pe, TextX as In, TextXActionType as Y, toDisposable as Ae, throttle as xn, COLORS as Mt, MemoryCursor as Rt, IUndoRedoService as $n, BuildTextUtils as Nt, ArrangeTypeEnum as Je, Inject as we, LocaleService as ln, DrawingTypeEnum as Et, WrapTextType as $e, FOCUSING_COMMON_DRAWINGS as tn, IContextService as zn, UniverInstanceType as Te, Direction as ue, useDependency as pe, DocumentFlavor as fn, FOCUSING_UNIVER_EDITOR as At, RxDisposable as jt, SHEET_EDITOR_UNITS as Lt, LifecycleService as Bt, DOCS_ZEN_EDITOR_UNIT_ID_KEY as Ut, fromEventSubject as Ft, LifecycleStages as Pn, DependentOn as kt, Injector as Ht, Plugin as Wt, merge as Gt, IConfigService as Vt } from "@univerjs/core";
- import { IDocDrawingService as je, UniverDocsDrawingPlugin as $t } from "@univerjs/docs-drawing";
- import { IDrawingManagerService as ve, DRAWING_IMAGE_ALLOW_IMAGE_LIST as zt, DRAWING_IMAGE_COUNT_LIMIT as Tn, ImageUploadStatusType as hn, DRAWING_IMAGE_ALLOW_SIZE as qt, getImageSize as Xt, getDrawingShapeKeyByDrawingSearch as Kt, IImageIoService as Yt, DRAWING_IMAGE_WIDTH_LIMIT as yn, DRAWING_IMAGE_HEIGHT_LIMIT as bn, UniverDrawingPlugin as Jt } from "@univerjs/drawing";
- import { DrawingCommonPanel as Zt, ImageCropperObject as Qt, COMPONENT_IMAGE_POPUP_MENU as ei, OpenImageCropOperation as ni, ImageResetSizeOperation as ti, UniverDrawingUIPlugin as ii } from "@univerjs/drawing-ui";
- import { IRenderManagerService as Q, DocumentEditArea as Ue, Liquid as qn, PageLayoutType as Mn, DocumentSkeletonPageType as Rn, Vector2 as ri, Rect as oi, getColor as si, TRANSFORM_CHANGE_OBSERVABLE_TYPE as ai } from "@univerjs/engine-render";
- import { IMessageService as ci, ILocalFileService as di, ISidebarService as li, MenuItemType as Xn, getMenuHiddenObservable as Kn, RibbonStartGroup as gi, KeyCode as Fe, ComponentManager as mi, IMenuManagerService as ui, IShortcutService as fi, UniverUIPlugin as hi } from "@univerjs/ui";
- import { RichTextEditingMutation as Z, DocSkeletonManagerService as oe, DocSelectionManagerService as _n } from "@univerjs/docs";
- import { DocSelectionRenderService as ye, getRichTextEditPath as ze, NodePositionConvertToCursor as Nn, getOneTextSelectionRange as En, getAnchorBounding as pi, TEXT_RANGE_LAYER_INDEX as wi, getDocObject as vi, getCustomBlockIdsInSelections as Ii, docDrawingPositionToTransform as _i, DocCanvasPopManagerService as Si, IEditorService as Ci, SetDocZoomRatioOperation as Di } from "@univerjs/docs-ui";
- import { BehaviorSubject as Oi, debounceTime as Yn, Observable as xi, takeUntil as An, filter as jn } from "rxjs";
- import { MessageType as Ln, InputNumber as Be, Select as Bn, Checkbox as Pi, RadioGroup as Un, Radio as xe } from "@univerjs/design";
- import Ti, { forwardRef as Jn, useRef as yi, createElement as Zn, useState as ie, useEffect as Sn } from "react";
- const bi = "docs-drawing-ui.config", Fn = {};
- var Mi = Object.defineProperty, Ri = Object.getOwnPropertyDescriptor, Ni = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? Ri(e, n) : e, o = i.length - 1, s; o >= 0; o--)
- (s = i[o]) && (r = (t ? s(e, n, r) : s(r)) || r);
- return t && r && Mi(e, n, r), r;
- }, We = (i, e) => (n, t) => e(n, t, i);
- function Ei(i) {
- var t, r, o, s;
- if (q.isNoop(i) || !Array.isArray(i))
- return null;
- const e = i.find((a) => Array.isArray(a) && (a == null ? void 0 : a[0]) === "drawings");
- if (e == null || !Array.isArray(e) || e.length < 3 || typeof e[1] == "string" && typeof e[2] != "object" || Array.isArray(e[1]) && typeof e[1][1] != "object")
- return null;
- const n = [];
- if (Array.isArray(e == null ? void 0 : e[1]))
- for (const a of e)
- Array.isArray(a) && n.push({
- type: (t = a == null ? void 0 : a[1]) != null && t.i ? "add" : "remove",
- drawingId: a == null ? void 0 : a[0],
- drawing: (r = a == null ? void 0 : a[1]) == null ? void 0 : r.i
- });
- else
- n.push({
- type: (o = e[2]) != null && o.i ? "add" : "remove",
- drawingId: e[1],
- drawing: (s = e[2]) == null ? void 0 : s.i
- });
- return n;
- }
- function Ai(i) {
- if (!Array.isArray(i) || i.length < 3 || i[0] !== "drawingsOrder")
- return [];
- const e = [];
- for (let n = 1; n < i.length; n++) {
- const t = i[n];
- if (Array.isArray(t) && typeof t[0] == "number" && typeof t[1] == "object")
- e.push(t[0]);
- else {
- e.length = 0;
- break;
- }
- }
- return e;
- }
- let rn = class extends Xe {
- constructor(i, e, n, t, r) {
- super(), this._univerInstanceService = i, this._commandService = e, this._drawingManagerService = n, this._docDrawingService = t, this._renderManagerService = r, this._initialize();
- }
- _initialize() {
- this._commandExecutedListener();
- }
- _commandExecutedListener() {
- this.disposeWithMe(
- this._commandService.beforeCommandExecuted((i) => {
- if (i.id !== Z.id)
- return;
- const e = i.params, { unitId: n, actions: t } = e, r = Ei(t);
- if (r != null)
- for (const { type: o, drawingId: s, drawing: a } of r)
- o === "add" ? this._addDrawings(n, [a]) : this._removeDrawings(n, [s]);
- })
- ), this.disposeWithMe(
- this._commandService.onCommandExecuted((i) => {
- if (i.id !== Z.id)
- return;
- const e = i.params, { unitId: n, actions: t } = e;
- Ai(t).length > 0 && this._updateDrawingsOrder(n);
- })
- ), this.disposeWithMe(
- this._commandService.onCommandExecuted((i) => {
- var s;
- if (i.id !== yt.id && i.id !== bt.id)
- return;
- const e = (s = this._univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : s.getUnitId(), n = this._drawingManagerService.getFocusDrawings();
- if (e == null || n.length === 0)
- return;
- const t = this._renderManagerService.getRenderById(e), r = t == null ? void 0 : t.scene;
- if (r == null)
- return !1;
- r.getTransformerByCreate().refreshControls();
- })
- );
- }
- _addDrawings(i, e) {
- const n = this._drawingManagerService, t = this._docDrawingService, r = this._docDrawingService.getBatchAddOp(e), { subUnitId: o, redo: s, objects: a } = r;
- n.applyJson1(i, o, s), t.applyJson1(i, o, s), n.addNotification(a), t.addNotification(a);
- }
- _removeDrawings(i, e) {
- const n = this._drawingManagerService, t = this._docDrawingService, r = this._docDrawingService.getBatchRemoveOp(e.map((d) => ({
- unitId: i,
- subUnitId: i,
- drawingId: d
- }))), { subUnitId: o, redo: s, objects: a } = r;
- n.applyJson1(i, o, s), t.applyJson1(i, o, s), n.removeNotification(a), t.removeNotification(a);
- }
- _updateDrawingsOrder(i) {
- const e = this._univerInstanceService.getUniverDocInstance(i);
- if (e == null)
- return;
- const n = e.getSnapshot().drawingsOrder;
- if (n == null)
- return;
- const t = this._drawingManagerService, r = this._docDrawingService;
- t.setDrawingOrder(i, i, n), r.setDrawingOrder(i, i, n);
- const o = {
- unitId: i,
- subUnitId: i,
- drawingIds: n
- };
- t.orderNotification(o), r.orderNotification(o);
- }
- };
- rn = Ni([
- We(0, J),
- We(1, z),
- We(2, ve),
- We(3, je),
- We(4, Q)
- ], rn);
- class gn {
- constructor() {
- Se(this, "_refreshDrawings$", new Oi(null));
- Se(this, "refreshDrawings$", this._refreshDrawings$.asObservable());
- }
- refreshDrawings(e) {
- this._refreshDrawings$.next(e);
- }
- }
- var me = /* @__PURE__ */ ((i) => (i.INLINE = "inline", i.BEHIND_TEXT = "behindText", i.IN_FRONT_OF_TEXT = "inFrontOfText", i.WRAP_SQUARE = "wrapSquare", i.WRAP_TOP_AND_BOTTOM = "wrapTopAndBottom", i))(me || {});
- const ji = {
- inline: k.INLINE,
- wrapSquare: k.WRAP_SQUARE,
- wrapTopAndBottom: k.WRAP_TOP_AND_BOTTOM,
- inFrontOfText: k.WRAP_NONE,
- behindText: k.WRAP_NONE
- };
- function Qn(i, e, n, t, r, o, s) {
- var p, h;
- const a = new In(), d = q.getInstance(), c = [], l = o.getSelfOrHeaderFooterModel(e).getBody(), u = o.getSelfOrHeaderFooterModel(i).getBody();
- if (l == null || u == null)
- return;
- const m = (h = (p = l.customBlocks) == null ? void 0 : p.find((v) => v.blockId === r)) == null ? void 0 : h.startIndex;
- if (m != null) {
- if (t = Math.min(u.dataStream.length - 2, t), i === e) {
- if (t < m ? (t > 0 && a.push({
- t: Y.RETAIN,
- len: t
- }), a.push({
- t: Y.INSERT,
- body: {
- dataStream: "\b",
- customBlocks: [{
- startIndex: 0,
- blockId: r
- }]
- },
- len: 1
- }), a.push({
- t: Y.RETAIN,
- len: m - t
- }), a.push({
- t: Y.DELETE,
- len: 1
- })) : (m > 0 && a.push({
- t: Y.RETAIN,
- len: m
- }), a.push({
- t: Y.DELETE,
- len: 1
- }), t - m - 1 > 0 && a.push({
- t: Y.RETAIN,
- len: t - m - 1
- }), a.push({
- t: Y.INSERT,
- body: {
- dataStream: "\b",
- customBlocks: [{
- startIndex: 0,
- blockId: r
- }]
- },
- len: 1
- })), t !== m) {
- const v = ze(o, e), w = d.editOp(a.serialize(), v);
- c.push(w);
- }
- } else {
- m > 0 && a.push({
- t: Y.RETAIN,
- len: m
- }), a.push({
- t: Y.DELETE,
- len: 1
- });
- let v = ze(o, e), w = d.editOp(a.serialize(), v);
- c.push(w), a.empty(), t > 0 && a.push({
- t: Y.RETAIN,
- len: t
- }), a.push({
- t: Y.INSERT,
- body: {
- dataStream: "\b",
- customBlocks: [{
- startIndex: 0,
- blockId: r
- }]
- },
- len: 1
- }), v = ze(o, i), w = d.editOp(a.serialize(), v), c.push(w), s.setSegment(i), s.setSegmentPage(n);
- }
- return c;
- }
- }
- const et = {
- id: "doc.command.update-doc-drawing-wrapping-style",
- type: X.COMMAND,
- // eslint-disable-next-line max-lines-per-function, complexity
- handler: (i, e) => {
- var N, B;
- if (e == null)
- return !1;
- const { drawings: n, wrappingStyle: t, unitId: r } = e, o = i.get(z), s = i.get(J), d = i.get(Q).getRenderById(r), c = d == null ? void 0 : d.with(oe).getSkeleton().getSkeletonData(), l = d == null ? void 0 : d.with(oe).getViewModel(), u = d == null ? void 0 : d.scene, m = s.getCurrentUniverDocInstance();
- if (m == null || c == null || u == null || l == null)
- return !1;
- const p = l.getEditArea(), h = u.getTransformerByCreate(), { pages: v, skeHeaders: w, skeFooters: S } = c, O = q.getInstance(), D = [], { drawings: x = {} } = m.getSnapshot();
- for (const R of n) {
- const { drawingId: I } = R, j = x[I].layoutType, H = ji[t];
- if (j !== H) {
- const C = O.replaceOp(["drawings", I, "layoutType"], j, H);
- D.push(C);
- }
- if (t === "behindText" || t === "inFrontOfText") {
- const C = x[I].behindDoc, M = t === "behindText" ? re.TRUE : re.FALSE;
- if (C !== M) {
- const P = O.replaceOp(["drawings", I, "behindDoc"], C, M);
- D.push(P);
- }
- }
- if (t === "inline")
- continue;
- let A = null, W = 0, _ = 0;
- for (const C of v) {
- const { headerId: M, footerId: P, marginTop: L, marginLeft: U, marginBottom: y, pageWidth: E, pageHeight: $ } = C;
- switch (p) {
- case Ue.HEADER: {
- const F = (N = w.get(M)) == null ? void 0 : N.get(E);
- F != null && F.skeDrawings.has(I) && (A = F.skeDrawings.get(I), W = F.marginTop, _ = U);
- break;
- }
- case Ue.FOOTER: {
- const F = (B = S.get(P)) == null ? void 0 : B.get(E);
- F != null && F.skeDrawings.has(I) && (A = F.skeDrawings.get(I), W = $ - y + F.marginTop, _ = U);
- break;
- }
- case Ue.BODY: {
- C.skeDrawings.has(I) && (A = C.skeDrawings.get(I), W = L, _ = U);
- break;
- }
- }
- if (A != null)
- break;
- }
- if (A != null) {
- const { aTop: C, aLeft: M } = A, P = x[I].docTransform.positionH;
- let L = M;
- P.relativeFrom === ee.MARGIN ? L -= _ : P.relativeFrom === ee.COLUMN && (L -= A.columnLeft);
- const U = {
- relativeFrom: P.relativeFrom,
- posOffset: L
- };
- if (P.posOffset !== U.posOffset) {
- const F = O.replaceOp(["drawings", I, "docTransform", "positionH"], P, U);
- D.push(F);
- }
- const y = x[I].docTransform.positionV;
- let E = C;
- y.relativeFrom === G.PAGE ? E += W : y.relativeFrom === G.LINE ? E -= A.lineTop : y.relativeFrom === G.PARAGRAPH && (E -= A.blockAnchorTop);
- const $ = {
- relativeFrom: y.relativeFrom,
- posOffset: E
- };
- if (y.posOffset !== $.posOffset) {
- const F = O.replaceOp(["drawings", I, "docTransform", "positionV"], y, $);
- D.push(F);
- }
- }
- }
- const b = {
- id: Z.id,
- params: {
- unitId: r,
- actions: [],
- textRanges: null
- }
- };
- b.params.actions = D.reduce((R, I) => q.compose(R, I), null);
- const T = o.syncExecuteCommand(b.id, b.params);
- return h.refreshControls(), !!T;
- }
- }, nt = {
- id: "doc.command.update-doc-drawing-distance",
- type: X.COMMAND,
- handler: (i, e) => {
- if (e == null)
- return !1;
- const n = i.get(z), r = i.get(J).getCurrentUniverDocInstance();
- if (r == null)
- return !1;
- const { drawings: o, dist: s, unitId: a } = e, d = q.getInstance(), c = [], { drawings: l = {} } = r.getSnapshot();
- for (const p of o) {
- const { drawingId: h } = p;
- for (const [v, w] of Object.entries(s)) {
- const S = l[h][v];
- if (S !== w) {
- const O = d.replaceOp(["drawings", h, v], S, w);
- c.push(O);
- }
- }
- }
- const u = {
- id: Z.id,
- params: {
- unitId: a,
- actions: [],
- textRanges: null
- }
- };
- return u.params.actions = c.reduce((p, h) => q.compose(p, h), null), !!n.syncExecuteCommand(u.id, u.params);
- }
- }, tt = {
- id: "doc.command.update-doc-drawing-wrap-text",
- type: X.COMMAND,
- handler: (i, e) => {
- if (e == null)
- return !1;
- const n = i.get(z), r = i.get(J).getCurrentUniverDocInstance();
- if (r == null)
- return !1;
- const { drawings: o, wrapText: s, unitId: a } = e, d = q.getInstance(), c = [], { drawings: l = {} } = r.getSnapshot();
- for (const p of o) {
- const { drawingId: h } = p, v = l[h].wrapText;
- if (v !== s) {
- const w = d.replaceOp(["drawings", h, "wrapText"], v, s);
- c.push(w);
- }
- }
- const u = {
- id: Z.id,
- params: {
- unitId: a,
- actions: [],
- textRanges: null
- }
- };
- return u.params.actions = c.reduce((p, h) => q.compose(p, h), null), !!n.syncExecuteCommand(u.id, u.params);
- }
- }, qe = {
- id: "doc.command.update-drawing-doc-transform",
- type: X.COMMAND,
- handler: (i, e) => {
- if (e == null)
- return !1;
- const n = i.get(z), t = i.get(J), o = i.get(Q).getRenderById(e.unitId), s = o == null ? void 0 : o.scene;
- if (s == null)
- return !1;
- const a = s.getTransformerByCreate(), d = t.getCurrentUniverDocInstance();
- if (d == null)
- return !1;
- const { drawings: c, unitId: l } = e, u = q.getInstance(), m = [], { drawings: p = {} } = d.getSnapshot();
- for (const w of c) {
- const { drawingId: S, key: O, value: D } = w, x = p[S].docTransform[O];
- if (!Pe.diffValue(x, D)) {
- const b = u.replaceOp(["drawings", S, "docTransform", O], x, D);
- m.push(b);
- }
- }
- const h = {
- id: Z.id,
- params: {
- unitId: l,
- actions: [],
- textRanges: null,
- debounce: !0
- }
- };
- h.params.actions = m.reduce((w, S) => q.compose(w, S), null);
- const v = n.syncExecuteCommand(h.id, h.params);
- return a.refreshControls(), !!v;
- }
- }, it = {
- id: "doc.command.move-inline-drawing",
- type: X.COMMAND,
- handler: (i, e) => {
- var B, R;
- if (e == null)
- return !1;
- const n = i.get(Q), t = (B = n.getRenderById(e.unitId)) == null ? void 0 : B.with(ye), r = i.get(gn), o = n.getRenderById(e.unitId), s = o == null ? void 0 : o.scene, a = o == null ? void 0 : o.with(oe).getSkeleton();
- if (s == null || t == null)
- return !1;
- const d = s.getTransformerByCreate(), c = i.get(z), u = i.get(J).getCurrentUniverDocInstance();
- if (u == null)
- return !1;
- const { drawing: m, unitId: p, offset: h, segmentId: v, segmentPage: w, needRefreshDrawings: S } = e;
- if (S)
- return r.refreshDrawings(a), d.refreshControls(), !0;
- const O = [], { drawingId: D } = m, x = (R = t.getSegment()) != null ? R : "", b = Qn(
- v,
- x,
- w,
- h,
- D,
- u,
- t
- );
- if (b == null || b.length === 0)
- return r.refreshDrawings(a), d.refreshControls(), !1;
- O.push(...b);
- const T = {
- id: Z.id,
- params: {
- unitId: p,
- actions: [],
- textRanges: null
- }
- };
- T.params.actions = O.reduce((I, j) => q.compose(I, j), null);
- const N = c.syncExecuteCommand(T.id, T.params);
- return d.refreshControls(), !!N;
- }
- }, rt = {
- id: "doc.command.transform-non-inline-drawing",
- type: X.COMMAND,
- // eslint-disable-next-line max-lines-per-function
- handler: (i, e) => {
- var A, W;
- if (e == null)
- return !1;
- const n = i.get(Q), t = (A = n.getRenderById(e.unitId)) == null ? void 0 : A.with(ye), r = n.getRenderById(e.unitId), o = r == null ? void 0 : r.scene;
- if (o == null || t == null)
- return !1;
- const s = o.getTransformerByCreate(), a = i.get(z), c = i.get(J).getCurrentUniverDocInstance();
- if (c == null)
- return !1;
- const { drawing: l, unitId: u, offset: m, docTransform: p, segmentId: h, segmentPage: v } = e, w = [], { drawingId: S } = l, O = (W = t.getSegment()) != null ? W : "", D = Qn(
- h,
- O,
- v,
- m,
- S,
- c,
- t
- );
- if (D == null)
- return !1;
- D.length > 0 && w.push(...D);
- const x = q.getInstance(), { drawings: b = {} } = c.getSnapshot(), T = b[S].docTransform, { positionH: N, positionV: B, size: R, angle: I } = T;
- if (!Pe.diffValue(N, p.positionH)) {
- const _ = x.replaceOp(["drawings", S, "docTransform", "positionH"], N, p.positionH);
- w.push(_);
- }
- if (!Pe.diffValue(B, p.positionV)) {
- const _ = x.replaceOp(["drawings", S, "docTransform", "positionV"], B, p.positionV);
- w.push(_);
- }
- if (!Pe.diffValue(R, p.size)) {
- const _ = x.replaceOp(["drawings", S, "docTransform", "size"], R, p.size);
- w.push(_);
- }
- if (!Pe.diffValue(I, p.angle)) {
- const _ = x.replaceOp(["drawings", S, "docTransform", "angle"], I, p.angle);
- w.push(_);
- }
- const j = {
- id: Z.id,
- params: {
- unitId: u,
- actions: [],
- textRanges: null,
- debounce: !0
- }
- };
- j.params.actions = w.reduce((_, C) => q.compose(_, C), null);
- const H = a.syncExecuteCommand(j.id, j.params);
- return s.refreshControls(), !!H;
- }
- };
- var Li = Object.defineProperty, Bi = Object.getOwnPropertyDescriptor, Ui = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? Bi(e, n) : e, o = i.length - 1, s; o >= 0; o--)
- (s = i[o]) && (r = (t ? s(e, n, r) : s(r)) || r);
- return t && r && Li(e, n, r), r;
- }, Ze = (i, e) => (n, t) => e(n, t, i);
- const Fi = "__InlineDrawingAnchor__";
- function kn(i) {
- const { path: e } = i;
- return e.some((n) => n === "cells");
- }
- let on = class extends Xe {
- constructor(e, n, t, r) {
- super();
- Se(this, "_liquid", new qn());
- Se(this, "_listenerOnImageMap", /* @__PURE__ */ new Set());
- // Use to cache the drawings is under transforming or scaling.
- Se(this, "_transformerCache", /* @__PURE__ */ new Map());
- Se(this, "_anchorShape");
- this._commandService = e, this._univerInstanceService = n, this._drawingManagerService = t, this._renderManagerService = r, this._init();
- }
- _init() {
- this._listenDrawingFocus();
- }
- _listenDrawingFocus() {
- this.disposeWithMe(
- this._drawingManagerService.add$.subscribe((e) => {
- if (e.length !== 0)
- for (const n of e) {
- const { unitId: t } = n;
- this._listenerOnImageMap.has(t) || (this._listenTransformerChange(t), this._listenerOnImageMap.add(t));
- }
- })
- );
- }
- // Only handle one drawing transformer change.
- // eslint-disable-next-line max-lines-per-function
- _listenTransformerChange(e) {
- var r;
- const n = (r = this._getSceneAndTransformerByDrawingSearch(e)) == null ? void 0 : r.transformer;
- if (n == null)
- return;
- this.disposeWithMe(
- Ae(
- n.changeStart$.subscribe((o) => {
- var a;
- this._transformerCache.clear();
- const { objects: s } = o;
- for (const d of s.values()) {
- const { oKey: c, width: l, height: u, left: m, top: p, angle: h } = d, v = this._drawingManagerService.getDrawingOKey(c);
- if (v == null)
- continue;
- const w = this._univerInstanceService.getUniverDocInstance(v.unitId), S = (a = w == null ? void 0 : w.getSnapshot().drawings) == null ? void 0 : a[v.drawingId];
- (S == null ? void 0 : S.layoutType) === k.INLINE && d.setOpacity(0.2), S != null && this._transformerCache.set(v.drawingId, {
- drawing: S,
- top: p,
- left: m,
- width: l,
- height: u,
- angle: h
- });
- }
- })
- )
- );
- const t = xn(this._updateMultipleDrawingDocTransform.bind(this), 50);
- xn(this._nonInlineDrawingTransform.bind(this), 50), this.disposeWithMe(
- Ae(
- n.changing$.subscribe((o) => {
- const { objects: s, offsetX: a, offsetY: d } = o;
- if (s.size > 1)
- t(s);
- else if (s.size === 1) {
- const c = this._transformerCache.values().next().value, l = s.values().next().value, { width: u, height: m, top: p, left: h, angle: v } = l;
- if (c && u === c.width && m === c.height && p === c.top && h === c.left && v === c.angle)
- return;
- c && (c.drawing.layoutType, k.INLINE), c && c.drawing.layoutType === k.INLINE && a != null && d != null && this._updateInlineDrawingAnchor(c.drawing, a, d);
- }
- })
- )
- ), this.disposeWithMe(
- Ae(
- // eslint-disable-next-line complexity
- n.changeEnd$.subscribe((o) => {
- const { objects: s, offsetX: a, offsetY: d } = o;
- for (const c of s.values()) {
- const l = this._drawingManagerService.getDrawingOKey(c.oKey);
- if (l == null)
- continue;
- const u = this._transformerCache.get(l == null ? void 0 : l.drawingId);
- (u == null ? void 0 : u.drawing.layoutType) === k.INLINE && c.setOpacity(1);
- }
- if (this._anchorShape && this._anchorShape.hide(), s.size > 1)
- this._updateMultipleDrawingDocTransform(s);
- else if (s.size === 1) {
- const c = this._transformerCache.values().next().value, l = s.values().next().value, { width: u, height: m, top: p, left: h, angle: v } = l;
- if (c && u === c.width && m === c.height && p === c.top && h === c.left && v === c.angle)
- return;
- c && c.drawing.layoutType === k.INLINE ? u !== c.width || m !== c.height || v !== c.angle ? this._updateDrawingSize(c, l) : a != null && d != null && this._moveInlineDrawing(c.drawing, a, d) : c && this._nonInlineDrawingTransform(c.drawing, l);
- }
- this._transformerCache.clear();
- })
- )
- );
- }
- // eslint-disable-next-line max-lines-per-function
- _updateMultipleDrawingDocTransform(e) {
- if (e.size < 1)
- return;
- const n = [];
- let t, r;
- for (const o of e.values()) {
- const { oKey: s, left: a, top: d, angle: c } = o;
- let { width: l, height: u } = o;
- const m = this._drawingManagerService.getDrawingOKey(s);
- if (m == null)
- continue;
- t == null && (t = m.unitId), r == null && (r = m.subUnitId);
- const p = this._transformerCache.get(m.drawingId);
- if (p == null)
- continue;
- const { drawing: h, top: v, left: w, width: S, height: O, angle: D } = p, { width: x, height: b } = this._getPageContentSize(h);
- if (l = Math.min(l, x), u = Math.min(u, b), (S !== l || O !== u) && n.push({
- drawingId: m.drawingId,
- key: "size",
- value: {
- width: l,
- height: u
- }
- }), D !== c && n.push({
- drawingId: m.drawingId,
- key: "angle",
- value: c
- }), v !== d || w !== a) {
- const T = d - v, N = a - w;
- T !== 0 && n.push({
- drawingId: m.drawingId,
- key: "positionV",
- value: {
- relativeFrom: h.docTransform.positionV.relativeFrom,
- posOffset: h.docTransform.positionV.posOffset + T
- }
- }), N !== 0 && n.push({
- drawingId: m.drawingId,
- key: "positionH",
- value: {
- relativeFrom: h.docTransform.positionH.relativeFrom,
- posOffset: h.docTransform.positionH.posOffset + N
- }
- });
- }
- }
- n.length > 0 && t && r && this._commandService.executeCommand(qe.id, {
- unitId: t,
- subUnitId: r,
- drawings: n
- });
- }
- // TODO: @JOCS, Use to draw and update the drawing anchor.
- _updateDrawingAnchor(e) {
- if (this._transformerCache.size !== 1)
- return;
- const n = this._transformerCache.values().next().value, t = e.values().next().value;
- this._getDrawingAnchor(n.drawing, t);
- }
- _updateInlineDrawingAnchor(e, n, t) {
- var o;
- if (this._transformerCache.size !== 1)
- return;
- const { contentBoxPointGroup: r } = (o = this._getInlineDrawingAnchor(e, n, t)) != null ? o : {};
- r != null && this._createOrUpdateInlineAnchor(e.unitId, r);
- }
- _getInlineDrawingAnchor(e, n, t) {
- var A, W;
- const r = this._renderManagerService.getRenderById(e.unitId), o = r == null ? void 0 : r.with(oe).getSkeleton();
- if (r == null)
- return;
- const { mainComponent: s, scene: a } = r, d = s, c = a.getViewports()[0], {
- pageLayoutType: l = Mn.VERTICAL,
- pageMarginLeft: u,
- pageMarginTop: m
- } = d.getOffsetConfig();
- let p = null, h = !1, v = -1, w = "";
- const S = 0.5, O = this._getTransformCoordForDocumentOffset(d, c, n, t);
- if (O == null)
- return;
- const D = (A = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : A.with(ye);
- if (D == null)
- return;
- const x = o == null ? void 0 : o.findNodeByCoord(
- O,
- l,
- u,
- m,
- {
- strict: !1,
- segmentId: D.getSegment(),
- segmentPage: D.getSegmentPage()
- }
- );
- if (x) {
- const { node: _, ratioX: C, segmentPage: M, segmentId: P } = x;
- h = C < S, p = _, v = M, w = P;
- }
- if (p == null)
- return;
- const b = o == null ? void 0 : o.findPositionByGlyph(p, v), T = this._getDocObject();
- if (b == null || o == null || T == null || kn(b))
- return;
- const N = {
- ...b,
- isBack: h
- }, B = T.document.getOffsetConfig(), R = new Nn(B, o), { cursorList: I, contentBoxPointGroup: j } = R.getRangePointData(N, N), { startOffset: H } = (W = En(I)) != null ? W : {};
- if (H != null)
- return { offset: H, contentBoxPointGroup: j, segmentId: w, segmentPage: v };
- }
- // eslint-disable-next-line max-lines-per-function, complexity
- _getDrawingAnchor(e, n) {
- var Ie, _e, ce, Ce, De, Me, Re, Oe, de, le, Ne;
- const t = this._renderManagerService.getRenderById(e.unitId), r = t == null ? void 0 : t.with(oe).getSkeleton(), o = r == null ? void 0 : r.getSkeletonData();
- if (o == null || t == null)
- return;
- const { pages: s, skeHeaders: a, skeFooters: d } = o, { mainComponent: c, scene: l } = t, u = c, m = l.getViewports()[0], { pageLayoutType: p = Mn.VERTICAL, pageMarginLeft: h, pageMarginTop: v, docsLeft: w, docsTop: S } = u.getOffsetConfig(), { left: O, top: D, angle: x } = n;
- let { width: b, height: T } = n;
- const { positionV: N, positionH: B } = e.docTransform, { width: R, height: I } = this._getPageContentSize(e);
- b = Math.min(b, R), T = Math.min(T, I);
- let j = null, H = "", A = -1;
- const W = !1, _ = {
- ...e.docTransform,
- size: {
- width: b,
- height: T
- },
- angle: x
- }, { x: C, y: M } = l.getViewportScrollXY(m), P = this._getTransformCoordForDocumentOffset(u, m, O - C, D - M);
- if (P == null)
- return;
- const L = (Ie = this._renderManagerService.getRenderById(e.unitId)) == null ? void 0 : Ie.with(ye);
- if (L == null)
- return;
- const U = r == null ? void 0 : r.findNodeByCoord(P, p, h, v, {
- strict: !1,
- segmentId: L.getSegment(),
- segmentPage: L.getSegmentPage()
- });
- if (U) {
- const { node: he, segmentPage: mn, segmentId: un } = U;
- j = he, A = mn, H = un;
- }
- if (j == null)
- return;
- const y = (_e = j.parent) == null ? void 0 : _e.parent, E = y == null ? void 0 : y.parent, $ = (ce = E == null ? void 0 : E.lines.find((he) => he.paragraphIndex === (y == null ? void 0 : y.paragraphIndex) && he.paragraphStart)) != null ? ce : E == null ? void 0 : E.lines[0], F = (Ce = E == null ? void 0 : E.parent) == null ? void 0 : Ce.parent;
- if (y == null || E == null || $ == null || F == null)
- return;
- this._liquid.reset();
- const K = F.type;
- for (const he of s) {
- const { headerId: mn, footerId: un, pageHeight: Dt, pageWidth: Dn, marginLeft: On, marginBottom: Ot } = he, xt = s.indexOf(he);
- if (A > -1 && xt === A) {
- switch (K) {
- case Rn.HEADER: {
- const He = (De = a.get(mn)) == null ? void 0 : De.get(Dn);
- if (He)
- this._liquid.translatePagePadding({
- marginTop: He.marginTop,
- marginLeft: On
- });
- else
- throw new Error("header skeleton not found");
- break;
- }
- case Rn.FOOTER: {
- const He = (Me = d.get(un)) == null ? void 0 : Me.get(Dn);
- if (He)
- this._liquid.translatePagePadding({
- marginTop: Dt - Ot + He.marginTop,
- marginLeft: On
- });
- else
- throw new Error("footer skeleton not found");
- break;
- }
- }
- break;
- }
- if (this._liquid.translatePagePadding(he), he === F)
- break;
- this._liquid.restorePagePadding(he), this._liquid.translatePage(he, p, h, v);
- }
- switch (N.relativeFrom === G.LINE ? j = y.divides[0].glyphGroup[0] : j = (le = (de = (Oe = (Re = $.divides) == null ? void 0 : Re[0]) == null ? void 0 : Oe.glyphGroup) == null ? void 0 : de[0]) != null ? le : j, _.positionH = {
- relativeFrom: B.relativeFrom,
- posOffset: O - this._liquid.x - w
- }, B.relativeFrom) {
- case ee.MARGIN: {
- _.positionH.posOffset = O - this._liquid.x - w - F.marginLeft;
- break;
- }
- case ee.COLUMN: {
- _.positionH.posOffset = O - this._liquid.x - w - E.left;
- break;
- }
- }
- switch (_.positionV = {
- relativeFrom: N.relativeFrom,
- posOffset: D - this._liquid.y - S
- }, N.relativeFrom) {
- case G.PAGE: {
- _.positionV.posOffset = D - this._liquid.y - S - F.marginTop;
- break;
- }
- case G.LINE: {
- _.positionV.posOffset = D - this._liquid.y - S - y.top;
- break;
- }
- case G.PARAGRAPH: {
- _.positionV.posOffset = D - this._liquid.y - S - $.top;
- break;
- }
- }
- if (j == null)
- return;
- const se = r == null ? void 0 : r.findPositionByGlyph(j, A), Le = this._getDocObject();
- if (se == null || r == null || Le == null || kn(se))
- return;
- const be = {
- ...se,
- isBack: W
- }, ke = Le.document.getOffsetConfig(), ae = new Nn(ke, r), { cursorList: ne } = ae.getRangePointData(be, be), { startOffset: te } = (Ne = En(ne)) != null ? Ne : {};
- if (te != null)
- return { offset: te, docTransform: _, segmentId: H, segmentPage: A };
- }
- // Update drawing when use transformer to resize it.
- _updateDrawingSize(e, n) {
- const t = [], { drawing: r, width: o, height: s, angle: a } = e, { unitId: d, subUnitId: c } = r;
- let { width: l, height: u, angle: m } = n;
- const { width: p, height: h } = this._getPageContentSize(r);
- l = Math.min(p, l), u = Math.min(h, u), (l !== o || u !== s) && t.push({
- drawingId: r.drawingId,
- key: "size",
- value: {
- width: l,
- height: u
- }
- }), m !== a && t.push({
- drawingId: r.drawingId,
- key: "angle",
- value: m
- }), t.length > 0 && d && c && this._commandService.executeCommand(qe.id, {
- unitId: d,
- subUnitId: c,
- drawings: t
- });
- }
- // Update inline drawing when use transformer to move it.
- _moveInlineDrawing(e, n, t) {
- const r = this._getInlineDrawingAnchor(e, n, t), { offset: o, segmentId: s, segmentPage: a } = r != null ? r : {};
- return this._commandService.executeCommand(it.id, {
- unitId: e.unitId,
- subUnitId: e.unitId,
- drawing: e,
- offset: o,
- segmentId: s,
- segmentPage: a,
- needRefreshDrawings: o == null
- });
- }
- // Limit the drawing to the page area, mainly in the vertical direction,
- // and the upper and lower limits cannot exceed the page margin area.
- _limitDrawingInPage(e, n) {
- const t = this._renderManagerService.getRenderById(e.unitId), { left: r, top: o, width: s, height: a, angle: d } = n, c = t == null ? void 0 : t.with(oe).getSkeleton(), l = c == null ? void 0 : c.getSkeletonData(), { pages: u } = l != null ? l : {};
- if (l == null || t == null || u == null)
- return {
- left: r,
- top: o,
- width: s,
- height: a,
- angle: d
- };
- const { mainComponent: m } = t, p = m, { top: h, pageLayoutType: v, pageMarginLeft: w, pageMarginTop: S } = p;
- let O = o;
- this._liquid.reset();
- for (const D of u) {
- const { marginBottom: x, pageHeight: b } = D, T = u.indexOf(D), N = u[T + 1];
- if (N == null)
- continue;
- if (Pe.hasIntersectionBetweenTwoRanges(
- o,
- o + a,
- this._liquid.y + h + b - x,
- this._liquid.y + h + b + S + N.marginTop
- )) {
- const R = o + a / 2, I = this._liquid.y + h + b + S / 2;
- R < I ? O = Math.min(o, this._liquid.y + h + b - x - a) : O = Math.max(o, this._liquid.y + h + b + S + N.marginTop);
- }
- this._liquid.translatePage(D, v, w, S);
- }
- return {
- left: r,
- top: O,
- width: s,
- height: a,
- angle: d
- };
- }
- _nonInlineDrawingTransform(e, n, t = !1) {
- const r = e.isMultiTransform === re.TRUE ? n : this._limitDrawingInPage(e, n);
- if (t && r.top !== n.top)
- return;
- const o = this._getDrawingAnchor(e, r), { offset: s, docTransform: a, segmentId: d, segmentPage: c } = o != null ? o : {};
- return s == null || a == null ? this._updateMultipleDrawingDocTransform(/* @__PURE__ */ new Map([[e.drawingId, n]])) : this._commandService.executeCommand(rt.id, {
- unitId: e.unitId,
- subUnitId: e.unitId,
- drawing: e,
- offset: s,
- docTransform: a,
- segmentId: d,
- segmentPage: c
- });
- }
- _getSceneAndTransformerByDrawingSearch(e) {
- if (e == null)
- return;
- const n = this._renderManagerService.getRenderById(e), t = n == null ? void 0 : n.scene;
- if (t == null)
- return;
- const r = t.getTransformerByCreate();
- return { scene: t, transformer: r };
- }
- _getTransformCoordForDocumentOffset(e, n, t, r) {
- const { documentTransform: o } = e.getOffsetConfig(), s = n.transformVector2SceneCoord(ri.FromArray([t, r]));
- if (s)
- return o.clone().invert().applyPoint(s);
- }
- _createOrUpdateInlineAnchor(e, n) {
- const t = this._renderManagerService.getRenderById(e);
- if (t == null)
- return;
- const { mainComponent: r, scene: o } = t, s = r, {
- docsLeft: a,
- docsTop: d
- } = s.getOffsetConfig(), c = pi(n), { left: l, top: u, height: m } = c, p = l + a, h = u + d;
- if (this._anchorShape) {
- this._anchorShape.transformByState({ left: p, top: h, height: m }), this._anchorShape.show();
- return;
- }
- const v = 6, w = new oi(Fi + Pe.generateRandomId(v), {
- left: p,
- top: h,
- height: m,
- strokeWidth: 2,
- stroke: si(Mt.darkGray, 1),
- evented: !1
- });
- this._anchorShape = w, o.addObject(w, wi);
- }
- _getDocObject() {
- return vi(this._univerInstanceService, this._renderManagerService);
- }
- _getPageContentSize(e) {
- const n = this._renderManagerService.getRenderById(e.unitId), t = n == null ? void 0 : n.with(oe).getSkeleton(), r = 500, o = 500, s = t == null ? void 0 : t.getSkeletonData();
- if (s == null || n == null)
- return {
- width: r,
- height: o
- };
- const { pages: a } = s;
- let d = null;
- for (const c of a) {
- const { skeDrawings: l } = c;
- if (l.has(e.drawingId)) {
- d = c;
- break;
- }
- }
- if (d) {
- const { pageWidth: c, pageHeight: l, marginLeft: u, marginBottom: m, marginRight: p, marginTop: h } = d;
- return {
- width: Math.max(r, c - u - p),
- height: Math.max(o, l - h - m)
- };
- } else
- return {
- width: r,
- height: o
- };
- }
- };
- on = Ui([
- Ze(0, z),
- Ze(1, J),
- Ze(2, ve),
- Ze(3, Q)
- ], on);
- var fe = function() {
- return fe = Object.assign || function(i) {
- for (var e, n = 1, t = arguments.length; n < t; n++) {
- e = arguments[n];
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (i[r] = e[r]);
- }
- return i;
- }, fe.apply(this, arguments);
- }, ki = function(i, e) {
- var n = {};
- for (var t in i) Object.prototype.hasOwnProperty.call(i, t) && e.indexOf(t) < 0 && (n[t] = i[t]);
- if (i != null && typeof Object.getOwnPropertySymbols == "function")
- for (var r = 0, t = Object.getOwnPropertySymbols(i); r < t.length; r++)
- e.indexOf(t[r]) < 0 && Object.prototype.propertyIsEnumerable.call(i, t[r]) && (n[t[r]] = i[t[r]]);
- return n;
- }, ot = Jn(function(i, e) {
- var n = i.icon, t = i.id, r = i.className, o = i.extend, s = ki(i, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(t, " ").concat(r || "").trim(), d = yi("_".concat(Gi()));
- return st(n, "".concat(t), { defIds: n.defIds, idSuffix: d.current }, fe({ ref: e, className: a }, s), o);
- });
- function st(i, e, n, t, r) {
- return Zn(i.tag, fe(fe({ key: e }, Hi(i, n, r)), t), (Wi(i, n).children || []).map(function(o, s) {
- return st(o, "".concat(e, "-").concat(i.tag, "-").concat(s), n, void 0, r);
- }));
- }
- function Hi(i, e, n) {
- var t = fe({}, i.attrs);
- n != null && n.colorChannel1 && t.fill === "colorChannel1" && (t.fill = n.colorChannel1);
- var r = e.defIds;
- return !r || r.length === 0 || (i.tag === "use" && t["xlink:href"] && (t["xlink:href"] = t["xlink:href"] + e.idSuffix), Object.entries(t).forEach(function(o) {
- var s = o[0], a = o[1];
- typeof a == "string" && (t[s] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
- })), t;
- }
- function Wi(i, e) {
- var n, t = e.defIds;
- return !t || t.length === 0 ? i : i.tag === "defs" && (!((n = i.children) === null || n === void 0) && n.length) ? fe(fe({}, i), { children: i.children.map(function(r) {
- return typeof r.attrs.id == "string" && t && t.indexOf(r.attrs.id) > -1 ? fe(fe({}, r), { attrs: fe(fe({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
- }) }) : i;
- }
- function Gi() {
- return Math.random().toString(36).substring(2, 8);
- }
- ot.displayName = "UniverIcon";
- var Vi = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z" } }] }, at = Jn(function(i, e) {
- return Zn(ot, Object.assign({}, i, {
- id: "add-image-single",
- ref: e,
- icon: Vi
- }));
- });
- at.displayName = "AddImageSingle";
- const Cn = {
- id: "doc.command.remove-doc-image",
- type: X.COMMAND,
- // eslint-disable-next-line max-lines-per-function
- handler: (i, e) => {
- var b, T, N, B;
- const n = i.get(z), t = i.get(J), r = i.get(Q), o = t.getCurrentUniverDocInstance();
- if (e == null || o == null)
- return !1;
- const s = r.getRenderById(e.unitId).with(ye), { drawings: a } = e, d = (b = s.getSegment()) != null ? b : "", c = new In(), l = q.getInstance(), u = (N = (T = o.getSelfOrHeaderFooterModel(d).getBody()) == null ? void 0 : T.customBlocks) != null ? N : [], m = a.map((R) => u.find((I) => I.blockId === R.drawingId)).filter((R) => !!R).sort((R, I) => R.startIndex > I.startIndex ? 1 : -1), p = a[0].unitId, h = new Rt();
- h.reset();
- const v = m[0].startIndex, w = [
- {
- startOffset: v,
- endOffset: v
- }
- ], S = {
- id: Z.id,
- params: {
- unitId: p,
- actions: [],
- textRanges: w
- }
- }, O = [];
- for (const R of m) {
- const { startIndex: I } = R;
- I > h.cursor && c.push({
- t: Y.RETAIN,
- len: I - h.cursor
- }), c.push({
- t: Y.DELETE,
- len: 1
- }), h.moveCursorTo(I + 1);
- }
- const D = ze(o, d);
- O.push(l.editOp(c.serialize(), D));
- for (const R of m) {
- const { blockId: I } = R, j = ((B = o.getDrawings()) != null ? B : {})[I], A = o.getDrawingsOrder().indexOf(I), W = l.removeOp(["drawings", I], j), _ = l.removeOp(["drawingsOrder", A], I);
- O.push(W), O.push(_);
- }
- return S.params.actions = O.reduce((R, I) => q.compose(R, I), null), !!n.syncExecuteCommand(S.id, S.params);
- }
- }, ct = {
- id: "doc.command.delete-drawing",
- type: X.COMMAND,
- handler: (i) => {
- const e = i.get(z), t = i.get(je).getFocusDrawings();
- if (t.length === 0)
- return !1;
- const { unitId: r } = t[0], o = t.map((s) => {
- const { unitId: a, subUnitId: d, drawingId: c, drawingType: l } = s;
- return {
- unitId: a,
- subUnitId: d,
- drawingId: c,
- drawingType: l
- };
- });
- return e.executeCommand(Cn.id, {
- unitId: r,
- drawings: o
- });
- }
- }, dt = {
- id: "doc.command.group-doc-image",
- type: X.COMMAND,
- handler: (i, e) => {
- i.get(z), i.get($n);
- const n = i.get(je);
- if (!e) return !1;
- const t = [];
- return e.forEach(({ parent: r, children: o }) => {
- t.push(r.unitId), o.forEach((s) => {
- t.push(s.unitId);
- });
- }), n.getGroupDrawingOp(e), !1;
- }
- }, lt = {
- id: "doc.command.insert-doc-image",
- type: X.COMMAND,
- // eslint-disable-next-line max-lines-per-function
- handler: (i, e) => {
- var T, N, B, R;
- if (e == null)
- return !1;
- const n = i.get(z), t = i.get(_n), r = i.get(J), o = t.getActiveTextRange(), s = r.getCurrentUniverDocInstance();
- if (o == null || s == null)
- return !1;
- const a = s.getUnitId(), { drawings: d } = e, { collapsed: c, startOffset: l, segmentId: u } = o, m = s.getSelfOrHeaderFooterModel(u).getBody();
- if (m == null)
- return !1;
- const p = new In(), h = q.getInstance(), v = [], w = (N = (T = s.getSnapshot().drawingsOrder) == null ? void 0 : T.length) != null ? N : 0;
- let S = 0;
- if (c)
- l > 0 && p.push({
- t: Y.RETAIN,
- len: l
- });
- else {
- const I = Nt.selection.delete([o], m, 0, null, !1);
- p.push(...I);
- const j = Ii(m, [o]), H = (B = s.getDrawings()) != null ? B : {}, A = (R = s.getDrawingsOrder()) != null ? R : [], W = j.sort((_, C) => A.indexOf(_) > A.indexOf(C) ? -1 : A.indexOf(_) < A.indexOf(C) ? 1 : 0);
- if (W.length > 0)
- for (const _ of W) {
- const C = H[_], M = A.indexOf(_);
- if (C == null || M < 0)
- continue;
- const P = h.removeOp(["drawings", _], C), L = h.removeOp(["drawingsOrder", M], _);
- v.push(P), v.push(L), S++;
- }
- }
- p.push({
- t: Y.INSERT,
- body: {
- dataStream: "\b".repeat(d.length),
- customBlocks: d.map((I, j) => ({
- startIndex: j,
- blockId: I.drawingId
- }))
- },
- len: d.length
- });
- const O = ze(s, u), D = h.editOp(p.serialize(), O);
- v.push(D);
- for (const I of d) {
- const { drawingId: j } = I, H = h.insertOp(["drawings", j], I), A = h.insertOp(["drawingsOrder", w - S], j);
- v.push(H), v.push(A);
- }
- const x = {
- id: Z.id,
- params: {
- unitId: a,
- actions: [],
- textRanges: []
- }
- };
- return x.params.actions = v.reduce((I, j) => q.compose(I, j), null), !!n.syncExecuteCommand(x.id, x.params);
- }
- }, gt = {
- id: "doc.command.set-drawing-arrange",
- type: X.COMMAND,
- handler: (i, e) => {
- const n = i.get(z), t = i.get(je);
- if (e == null)
- return !1;
- const { unitId: r, subUnitId: o, drawingIds: s, arrangeType: a } = e, d = { unitId: r, subUnitId: o, drawingIds: s };
- let c;
- if (a === Je.forward ? c = t.getForwardDrawingsOp(d) : a === Je.backward ? c = t.getBackwardDrawingOp(d) : a === Je.front ? c = t.getFrontDrawingsOp(d) : a === Je.back && (c = t.getBackDrawingsOp(d)), c == null)
- return !1;
- const { redo: l } = c;
- if (l == null)
- return !1;
- const u = [];
- let m = Pe.deepClone(l);
- m = m.slice(3), m.unshift("drawingsOrder"), u.push(m);
- const p = {
- id: Z.id,
- params: {
- unitId: r,
- actions: [],
- textRanges: null
- }
- };
- return p.params.actions = u.reduce((v, w) => q.compose(v, w), null), !!n.syncExecuteCommand(p.id, p.params);
- }
- }, mt = {
- id: "doc.command.ungroup-doc-image",
- type: X.COMMAND,
- handler: (i, e) => {
- i.get(z), i.get($n);
- const n = i.get(je);
- if (!e) return !1;
- const t = [];
- return e.forEach(({ parent: r, children: o }) => {
- t.push(r.unitId), o.forEach((s) => {
- t.push(s.unitId);
- });
- }), n.getUngroupDrawingOp(e), !1;
- }
- };
- var $i = Object.defineProperty, zi = Object.getOwnPropertyDescriptor, qi = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? zi(e, n) : e, o = i.length - 1, s; o >= 0; o--)
- (s = i[o]) && (r = (t ? s(e, n, r) : s(r)) || r);
- return t && r && $i(e, n, r), r;
- }, ge = (i, e) => (n, t) => e(n, t, i);
- let sn = class extends Xe {
- constructor(i, e, n, t, r, o, s, a, d, c, l, u, m) {
- super(), this._context = i, this._commandService = e, this._docSelectionManagerService = n, this._renderManagerSrv = t, this._imageIoService = r, this._docDrawingService = o, this._drawingManagerService = s, this._contextService = a, this._messageService = d, this._localeService = c, this._docSelectionRenderService = l, this._docRefreshDrawingsService = u, this._fileOpenerService = m, this._updateOrderListener(), this._groupDrawingListener(), this._focusDrawingListener(), this._transformDrawingListener(), this._editAreaChangeListener();
- }
- async insertDocImage() {
- const i = await this._fileOpenerService.openFile({
- multiple: !0,
- accept: zt.map((n) => `.${n.replace("image/", "")}`).join(",")
- }), e = i.length;
- return e > Tn ? (this._messageService.show({
- type: Ln.Error,
- content: this._localeService.t("update-status.exceedMaxCount", String(Tn))
- }), !1) : e === 0 ? !1 : (await this._insertFloatImages(i), !0);
- }
- // eslint-disable-next-line max-lines-per-function
- async _insertFloatImages(i) {
- let e = [];
- try {
- e = await Promise.all(i.map((r) => this._imageIoService.saveImage(r)));
- } catch (r) {
- const o = r.message;
- let s = "";
- switch (o) {
- case hn.ERROR_EXCEED_SIZE:
- s = this._localeService.t("update-status.exceedMaxSize", String(qt / (1024 * 1024)));
- break;
- case hn.ERROR_IMAGE_TYPE:
- s = this._localeService.t("update-status.invalidImageType");
- break;
- case hn.ERROR_IMAGE:
- s = this._localeService.t("update-status.invalidImage");
- break;
- }
- this._messageService.show({
- type: Ln.Error,
- content: s
- });
- }
- if (e.length === 0)
- return;
- const { unitId: n } = this._context, t = [];
- for (const r of e) {
- if (r == null)
- continue;
- const { imageId: o, imageSourceType: s, source: a, base64Cache: d } = r, { width: c, height: l, image: u } = await Xt(d || "");
- this._imageIoService.addImageSourceCache(o, s, u);
- let m = 1;
- if (c > yn || l > bn) {
- const w = yn / c, S = bn / l;
- m = Math.min(w, S);
- }
- const p = this._getImagePosition(c * m, l * m);
- if (p == null)
- return;
- const h = {
- unitId: n,
- subUnitId: n,
- drawingId: o,
- drawingType: Et.DRAWING_IMAGE,
- imageSourceType: s,
- source: a,
- transform: _i(p),
- docTransform: p,
- behindDoc: re.FALSE,
- title: "",
- description: "",
- layoutType: k.INLINE,
- // Insert inline drawing by default.
- wrapText: $e.BOTH_SIDES,
- distB: 0,
- distL: 0,
- distR: 0,
- distT: 0
- };
- this._isInsertInHeaderFooter() && (h.isMultiTransform = re.TRUE, h.transforms = h.transform ? [h.transform] : null), t.push(h);
- }
- this._commandService.executeCommand(lt.id, {
- unitId: n,
- drawings: t
- });
- }
- _isInsertInHeaderFooter() {
- var t;
- const { unitId: i } = this._context, e = (t = this._renderManagerSrv.getRenderById(i)) == null ? void 0 : t.with(oe).getViewModel(), n = e == null ? void 0 : e.getEditArea();
- return n === Ue.HEADER || n === Ue.FOOTER;
- }
- _getImagePosition(i, e) {
- const n = this._docSelectionRenderService.getActiveTextRange(), t = (n == null ? void 0 : n.getAbsolutePosition()) || {
- left: 0,
- top: 0
- };
- return {
- size: {
- width: i,
- height: e
- },
- positionH: {
- relativeFrom: ee.PAGE,
- posOffset: t.left
- },
- positionV: {
- relativeFrom: G.PARAGRAPH,
- posOffset: 0
- },
- angle: 0
- };
- }
- _updateOrderListener() {
- this._drawingManagerService.featurePluginOrderUpdate$.subscribe((i) => {
- const { unitId: e, subUnitId: n, drawingIds: t, arrangeType: r } = i;
- this._commandService.executeCommand(gt.id, {
- unitId: e,
- subUnitId: n,
- drawingIds: t,
- arrangeType: r
- });
- });
- }
- _groupDrawingListener() {
- this._drawingManagerService.featurePluginGroupUpdate$.subscribe((i) => {
- this._commandService.executeCommand(dt.id, i);
- }), this._drawingManagerService.featurePluginUngroupUpdate$.subscribe((i) => {
- this._commandService.executeCommand(mt.id, i);
- });
- }
- _getCurrentSceneAndTransformer() {
- const { scene: i, mainComponent: e } = this._context;
- if (i == null || e == null)
- return;
- const n = i.getTransformerByCreate(), { docsLeft: t, docsTop: r } = e.getOffsetConfig();
- return { scene: i, transformer: n, docsLeft: t, docsTop: r };
- }
- _transformDrawingListener() {
- const i = this._getCurrentSceneAndTransformer();
- if (i && i.transformer)
- this.disposeWithMe(i.transformer.changeEnd$.pipe(Yn(30)).subscribe((e) => {
- this._docSelectionManagerService.refreshSelection();
- }));
- else
- throw new Error("transformer is not init");
- }
- _focusDrawingListener() {
- this.disposeWithMe(
- this._drawingManagerService.focus$.subscribe((i) => {
- var r;
- const { transformer: e, docsLeft: n, docsTop: t } = (r = this._getCurrentSceneAndTransformer()) != null ? r : {};
- if (i == null || i.length === 0)
- this._contextService.setContextValue(tn, !1), this._docDrawingService.focusDrawing([]), e && e.resetProps({
- zeroTop: 0,
- zeroLeft: 0
- });
- else {
- this._contextService.setContextValue(tn, !0), this._docDrawingService.focusDrawing(i), this._setDrawingSelections(i);
- const o = this._docSelectionRenderService.getSegment(), s = this._findSegmentIdByDrawingId(i[0].drawingId);
- o !== s && this._docSelectionRenderService.setSegment(s), e && e.resetProps({
- zeroTop: t,
- zeroLeft: n
- });
- }
- })
- );
- }
- _findSegmentIdByDrawingId(i) {
- var s, a, d;
- const { unit: e } = this._context, { body: n, headers: t = {}, footers: r = {} } = e.getSnapshot();
- if (((s = n == null ? void 0 : n.customBlocks) != null ? s : []).some((c) => c.blockId === i))
- return "";
- for (const c of Object.keys(t))
- if ((a = t[c].body.customBlocks) != null && a.some((l) => l.blockId === i))
- return c;
- for (const c of Object.keys(r))
- if ((d = r[c].body.customBlocks) != null && d.some((l) => l.blockId === i))
- return c;
- return "";
- }
- // Update drawings edit status and opacity. You can not edit header footer images when you are editing body. and vice verse.
- _updateDrawingsEditStatus() {
- var a;
- const { unit: i, scene: e, unitId: n } = this._context, t = (a = this._renderManagerSrv.getRenderById(n)) == null ? void 0 : a.with(oe).getViewModel();
- if (t == null || i == null)
- return;
- const r = i.getSnapshot(), { drawings: o = {} } = r, s = t.getEditArea() === Ue.BODY;
- for (const d of Object.keys(o)) {
- const c = o[d], l = Kt({ unitId: n, drawingId: c.drawingId, subUnitId: n }), u = e.fuzzyMathObjects(l, !0);
- if (u.length)
- for (const m of u)
- e.detachTransformerFrom(m), m.setOpacity(0.5), (s && c.isMultiTransform !== re.TRUE || !s && c.isMultiTransform === re.TRUE) && (e.attachTransformerTo(m), m.setOpacity(1));
- }
- }
- _editAreaChangeListener() {
- var n;
- const { unitId: i } = this._context, e = (n = this._renderManagerSrv.getRenderById(i)) == null ? void 0 : n.with(oe).getViewModel();
- e != null && (this._updateDrawingsEditStatus(), this.disposeWithMe(
- e.editAreaChange$.subscribe(() => {
- this._updateDrawingsEditStatus();
- })
- ), this._docRefreshDrawingsService.refreshDrawings$.subscribe((t) => {
- t != null && queueMicrotask(() => {
- this._updateDrawingsEditStatus();
- });
- }), this.disposeWithMe(
- this._commandService.onCommandExecuted(async (t) => {
- t.id === Z.id && queueMicrotask(() => {
- this._updateDrawingsEditStatus();
- });
- })
- ));
- }
- _setDrawingSelections(i) {
- var r, o;
- const { unit: e } = this._context, n = (o = (r = e.getSnapshot().body) == null ? void 0 : r.customBlocks) != null ? o : [], t = i.map((s) => {
- const a = s.drawingId, d = n.find((c) => c.blockId === a);
- return d ? d.startIndex : null;
- }).filter((s) => s !== null).map((s) => ({ startOffset: s, endOffset: s + 1 }));
- this._docSelectionManagerService.replaceDocRanges(t);
- }
- };
- sn = qi([
- ge(1, z),
- ge(2, we(_n)),
- ge(3, Q),
- ge(4, Yt),
- ge(5, je),
- ge(6, ve),
- ge(7, zn),
- ge(8, ci),
- ge(9, we(ln)),
- ge(10, we(ye)),
- ge(11, we(gn)),
- ge(12, di)
- ], sn);
- const ut = {
- id: "doc.command.insert-float-image",
- type: X.COMMAND,
- handler: (i) => {
- var n, t;
- return (t = (n = i.get(Q).getCurrentTypeOfRenderer(Te.UNIVER_DOC)) == null ? void 0 : n.with(sn).insertDocImage()) != null ? t : !1;
- }
- }, Ke = {
- id: "doc.command.move-drawing",
- type: X.COMMAND,
- handler: (i, e) => {
- const n = i.get(z), t = i.get(je), r = i.get(J), o = i.get(Q), { direction: s } = e, a = t.getFocusDrawings();
- if (a.length === 0)
- return !1;
- const d = a[0].unitId, c = o.getRenderById(d), l = c == null ? void 0 : c.scene;
- if (l == null)
- return !1;
- const u = l.getTransformerByCreate(), m = r.getUniverDocInstance(d), p = a.map((v) => {
- var T, N, B, R, I;
- const { drawingId: w } = v, S = (T = m == null ? void 0 : m.getSnapshot().drawings) == null ? void 0 : T[w];
- if (S == null || S.layoutType === k.INLINE)
- return null;
- const { positionH: O, positionV: D } = S.docTransform, x = { ...O }, b = { ...D };
- return s === ue.UP ? b.posOffset = ((N = b.posOffset) != null ? N : 0) - 2 : s === ue.DOWN ? b.posOffset = ((B = b.posOffset) != null ? B : 0) + 2 : s === ue.LEFT ? x.posOffset = ((R = x.posOffset) != null ? R : 0) - 2 : s === ue.RIGHT && (x.posOffset = ((I = x.posOffset) != null ? I : 0) + 2), {
- drawingId: w,
- key: s === ue.UP || s === ue.DOWN ? "positionV" : "positionH",
- value: s === ue.UP || s === ue.DOWN ? b : x
- };
- }).filter((v) => v != null);
- if (p.length === 0)
- return !1;
- const h = n.syncExecuteCommand(qe.id, {
- unitId: d,
- subUnitId: d,
- drawings: p
- });
- return u.refreshControls(), !!h;
- }
- }, Xi = {
- id: "doc.operation.clear-drawing-transformer",
- type: X.MUTATION,
- handler: (i, e) => {
- const n = i.get(Q);
- return e.forEach((t) => {
- var r, o;
- (o = (r = n.getRenderById(t)) == null ? void 0 : r.scene.getTransformer()) == null || o.debounceRefreshControls();
- }), !0;
- }
- }, ft = "COMPONENT_DOC_DRAWING_PANEL", ht = {
- id: "sidebar.operation.doc-image",
- type: X.COMMAND,
- handler: async (i, e) => {
- const n = i.get(li), t = i.get(ln), r = i.get(ve);
- switch (e.value) {
- case "open":
- n.open({
- header: { title: t.t("docImage.panel.title") },
- children: { label: ft },
- onClose: () => {
- r.focusDrawing(null);
- },
- width: 360
- });
- break;
- case "close":
- default:
- n.close();
- break;
- }
- return !0;
- }
- }, pt = {
- id: "doc.operation.edit-doc-image",
- type: X.OPERATION,
- handler: (i, e) => {
- const n = i.get(ve), t = i.get(z);
- return e == null ? !1 : (n.focusDrawing([e]), t.executeCommand(ht.id, { value: "open" }), !0);
- }
- };
- var pn = { exports: {} }, Ge = {};
- /**
- * @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 Hn;
- function Ki() {
- if (Hn) return Ge;
- Hn = 1;
- var i = Ti, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), t = Object.prototype.hasOwnProperty, r = i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, o = { key: !0, ref: !0, __self: !0, __source: !0 };
- function s(a, d, c) {
- var l, u = {}, m = null, p = null;
- c !== void 0 && (m = "" + c), d.key !== void 0 && (m = "" + d.key), d.ref !== void 0 && (p = d.ref);
- for (l in d) t.call(d, l) && !o.hasOwnProperty(l) && (u[l] = d[l]);
- if (a && a.defaultProps) for (l in d = a.defaultProps, d) u[l] === void 0 && (u[l] = d[l]);
- return { $$typeof: e, type: a, key: m, ref: p, props: u, _owner: r.current };
- }
- return Ge.Fragment = n, Ge.jsx = s, Ge.jsxs = s, Ge;
- }
- var Wn;
- function Yi() {
- return Wn || (Wn = 1, pn.exports = Ki()), pn.exports;
- }
- var g = Yi();
- function wt(i) {
- var e, n, t = "";
- if (typeof i == "string" || typeof i == "number") t += i;
- else if (typeof i == "object") if (Array.isArray(i)) {
- var r = i.length;
- for (e = 0; e < r; e++) i[e] && (n = wt(i[e])) && (t && (t += " "), t += n);
- } else for (n in i) i[n] && (t && (t += " "), t += n);
- return t;
- }
- function V() {
- for (var i, e, n = 0, t = "", r = arguments.length; n < r; n++) (i = arguments[n]) && (e = wt(i)) && (t && (t += " "), t += e);
- return t;
- }
- const Ji = "univer-image-common-panel", Zi = "univer-image-common-panel-grid", Qi = "univer-image-common-panel-border", er = "univer-image-common-panel-title", nr = "univer-image-common-panel-subtitle", tr = "univer-image-common-panel-row", ir = "univer-image-common-panel-row-vertical", rr = "univer-image-common-panel-column", or = "univer-image-common-panel-column-center", sr = "univer-image-common-panel-inline", ar = "univer-image-common-panel-span2", cr = "univer-image-common-panel-span3", dr = "univer-image-common-panel-input", lr = "univer-sheet-image-menu", gr = "univer-sheet-image-menu-input", f = {
- imageCommonPanel: Ji,
- imageCommonPanelGrid: Zi,
- imageCommonPanelBorder: Qi,
- imageCommonPanelTitle: er,
- imageCommonPanelSubtitle: nr,
- imageCommonPanelRow: tr,
- imageCommonPanelRowVertical: ir,
- imageCommonPanelColumn: rr,
- imageCommonPanelColumnCenter: or,
- imageCommonPanelInline: sr,
- imageCommonPanelSpan2: ar,
- imageCommonPanelSpan3: cr,
- imageCommonPanelInput: dr,
- sheetImageMenu: lr,
- sheetImageMenuInput: gr
- }, Gn = -1e3, Vn = 1e3, mr = (i) => {
- const e = pe(z), n = pe(ln), t = pe(ve), r = pe(Q), o = pe(J), { drawings: s } = i, a = s[0];
- if (a == null)
- return;
- const { unitId: d } = a, c = o.getUniverDocInstance(d), l = c == null ? void 0 : c.getSnapshot().documentStyle.documentFlavor, u = r.getRenderById(d), m = u == null ? void 0 : u.scene;
- if (m == null)
- return;
- const p = m.getTransformerByCreate(), h = [{
- label: n.t("image-position.column"),
- value: String(ee.COLUMN)
- }, {
- label: n.t("image-position.page"),
- value: String(ee.PAGE)
- }, {
- label: n.t("image-position.margin"),
- value: String(ee.MARGIN)
- }], v = [{
- label: n.t("image-position.line"),
- value: String(G.LINE),
- disabled: l === fn.MODERN
- }, {
- label: n.t("image-position.page"),
- value: String(G.PAGE),
- disabled: l === fn.MODERN
- }, {
- label: n.t("image-position.margin"),
- value: String(G.MARGIN),
- disabled: l === fn.MODERN
- }, {
- label: n.t("image-position.paragraph"),
- value: String(G.PARAGRAPH)
- }], [w, S] = ie(!0), [O, D] = ie({
- relativeFrom: ee.PAGE,
- posOffset: 0
- }), [x, b] = ie({
- relativeFrom: G.PAGE,
- posOffset: 0
- }), [T, N] = ie(!0), [B, R] = ie(!0);
- function I(C, M) {
- var y;
- C === "positionH" ? D(M) : b(M);
- const P = t.getFocusDrawings();
- if (P.length === 0)
- return;
- const L = P.map((E) => ({
- unitId: E.unitId,
- subUnitId: E.subUnitId,
- drawingId: E.drawingId
- }));
- e.executeCommand(qe.id, {
- unitId: P[0].unitId,
- subUnitId: P[0].unitId,
- drawings: L.map((E) => ({
- drawingId: E.drawingId,
- key: C,
- value: M
- }))
- });
- const U = (y = r.getRenderById(d)) == null ? void 0 : y.with(ye);
- U && U.blur(), p.refreshControls();
- }
- function j(C) {
- var te, Ie, _e;
- const M = O.relativeFrom, P = O.posOffset, L = Number(C);
- if (M === L)
- return;
- const U = t.getFocusDrawings();
- if (U.length === 0)
- return;
- const y = U[0].drawingId, E = U[0].unitId;
- let $ = null, F = 0;
- const K = (te = r.getRenderById(E)) == null ? void 0 : te.with(oe).getSkeleton(), se = K == null ? void 0 : K.getSkeletonData();
- if (se == null)
- return;
- const { pages: Le, skeHeaders: be, skeFooters: ke } = se;
- for (const ce of Le) {
- const { marginLeft: Ce, skeDrawings: De, headerId: Me, footerId: Re, pageWidth: Oe } = ce;
- if (De.has(y)) {
- $ = De.get(y), F = Ce;
- break;
- }
- const de = (Ie = be.get(Me)) == null ? void 0 : Ie.get(Oe);
- if (de != null && de.skeDrawings.has(y)) {
- $ = de == null ? void 0 : de.skeDrawings.get(y), F = Ce;
- break;
- }
- const le = (_e = ke.get(Re)) == null ? void 0 : _e.get(Oe);
- if (le != null && le.skeDrawings.has(y)) {
- $ = le == null ? void 0 : le.skeDrawings.get(y), F = Ce;
- break;
- }
- }
- if ($ == null)
- return;
- let ae = 0;
- M === ee.COLUMN ? ae -= $.columnLeft : M === ee.MARGIN && (ae -= F), L === ee.COLUMN ? ae += $.columnLeft : L === ee.MARGIN ? ae += F : ee.PAGE;
- const ne = {
- relativeFrom: L,
- posOffset: (P != null ? P : 0) - ae
- };
- I("positionH", ne);
- }
- function H(C) {
- var De, Me, Re, Oe, de, le;
- const M = x.relativeFrom, P = x.posOffset, L = Number(C);
- if (M === L)
- return;
- const U = t.getFocusDrawings();
- if (U.length === 0)
- return;
- const { drawingId: y, unitId: E } = U[0], $ = o.getUniverDocInstance(E), F = (De = r.getRenderById(E)) == null ? void 0 : De.with(oe).getSkeleton(), K = (Me = r.getRenderById(E)) == null ? void 0 : Me.with(ye), se = K == null ? void 0 : K.getSegment(), Le = K == null ? void 0 : K.getSegmentPage(), be = (Oe = (Re = $ == null ? void 0 : $.getSelfOrHeaderFooterModel(se).getBody()) == null ? void 0 : Re.customBlocks) == null ? void 0 : Oe.find((Ne) => Ne.blockId === y);
- if (be == null || F == null || K == null)
- return;
- const { startIndex: ke } = be, ae = F.findNodeByCharIndex(ke, se, Le), ne = (de = ae == null ? void 0 : ae.parent) == null ? void 0 : de.parent, te = ne == null ? void 0 : ne.parent, Ie = te == null ? void 0 : te.lines.find((Ne) => Ne.paragraphIndex === (ne == null ? void 0 : ne.paragraphIndex) && Ne.paragraphStart), _e = (le = te == null ? void 0 : te.parent) == null ? void 0 : le.parent;
- if (ae == null || ne == null || Ie == null || te == null || _e == null)
- return;
- let ce = 0;
- M === G.PARAGRAPH ? ce -= Ie.top : M === G.LINE ? ce -= ne.top : M === G.PAGE && (ce += _e.marginTop), L === G.PARAGRAPH ? ce += Ie.top : L === G.LINE ? ce += ne.top : L === G.PAGE && (ce -= _e.marginTop);
- const Ce = {
- relativeFrom: L,
- posOffset: (P != null ? P : 0) - ce
- };
- I("positionV", Ce);
- }
- function A(C) {
- var E;
- const M = c == null ? void 0 : c.getSnapshot(), P = (E = M == null ? void 0 : M.drawings) == null ? void 0 : E[C.drawingId];
- if (P == null)
- return;
- const { layoutType: L } = P, {
- positionH: U,
- positionV: y
- } = P.docTransform;
- D(U), b(y), S(L === k.INLINE), N(y.relativeFrom === G.PARAGRAPH || y.relativeFrom === G.LINE);
- }
- function W() {
- const C = t.getFocusDrawings();
- C.length !== 0 && A(C[0]);
- }
- function _(C) {
- N(C), H(String(C ? G.PARAGRAPH : G.PAGE));
- }
- return Sn(() => {
- W();
- const C = t.focus$.subscribe((P) => {
- if (P.length === 0) {
- R(!1);
- return;
- }
- R(!0), A(P[0]);
- }), M = e.onCommandExecuted(async (P) => {
- P.id === Z.id && W();
- });
- return () => {
- C.unsubscribe(), M.dispose();
- };
- }, []), /* @__PURE__ */ g.jsxs("div", { className: V(f.imageCommonPanelGrid, f.imageCommonPanelBorder), style: { display: B ? "block" : "none" }, children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelTitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-position.title") }) }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSubtitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-position.horizontal") }) }) }),
- /* @__PURE__ */ g.jsxs("div", { className: f.imageCommonPanelRow, children: [
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-position.absolutePosition") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Be,
- {
- min: Gn,
- max: Vn,
- precision: 1,
- disabled: w,
- value: O.posOffset,
- onChange: (C) => {
- I("positionH", {
- relativeFrom: O.relativeFrom,
- posOffset: C
- });
- },
- className: f.imageCommonPanelInput
- }
- ) }) })
- ] }) }),
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-position.toTheRightOf") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Bn,
- {
- value: String(O.relativeFrom),
- disabled: w,
- options: h,
- onChange: j
- }
- ) }) })
- ] }) })
- ] }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSubtitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-position.vertical") }) }) }),
- /* @__PURE__ */ g.jsxs("div", { className: f.imageCommonPanelRow, children: [
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-position.absolutePosition") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Be,
- {
- min: Gn,
- max: Vn,
- precision: 1,
- disabled: w,
- value: x.posOffset,
- onChange: (C) => {
- I("positionV", {
- relativeFrom: x.relativeFrom,
- posOffset: C
- });
- },
- className: f.imageCommonPanelInput
- }
- ) }) })
- ] }) }),
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-position.bellow") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Bn,
- {
- disabled: w,
- value: String(x.relativeFrom),
- options: v,
- onChange: H
- }
- ) }) })
- ] }) })
- ] }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSubtitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-position.options") }) }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, style: { marginBottom: "50px" }, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(Pi, { disabled: w, checked: T, onChange: _, children: n.t("image-position.moveObjectWithText") }) }) })
- ] });
- }, Qe = 0, en = 100, ur = (i) => {
- const e = pe(z), n = pe(ln), t = pe(ve), r = pe(Q), o = pe(J), { drawings: s } = i, a = s[0];
- if (a == null)
- return null;
- const { unitId: d } = a, c = o.getUniverDocInstance(d), l = r.getRenderById(d);
- if ((l == null ? void 0 : l.scene) == null)
- return null;
- const [m, p] = ie(!0), [h, v] = ie(!0), [w, S] = ie(!0), [O, D] = ie(me.INLINE), [x, b] = ie(""), [T, N] = ie({
- distT: 0,
- distL: 0,
- distB: 0,
- distR: 0
- }), [B, R] = ie(!0);
- function I(_) {
- D(_);
- const C = t.getFocusDrawings();
- if (C.length === 0)
- return;
- const { unitId: M, subUnitId: P } = C[0], L = C.map(({ unitId: U, subUnitId: y, drawingId: E }) => ({
- unitId: U,
- subUnitId: y,
- drawingId: E
- }));
- e.executeCommand(et.id, {
- unitId: M,
- subUnitId: P,
- drawings: L,
- wrappingStyle: _
- });
- }
- function j(_) {
- b(_);
- const C = t.getFocusDrawings();
- if (C.length === 0)
- return;
- const M = C.map((P) => ({
- unitId: P.unitId,
- subUnitId: P.subUnitId,
- drawingId: P.drawingId
- }));
- e.executeCommand(tt.id, {
- unitId: C[0].unitId,
- subUnitId: C[0].unitId,
- drawings: M,
- wrapText: _
- });
- }
- function H(_, C) {
- if (_ == null)
- return;
- const M = { ...T, [C]: _ };
- N(M);
- const P = t.getFocusDrawings();
- if (P.length === 0)
- return;
- const L = P.map((U) => ({
- unitId: U.unitId,
- subUnitId: U.subUnitId,
- drawingId: U.drawingId
- }));
- e.executeCommand(nt.id, {
- unitId: P[0].unitId,
- subUnitId: P[0].unitId,
- drawings: L,
- dist: {
- [C]: _
- }
- });
- }
- function A() {
- const _ = t.getFocusDrawings();
- _.length !== 0 && W(_[0]);
- }
- function W(_) {
- var K, se;
- const C = (se = (K = c == null ? void 0 : c.getSnapshot()) == null ? void 0 : K.drawings) == null ? void 0 : se[_.drawingId];
- if (C == null)
- return;
- const {
- distT: M = 0,
- distL: P = 0,
- distB: L = 0,
- distR: U = 0,
- layoutType: y = k.INLINE,
- behindDoc: E = re.FALSE,
- wrapText: $ = $e.BOTH_SIDES
- } = C;
- if (N({
- distT: M,
- distL: P,
- distB: L,
- distR: U
- }), b($), p(y !== k.WRAP_SQUARE), y === k.WRAP_NONE || y === k.INLINE ? v(!0) : v(!1), y === k.WRAP_NONE || y === k.INLINE || y === k.WRAP_TOP_AND_BOTTOM ? S(!0) : S(!1), y === k.WRAP_NONE)
- E === re.TRUE ? D(me.BEHIND_TEXT) : D(me.IN_FRONT_OF_TEXT);
- else
- switch (y) {
- case k.INLINE:
- D(me.INLINE);
- break;
- case k.WRAP_SQUARE:
- D(me.WRAP_SQUARE);
- break;
- case k.WRAP_TOP_AND_BOTTOM:
- D(me.WRAP_TOP_AND_BOTTOM);
- break;
- default:
- throw new Error(`Unsupported layout type: ${y}`);
- }
- }
- return Sn(() => {
- A();
- const _ = t.focus$.subscribe((M) => {
- if (M.length === 0) {
- R(!1);
- return;
- }
- R(!0), W(M[0]);
- }), C = e.onCommandExecuted(async (M) => {
- M.id === Z.id && A();
- });
- return () => {
- _.unsubscribe(), C.dispose();
- };
- }, []), /* @__PURE__ */ g.jsxs("div", { className: V(f.imageCommonPanelGrid, f.imageCommonPanelBorder), style: { display: B ? "block" : "none" }, children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelTitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-text-wrap.title") }) }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSubtitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-text-wrap.wrappingStyle") }) }) }),
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelRow), children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn), children: /* @__PURE__ */ g.jsxs(Un, { value: O, onChange: I, direction: "vertical", children: [
- /* @__PURE__ */ g.jsx(xe, { value: me.INLINE, children: n.t("image-text-wrap.inline") }),
- /* @__PURE__ */ g.jsx(xe, { value: me.WRAP_SQUARE, children: n.t("image-text-wrap.square") }),
- /* @__PURE__ */ g.jsx(xe, { value: me.WRAP_TOP_AND_BOTTOM, children: n.t("image-text-wrap.topAndBottom") }),
- /* @__PURE__ */ g.jsx(xe, { value: me.BEHIND_TEXT, children: n.t("image-text-wrap.behindText") }),
- /* @__PURE__ */ g.jsx(xe, { value: me.IN_FRONT_OF_TEXT, children: n.t("image-text-wrap.inFrontText") })
- ] }) }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSubtitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-text-wrap.wrapText") }) }) }),
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelRow), children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn), children: /* @__PURE__ */ g.jsxs(Un, { disabled: m, value: x, onChange: j, direction: "horizontal", children: [
- /* @__PURE__ */ g.jsx(xe, { value: $e.BOTH_SIDES, children: n.t("image-text-wrap.bothSide") }),
- /* @__PURE__ */ g.jsx(xe, { value: $e.LEFT, children: n.t("image-text-wrap.leftOnly") }),
- /* @__PURE__ */ g.jsx(xe, { value: $e.RIGHT, children: n.t("image-text-wrap.rightOnly") })
- ] }) }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSubtitle), children: /* @__PURE__ */ g.jsx("div", { children: n.t("image-text-wrap.distanceFromText") }) }) }),
- /* @__PURE__ */ g.jsxs("div", { className: f.imageCommonPanelRow, children: [
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-text-wrap.top") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Be,
- {
- min: Qe,
- max: en,
- disabled: h,
- precision: 1,
- value: T.distT,
- onChange: (_) => {
- H(_, "distT");
- },
- className: f.imageCommonPanelInput
- }
- ) }) })
- ] }) }),
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-text-wrap.left") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Be,
- {
- min: Qe,
- max: en,
- disabled: w,
- precision: 1,
- value: T.distL,
- onChange: (_) => {
- H(_, "distL");
- },
- className: f.imageCommonPanelInput
- }
- ) }) })
- ] }) })
- ] }),
- /* @__PURE__ */ g.jsxs("div", { className: f.imageCommonPanelRow, children: [
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-text-wrap.bottom") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Be,
- {
- min: Qe,
- max: en,
- disabled: h,
- precision: 1,
- value: T.distB,
- onChange: (_) => {
- H(_, "distB");
- },
- className: f.imageCommonPanelInput
- }
- ) }) })
- ] }) }),
- /* @__PURE__ */ g.jsx("div", { className: V(f.imageCommonPanelColumn, f.imageCommonPanelSpan2), children: /* @__PURE__ */ g.jsxs("label", { children: [
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: n.t("image-text-wrap.right") }) }),
- /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelRow, children: /* @__PURE__ */ g.jsx("div", { className: f.imageCommonPanelColumn, children: /* @__PURE__ */ g.jsx(
- Be,
- {
- min: Qe,
- max: en,
- disabled: w,
- precision: 1,
- value: T.distR,
- onChange: (_) => {
- H(_, "distR");
- },
- className: f.imageCommonPanelInput
- }
- ) }) })
- ] }) })
- ] })
- ] });
- }, fr = () => {
- const i = pe(ve), e = i.getFocusDrawings(), [n, t] = ie(e);
- return Sn(() => {
- const r = i.focus$.subscribe((o) => {
- t(o);
- });
- return () => {
- r.unsubscribe();
- };
- }, []), !!(n != null && n.length) && /* @__PURE__ */ g.jsxs("div", { className: f.imageCommonPanel, children: [
- /* @__PURE__ */ g.jsx(Zt, { drawings: n, hasAlign: !1, hasCropper: !1, hasGroup: !1, hasTransform: !1 }),
- /* @__PURE__ */ g.jsx(ur, { drawings: n }),
- /* @__PURE__ */ g.jsx(mr, { drawings: n })
- ] });
- }, vt = "addition-and-subtraction-single", It = "doc.menu.image", _t = ut.id, hr = (i) => {
- const e = i.get(_n), n = i.get(J);
- return new xi((t) => {
- const r = e.textSelection$.subscribe(() => {
- var s;
- const o = e.getActiveTextRange();
- if (o) {
- const { segmentId: a, startOffset: d, endOffset: c } = o, l = n.getCurrentUniverDocInstance(), u = (s = l == null ? void 0 : l.getSelfOrHeaderFooterModel(a).getBody()) == null ? void 0 : s.tables;
- if (u && u.length && u.some((m) => {
- const { startIndex: p, endIndex: h } = m;
- return d >= p && d < h || c >= p && c < h;
- })) {
- t.next(!0);
- return;
- }
- } else {
- t.next(!0);
- return;
- }
- t.next(!1);
- });
- return () => r.unsubscribe();
- });
- };
- function pr(i) {
- return {
- id: It,
- type: Xn.SUBITEMS,
- icon: vt,
- tooltip: "docImage.title",
- disabled$: hr(i),
- hidden$: Kn(i, Te.UNIVER_DOC)
- };
- }
- function wr(i) {
- return {
- id: _t,
- title: "docImage.upload.float",
- type: Xn.BUTTON,
- hidden$: Kn(i, Te.UNIVER_DOC)
- };
- }
- const vr = {
- [gi.LAYOUT]: {
- [It]: {
- order: 0,
- menuItemFactory: pr,
- [_t]: {
- order: 0,
- menuItemFactory: wr
- }
- }
- }
- };
- function Ye(i) {
- return i.getContextValue(At) && i.getContextValue(tn);
- }
- const Ir = {
- id: Ke.id,
- description: "shortcut.doc.drawing-move-down",
- group: "4_doc-drawing-view",
- binding: Fe.ARROW_DOWN,
- priority: 100,
- preconditions: Ye,
- staticParameters: {
- direction: ue.DOWN
- }
- }, _r = {
- id: Ke.id,
- description: "shortcut.doc.drawing-move-up",
- group: "4_doc-drawing-view",
- binding: Fe.ARROW_UP,
- priority: 100,
- preconditions: Ye,
- staticParameters: {
- direction: ue.UP
- }
- }, Sr = {
- id: Ke.id,
- description: "shortcut.doc.drawing-move-left",
- group: "4_doc-drawing-view",
- binding: Fe.ARROW_LEFT,
- priority: 100,
- preconditions: Ye,
- staticParameters: {
- direction: ue.LEFT
- }
- }, Cr = {
- id: Ke.id,
- description: "shortcut.doc.drawing-move-right",
- group: "4_doc-drawing-view",
- binding: Fe.ARROW_RIGHT,
- priority: 100,
- preconditions: Ye,
- staticParameters: {
- direction: ue.RIGHT
- }
- }, Dr = {
- id: ct.id,
- description: "shortcut.doc.drawing-delete",
- group: "4_doc-drawing-view",
- // when focusing on any other input tag do not trigger this shortcut
- preconditions: Ye,
- binding: Fe.DELETE,
- mac: Fe.BACKSPACE
- };
- var Or = Object.defineProperty, xr = Object.getOwnPropertyDescriptor, Pr = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? xr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
- (s = i[o]) && (r = (t ? s(e, n, r) : s(r)) || r);
- return t && r && Or(e, n, r), r;
- }, nn = (i, e) => (n, t) => e(n, t, i);
- let an = class extends Xe {
- constructor(i, e, n, t) {
- super(), this._componentManager = i, this._menuManagerService = e, this._commandService = n, this._shortcutService = t, this._init();
- }
- _initCustomComponents() {
- const i = this._componentManager;
- this.disposeWithMe(i.register(vt, at)), this.disposeWithMe(i.register(ft, fr));
- }
- _initMenus() {
- this._menuManagerService.mergeMenu(vr);
- }
- _initCommands() {
- [
- ut,
- lt,
- et,
- nt,
- tt,
- qe,
- it,
- rt,
- Cn,
- ht,
- Xi,
- pt,
- dt,
- mt,
- Ke,
- ct,
- gt
- ].forEach((i) => this.disposeWithMe(this._commandService.registerCommand(i)));
- }
- _initShortcuts() {
- [
- // sheet drawing shortcuts
- Ir,
- _r,
- Sr,
- Cr,
- Dr
- ].forEach((i) => {
- this.disposeWithMe(this._shortcutService.registerShortcut(i));
- });
- }
- _init() {
- this._initCommands(), this._initCustomComponents(), this._initMenus(), this._initShortcuts();
- }
- };
- an = Pr([
- nn(0, we(mi)),
- nn(1, ui),
- nn(2, z),
- nn(3, fi)
- ], an);
- var Tr = Object.defineProperty, yr = Object.getOwnPropertyDescriptor, br = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? yr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
- (s = i[o]) && (r = (t ? s(e, n, r) : s(r)) || r);
- return t && r && Tr(e, n, r), r;
- }, Ve = (i, e) => (n, t) => e(n, t, i);
- let cn = class extends jt {
- constructor(e, n, t, r, o) {
- super();
- Se(this, "_initImagePopupMenu", /* @__PURE__ */ new Set());
- this._drawingManagerService = e, this._canvasPopManagerService = n, this._renderManagerService = t, this._univerInstanceService = r, this._contextService = o, this._init();
- }
- _init() {
- this._univerInstanceService.getCurrentTypeOfUnit$(Te.UNIVER_DOC).pipe(An(this.dispose$)).subscribe((e) => this._create(e)), this._univerInstanceService.getTypeOfUnitDisposed$(Te.UNIVER_DOC).pipe(An(this.dispose$)).subscribe((e) => this._dispose(e)), this._univerInstanceService.getAllUnitsForType(Te.UNIVER_DOC).forEach((e) => this._create(e));
- }
- _dispose(e) {
- const n = e.getUnitId();
- this._renderManagerService.removeRender(n);
- }
- _create(e) {
- if (!e)
- return;
- const n = e.getUnitId();
- this._renderManagerService.has(n) && !this._initImagePopupMenu.has(n) && (this._popupMenuListener(n), this._initImagePopupMenu.add(n));
- }
- _hasCropObject(e) {
- const n = e.getAllObjects();
- for (const t of n)
- if (t instanceof Qt)
- return !0;
- return !1;
- }
- // eslint-disable-next-line max-lines-per-function
- _popupMenuListener(e) {
- var o;
- const n = (o = this._renderManagerService.getRenderById(e)) == null ? void 0 : o.scene;
- if (!n)
- return;
- const t = n.getTransformerByCreate();
- if (!t)
- return;
- const r = [];
- this.disposeWithMe(
- Ae(
- t.createControl$.subscribe(() => {
- if (this._hasCropObject(n))
- return;
- const s = t.getSelectedObjectMap();
- if (r.forEach((w) => w.dispose()), r.length = 0, s.size > 1)
- return;
- const a = s.values().next().value;
- if (!a)
- return;
- const d = a.oKey, c = this._drawingManagerService.getDrawingOKey(d);
- if (!c)
- return;
- const { unitId: l, subUnitId: u, drawingId: m } = c, p = this._canvasPopManagerService.attachPopupToObject(
- a,
- {
- componentKey: ei,
- direction: "horizontal",
- offset: [2, 0],
- extraProps: {
- menuItems: this._getImageMenuItems(l, u, m)
- }
- },
- l
- );
- r.push(this.disposeWithMe(p)), !this._drawingManagerService.getFocusDrawings().find((w) => w.unitId === l && w.subUnitId === u && w.drawingId === m) && this._drawingManagerService.focusDrawing([{
- unitId: l,
- subUnitId: u,
- drawingId: m
- }]);
- })
- )
- ), this.disposeWithMe(
- Ae(
- t.clearControl$.subscribe(() => {
- r.forEach((s) => s.dispose()), r.length = 0, this._contextService.setContextValue(tn, !1), this._drawingManagerService.focusDrawing(null);
- })
- )
- ), this.disposeWithMe(
- Ae(
- t.changing$.subscribe(() => {
- r.forEach((s) => s.dispose()), r.length = 0;
- })
- )
- ), this.disposeWithMe(
- Ae(
- t.changeStart$.subscribe(() => {
- r.forEach((s) => s.dispose()), r.length = 0;
- })
- )
- );
- }
- _getImageMenuItems(e, n, t) {
- return [
- {
- label: "image-popup.edit",
- index: 0,
- commandId: pt.id,
- commandParams: { unitId: e, subUnitId: n, drawingId: t },
- disable: !!Lt.includes(e)
- },
- {
- label: "image-popup.delete",
- index: 1,
- commandId: Cn.id,
- commandParams: { unitId: e, drawings: [{ unitId: e, subUnitId: n, drawingId: t }] },
- disable: !1
- },
- {
- label: "image-popup.crop",
- index: 2,
- commandId: ni.id,
- commandParams: { unitId: e, subUnitId: n, drawingId: t },
- disable: !0
- // TODO: @JOCS, feature is not ready.
- },
- {
- label: "image-popup.reset",
- index: 3,
- commandId: ti.id,
- commandParams: [{ unitId: e, subUnitId: n, drawingId: t }],
- disable: !0
- // TODO: @JOCS, feature is not ready.
- }
- ];
- }
- };
- cn = br([
- Ve(0, ve),
- Ve(1, we(Si)),
- Ve(2, Q),
- Ve(3, J),
- Ve(4, zn)
- ], cn);
- var Mr = Object.defineProperty, Rr = Object.getOwnPropertyDescriptor, Nr = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? Rr(e, n) : e, o = i.length - 1, s; o >= 0; o--)
- (s = i[o]) && (r = (t ? s(e, n, r) : s(r)) || r);
- return t && r && Mr(e, n, r), r;
- }, Ee = (i, e) => (n, t) => e(n, t, i);
- let vn = class extends Xe {
- constructor(e, n, t, r, o, s, a, d) {
- super();
- Se(this, "_liquid", new qn());
- this._context = e, this._docSkeletonManagerService = n, this._commandService = t, this._editorService = r, this._drawingManagerService = o, this._docRefreshDrawingsService = s, this._univerInstanceService = a, this._lifecycleService = d, this._initialize(), this._commandExecutedListener();
- }
- _initialize() {
- this._initialRenderRefresh(), this._drawingInitializeListener(), this._initResize();
- }
- _initialRenderRefresh() {
- this._docSkeletonManagerService.currentSkeleton$.subscribe((e) => {
- e != null && this._refreshDrawing(e);
- }), this._docRefreshDrawingsService.refreshDrawings$.subscribe((e) => {
- e != null && this._refreshDrawing(e);
- });
- }
- _commandExecutedListener() {
- const e = [Z.id, Di.id];
- this.disposeWithMe(
- this._commandService.onCommandExecuted((n) => {
- if (e.includes(n.id)) {
- const t = n.params, { unitId: r } = t, { unitId: o, mainComponent: s } = this._context;
- if (r !== o)
- return;
- const a = this._docSkeletonManagerService.getSkeleton();
- if (a == null)
- return;
- if (this._editorService.isEditor(o) && o !== Ut) {
- s == null || s.makeDirty();
- return;
- }
- this._refreshDrawing(a);
- }
- })
- );
- }
- _initResize() {
- this.disposeWithMe(
- Ft(this._context.engine.onTransformChange$).pipe(
- jn((e) => e.type === ai.resize),
- Yn(16)
- ).subscribe(() => {
- var t;
- const e = this._docSkeletonManagerService.getSkeleton(), { scene: n } = this._context;
- (t = n.getTransformer()) == null || t.refreshControls(), this._refreshDrawing(e);
- })
- );
- }
- _refreshDrawing(e) {
- var O, D;
- const n = e == null ? void 0 : e.getSkeletonData(), { mainComponent: t, unitId: r } = this._context, o = t;
- if (!n)
- return;
- const { left: s, top: a, pageLayoutType: d, pageMarginLeft: c, pageMarginTop: l } = o, { pages: u, skeHeaders: m, skeFooters: p } = n, h = {};
- this._liquid.reset();
- for (let x = 0, b = u.length; x < b; x++) {
- const T = u[x], { headerId: N, footerId: B, pageWidth: R } = T;
- if (N) {
- const I = (O = m.get(N)) == null ? void 0 : O.get(R);
- I && this._calculateDrawingPosition(
- r,
- I,
- s,
- a,
- h,
- I.marginTop,
- T.marginLeft
- );
- }
- if (B) {
- const I = (D = p.get(B)) == null ? void 0 : D.get(R);
- I && this._calculateDrawingPosition(
- r,
- I,
- s,
- a,
- h,
- T.pageHeight - T.marginBottom + I.marginTop,
- T.marginLeft
- );
- }
- this._calculateDrawingPosition(r, T, s, a, h, T.marginTop, T.marginLeft), this._liquid.translatePage(T, d, c, l);
- }
- const v = Object.values(h), w = v.filter((x) => !x.isMultiTransform), S = v.filter((x) => x.isMultiTransform);
- w.length > 0 && this._drawingManagerService.refreshTransform(w), this._handleMultiDrawingsTransform(S);
- }
- _handleMultiDrawingsTransform(e) {
- const { scene: n, unitId: t } = this._context, r = n.getTransformerByCreate();
- e.forEach((d) => {
- const c = this._drawingManagerService.getDrawingByParam(d);
- c != null && (c.transform = d.transform, c.transforms = d.transforms, c.isMultiTransform = d.isMultiTransform);
- });
- const s = [...r.getSelectedObjectMap().keys()], a = Object.values(this._drawingManagerService.getDrawingData(t, t)).filter((d) => d.isMultiTransform === re.TRUE);
- this._drawingManagerService.removeNotification(a), e.length > 0 && this._drawingManagerService.addNotification(e);
- for (const d of s) {
- const c = n.getObject(d);
- c && r.setSelectedControl(c);
- }
- }
- _calculateDrawingPosition(e, n, t, r, o, s, a) {
- const { skeDrawings: d } = n;
- this._liquid.translatePagePadding({
- marginTop: s,
- marginLeft: a
- }), d.forEach((c) => {
- const { aLeft: l, aTop: u, height: m, width: p, angle: h, drawingId: v, drawingOrigin: w } = c, S = w.layoutType === k.WRAP_NONE && w.behindDoc === re.TRUE, { isMultiTransform: O = re.FALSE } = w, D = {
- left: l + t + this._liquid.x,
- top: u + r + this._liquid.y,
- width: p,
- height: m,
- angle: h
- };
- o[v] == null ? o[v] = {
- unitId: e,
- subUnitId: e,
- drawingId: v,
- behindText: S,
- transform: D,
- transforms: [D],
- isMultiTransform: O
- } : O === re.TRUE && o[v].transforms.push(D);
- }), this._liquid.restorePagePadding({
- marginTop: s,
- marginLeft: a
- });
- }
- _drawingInitializeListener() {
- const e = () => {
- const n = this._docSkeletonManagerService.getSkeleton();
- n != null && (this._refreshDrawing(n), this._drawingManagerService.initializeNotification(this._context.unitId));
- };
- this._lifecycleService.stage === Pn.Steady ? setTimeout(() => {
- e();
- }, 1e3) : this._lifecycleService.lifecycle$.pipe(jn((n) => n === Pn.Steady)).subscribe(e);
- }
- };
- vn = Nr([
- Ee(1, we(oe)),
- Ee(2, z),
- Ee(3, Ci),
- Ee(4, ve),
- Ee(5, we(gn)),
- Ee(6, J),
- Ee(7, we(Bt))
- ], vn);
- var St = Object.defineProperty, Er = Object.getOwnPropertyDescriptor, Ar = (i, e, n) => e in i ? St(i, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[e] = n, jr = (i, e, n, t) => {
- for (var r = t > 1 ? void 0 : t ? Er(e, n) : e, o = i.length - 1, s; o >= 0; o--)
- (s = i[o]) && (r = (t ? s(e, n, r) : s(r)) || r);
- return t && r && St(e, n, r), r;
- }, wn = (i, e) => (n, t) => e(n, t, i), Ct = (i, e, n) => Ar(i, typeof e != "symbol" ? e + "" : e, n);
- const Lr = "DOC_DRAWING_UI_PLUGIN";
- let dn = class extends Wt {
- constructor(i = Fn, e, n, t) {
- super(), this._config = i, this._injector = e, this._renderManagerSrv = n, this._configService = t;
- const { ...r } = Gt(
- {},
- Fn,
- this._config
- );
- this._configService.setConfig(bi, r);
- }
- onStarting() {
- [
- [an],
- [cn],
- [on],
- [rn],
- [gn]
- ].forEach((e) => this._injector.add(e));
- }
- onReady() {
- [
- [sn],
- [vn]
- ].forEach((i) => this._renderManagerSrv.registerRenderModule(Te.UNIVER_DOC, i)), this._injector.get(rn), this._injector.get(an), this._injector.get(on);
- }
- onRendered() {
- this._injector.get(cn);
- }
- };
- Ct(dn, "type", Te.UNIVER_DOC);
- Ct(dn, "pluginName", Lr);
- dn = jr([
- kt(ii, Jt, $t, hi),
- wn(1, we(Ht)),
- wn(2, Q),
- wn(3, Vt)
- ], dn);
- export {
- Xi as ClearDocDrawingTransformerOperation,
- It as DOCS_IMAGE_MENU_ID,
- ct as DeleteDocDrawingsCommand,
- pt as EditDocDrawingOperation,
- dt as GroupDocDrawingCommand,
- lt as InsertDocDrawingCommand,
- ut as InsertDocImageCommand,
- Ke as MoveDocDrawingsCommand,
- Cn as RemoveDocDrawingCommand,
- gt as SetDocDrawingArrangeCommand,
- ht as SidebarDocDrawingOperation,
- mt as UngroupDocDrawingCommand,
- dn as UniverDocsDrawingUIPlugin
- };
|