Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Jun 18, 2024
1 parent a270e80 commit 479d84f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 92 deletions.
4 changes: 3 additions & 1 deletion examples/src/docs/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
import { UniverUIPlugin } from '@univerjs/ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverDebuggerPlugin } from '@univerjs/debugger';
import { UniverDocsDrawingUIPlugin } from '@univerjs/docs-drawing-ui';

import { DEFAULT_DOCUMENT_DATA_CN } from '../data';
import { enUS, ruRU, zhCN } from '../locales';

Expand Down Expand Up @@ -66,7 +68,7 @@ univer.registerPlugin(UniverDocsUIPlugin, {
},
});

// univer.registerPlugin(UniverDocsDrawingUIPlugin);
univer.registerPlugin(UniverDocsDrawingUIPlugin);

univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_CN);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class DocDrawingUpdateController extends Disposable {
drawings: [docDrawingParam],
} as IInsertDrawingCommandParams);

this._docSkeletonManagerService.getCurrent()?.skeleton.calculate();
this._docSkeletonManagerService.getSkeleton()?.calculate();
}

private _getUnitInfo() {
Expand Down Expand Up @@ -275,99 +275,20 @@ export class DocDrawingUpdateController extends Disposable {
});

if (drawings.length > 0) {
const unitId = params[0].unitId;
this._commandService.syncExecuteCommand(SetDocDrawingCommand.id, {
unitId: params[0].unitId,
unitId,
drawings,
} as ISetDrawingCommandParams);

this._refreshDocSkeleton();
this._refreshDocSkeleton(unitId);
}
});
}

private _getDocsOffsetInfo() {
const docsSkeletonObject = this._docSkeletonManagerService.getCurrent();
if (docsSkeletonObject == null) {
return {
pageMarginCache: new Map<string, { marginLeft: number; marginTop: number }>(),
docsLeft: 0,
docsTop: 0,
};
}

const { unitId, skeleton } = docsSkeletonObject;

private _refreshDocSkeleton(unitId: string) {
const skeleton = this._docSkeletonManagerService.getSkeleton();
const currentRender = this._renderManagerService.getRenderById(unitId);

const skeletonData = skeleton?.getSkeletonData();

if (currentRender == null || !skeletonData) {
return {
pageMarginCache: new Map<string, { marginLeft: number; marginTop: number }>(),
docsLeft: 0,
docsTop: 0,
};
}

const { mainComponent } = currentRender;

const documentComponent = mainComponent as Documents;

const { left: docsLeft, top: docsTop, pageLayoutType, pageMarginLeft, pageMarginTop } = documentComponent;

const { pages } = skeletonData;

const liquid = new Liquid();

const pageMarginCache = new Map<string, { marginLeft: number; marginTop: number }>();

for (let i = 0, len = pages.length; i < len; i++) {
const page = pages[i];
const { skeDrawings, marginLeft, marginTop } = page;
// cumPageLeft + = pageWidth + documents.pageMarginLeft;

liquid.translatePagePadding(page);

skeDrawings.forEach((drawing) => {
const { aLeft, aTop, height, width, drawingId, drawingOrigin } = drawing;
// const behindText = drawingOrigin.layoutType === PositionedObjectLayoutType.WRAP_NONE && drawingOrigin.behindDoc === BooleanNumber.TRUE;
// floatObjects.push({
// unitId,
// subUnitId: DEFAULT_DOCUMENT_SUB_COMPONENT_ID,
// floatingObjectId: drawingId,
// behindText,
// floatingObject: {
// left: aLeft + docsLeft + liquid.x,
// top: aTop + docsTop + liquid.y,
// width,
// height,
// },
// });

pageMarginCache.set(drawingId, {
marginLeft: liquid.x,
marginTop: liquid.y,
});
});

liquid.restorePagePadding(page);

liquid.translatePage(page, pageLayoutType, pageMarginLeft, pageMarginTop);
}

return { pageMarginCache, docsLeft, docsTop };
}

private _refreshDocSkeleton() {
const docsSkeletonObject = this._docSkeletonManagerService.getCurrent();
if (docsSkeletonObject == null) {
return;
}

const { unitId, skeleton } = docsSkeletonObject;

const currentRender = this._renderManagerService.getRenderById(unitId);

if (currentRender == null) {
return;
}
Expand Down
8 changes: 6 additions & 2 deletions packages/docs-drawing-ui/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
* limitations under the License.
*/

import { LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
import { DependentOn, LocaleService, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { UniverDrawingUIPlugin } from '@univerjs/drawing-ui';
import { UniverDrawingPlugin } from '@univerjs/drawing';
import { UniverDocsDrawingPlugin } from '@univerjs/docs-drawing';
import { DocDrawingPopupMenuController } from './controllers/drawing-popup-menu.controller';
import { DocDrawingUIController } from './controllers/doc-drawing.controller';
import { DocDrawingUpdateController } from './controllers/doc-drawing-update.controller';

const PLUGIN_NAME = 'Docs_Drawing_UI_PLUGIN';
const PLUGIN_NAME = 'DOCS_DRAWING_UI_PLUGIN';

@DependentOn(UniverDrawingUIPlugin, UniverDrawingPlugin, UniverDocsDrawingPlugin)
export class UniverDocsDrawingUIPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_DOC;
static override pluginName = PLUGIN_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class DocBackScrollRenderController extends RxDisposable implements IRend
private _scrollToSelection(unitId: string) {
const activeTextRange = this._textSelectionManagerService.getActiveRange();
const docObject = neoGetDocObject(this._context);
const skeleton = this._docSkeletonManagerService.getSkeleton()?.skeleton;
const skeleton = this._docSkeletonManagerService.getSkeleton();

if (activeTextRange == null || docObject == null || skeleton == null) {
if (activeTextRange == null || docObject == null) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/controllers/ime-input.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class IMEInputController extends Disposable {
}

const skeleton = this._renderManagerSrv.getRenderById(documentModel.getUnitId())
?.with(DocSkeletonManagerService).getSkeleton()?.skeleton;
?.with(DocSkeletonManagerService).getSkeleton();

const { event, activeRange } = config;

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/services/doc-skeleton-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DocSkeletonManagerService extends RxDisposable implements IRenderMo
});
}

getSkeleton(): Nullable<DocumentSkeleton> {
getSkeleton(): DocumentSkeleton {
return this._skeleton;
}

Expand Down

0 comments on commit 479d84f

Please sign in to comment.