@univerjs/docs 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +0 -1
  3. package/lib/cjs/facade.js +331 -60
  4. package/lib/cjs/index.js +2472 -102
  5. package/lib/es/facade.js +326 -62
  6. package/lib/es/index.js +2419 -85
  7. package/lib/facade.js +326 -62
  8. package/lib/index.js +2419 -85
  9. package/lib/types/commands/commands/core-editing.command.d.ts +5 -1
  10. package/lib/types/commands/commands/set-document-permission.command.d.ts +27 -0
  11. package/lib/types/commands/commands/set-document-permissions.command.d.ts +17 -0
  12. package/lib/types/commands/mutations/core-editing.mutation-id.d.ts +16 -0
  13. package/lib/types/commands/mutations/core-editing.mutation.d.ts +20 -1
  14. package/lib/types/commands/mutations/doc-structure-mutation-validation.d.ts +17 -0
  15. package/lib/types/commands/mutations/set-document-permission-rule.mutation.d.ts +17 -0
  16. package/lib/types/commands/mutations/set-document-permission-rules.mutation.d.ts +17 -0
  17. package/lib/types/controllers/doc-permission.controller.d.ts +26 -0
  18. package/lib/types/facade/f-document-paragraph.d.ts +15 -2
  19. package/lib/types/facade/f-document-permission.d.ts +177 -0
  20. package/lib/types/facade/f-document-section.d.ts +15 -2
  21. package/lib/types/facade/f-document-text-range.d.ts +3 -1
  22. package/lib/types/facade/f-document.d.ts +34 -2
  23. package/lib/types/facade/f-univer.d.ts +4 -3
  24. package/lib/types/facade/index.d.ts +1 -0
  25. package/lib/types/facade/utils.d.ts +2 -1
  26. package/lib/types/index.d.ts +13 -1
  27. package/lib/types/layout-worker/config/config.d.ts +24 -0
  28. package/lib/types/layout-worker/document-font-metrics.d.ts +18 -0
  29. package/lib/types/layout-worker/index.d.ts +70 -0
  30. package/lib/types/layout-worker/performance-tracker.d.ts +27 -0
  31. package/lib/types/layout-worker/protocol.d.ts +35 -0
  32. package/lib/types/layout-worker/worker.d.ts +49 -0
  33. package/lib/types/services/doc-interceptor/interceptor-const.d.ts +2 -1
  34. package/lib/types/services/doc-layout-executor.service.d.ts +218 -0
  35. package/lib/types/services/doc-selection-manager.service.d.ts +7 -1
  36. package/lib/types/services/doc-skeleton-manager.service.d.ts +6 -1
  37. package/lib/types/services/doc-state-change-manager.service.d.ts +1 -0
  38. package/lib/types/services/doc-state-emit.service.d.ts +4 -0
  39. package/lib/types/services/document-layout-snapshot.d.ts +22 -0
  40. package/lib/types/services/permission/document-permission-resolver.d.ts +27 -0
  41. package/lib/types/services/permission/document-permission-rule.model.d.ts +19 -0
  42. package/lib/types/services/permission/document-permission.d.ts +35 -0
  43. package/lib/types/services/permission/permission-point/document/comment.d.ts +27 -0
  44. package/lib/types/services/permission/permission-point/document/copy.d.ts +27 -0
  45. package/lib/types/services/permission/permission-point/document/editable.d.ts +27 -0
  46. package/lib/types/services/permission/permission-point/document/export.d.ts +27 -0
  47. package/lib/types/services/permission/permission-point/document/print.d.ts +27 -0
  48. package/lib/types/services/permission/permission-point/entity/edit.d.ts +28 -0
  49. package/lib/types/services/permission/permission-point/paragraph/edit.d.ts +28 -0
  50. package/lib/types/services/permission/permission-point/section/edit.d.ts +28 -0
  51. package/lib/umd/facade.js +3 -3
  52. package/lib/umd/index.js +2 -2
  53. package/package.json +7 -5
@@ -21,18 +21,25 @@ export { SetDocumentDefaultParagraphStyleCommand } from './commands/commands/set
21
21
  export type { IDocumentDefaultParagraphStylePatch, ISetDocumentDefaultParagraphStyleCommandParams, } from './commands/commands/set-document-default-paragraph-style.command';
22
22
  export { SetDocumentNameCommand } from './commands/commands/set-document-name.command';
23
23
  export type { ISetDocumentNameCommandParams } from './commands/commands/set-document-name.command';
24
+ export { SetDocumentPermissionCommand } from './commands/commands/set-document-permission.command';
25
+ export type { ISetDocumentPermissionCommandParams } from './commands/commands/set-document-permission.command';
26
+ export { SetDocumentPermissionsCommand } from './commands/commands/set-document-permissions.command';
24
27
  export { SetSectionHeaderFooterLinkCommand } from './commands/commands/set-section-header-footer-link.command';
25
28
  export type { ISetSectionHeaderFooterLinkCommandParams } from './commands/commands/set-section-header-footer-link.command';
26
29
  export { UpdateDocumentParagraphStyleCommand } from './commands/commands/update-document-paragraph-style.command';
27
30
  export { DeleteDocumentSectionBreakCommand, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, UpdateDocumentSectionCommand } from './commands/commands/update-document-section.command';
28
31
  export type { IDeleteDocumentSectionBreakCommandParams, IDocumentSectionConfig, IDocumentSectionUpdate, IInsertDocumentColumnBreakCommandParams, IInsertDocumentSectionBreakCommandParams, IUpdateDocumentSectionCommandParams } from './commands/commands/update-document-section.command';
29
- export { RichTextEditingMutation } from './commands/mutations/core-editing.mutation';
32
+ export { DocHistoryAction, RichTextEditingMutation, transformDocumentTextRanges } from './commands/mutations/core-editing.mutation';
30
33
  export type { IRichTextEditingMutationParams } from './commands/mutations/core-editing.mutation';
34
+ export { SetDocumentPermissionRuleMutation } from './commands/mutations/set-document-permission-rule.mutation';
35
+ export { SetDocumentPermissionRulesMutation } from './commands/mutations/set-document-permission-rules.mutation';
31
36
  export { SetTextSelectionsOperation } from './commands/operations/text-selection.operation';
32
37
  export type { ISetTextSelectionsOperationParams } from './commands/operations/text-selection.operation';
33
38
  export type { IUniverDocsConfig } from './config/config';
34
39
  export { createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, isEmbedDocsCustomBlockData, isSheetLikeDocsCustomBlockChildType, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, } from './embed-host-anchor';
35
40
  export type { EmbedDocsCustomBlockInteractionMode, IDocsCustomBlockMutationParams, IEmbedDocsCustomBlockData, } from './embed-host-anchor';
41
+ export { DocsLayoutWorkerCapabilityError, DocsLayoutWorkerClientService, startDocsLayoutWorker, UniverDocsLayoutWorkerPlugin } from './layout-worker';
42
+ export type { IDocsLayoutWorkerCapabilities, IDocsLayoutWorkerFontProbe, IDocsLayoutWorkerRuntime, IUniverDocsLayoutWorkerConfig } from './layout-worker';
36
43
  export { UniverDocsPlugin } from './plugin';
37
44
  export { DocBlockMoveValidatorService } from './services/doc-block-move-validator.service';
38
45
  export type { DocBlockMoveTransformer, DocBlockMoveValidator, IDocBlockMoveResult, IDocBlockMoveTransformContext, IDocBlockMoveValidationContext, } from './services/doc-block-move-validator.service';
@@ -40,6 +47,8 @@ export { DocContentInsertService } from './services/doc-content-insert.service';
40
47
  export type { IDocContentInsertRange } from './services/doc-content-insert.service';
41
48
  export { DocInterceptorService } from './services/doc-interceptor/doc-interceptor.service';
42
49
  export { DOC_INTERCEPTOR_POINT } from './services/doc-interceptor/interceptor-const';
50
+ export { DocLayoutExecutorService, DocLayoutExecutorState, DocLayoutExecutorType, DocLayoutSessionStatus, } from './services/doc-layout-executor.service';
51
+ export type { IDocLayoutCancelRequest, IDocLayoutCreateSessionRequest, IDocLayoutCustomRangePresentation, IDocLayoutCustomRangePresentationContext, IDocLayoutCustomRangePresentationEntry, IDocLayoutCustomRangePresentationPatch, IDocLayoutDisposeMountRequest, IDocLayoutDisposeSessionRequest, IDocLayoutExecutor, IDocLayoutExecutorStatus, IDocLayoutMountIdentity, IDocLayoutMutationProjection, IDocLayoutPageRequest, IDocLayoutPageResult, IDocLayoutPerformanceMetrics, IDocLayoutRecordPatch, IDocLayoutStartOptions, IDocLayoutStartRequest, IDocLayoutStartResult, IDocLayoutStepRequest, IDocLayoutStepResult, } from './services/doc-layout-executor.service';
43
52
  export { DOC_SELECTION_OPTION_PRESERVE_CARET, DocSelectionManagerService, } from './services/doc-selection-manager.service';
44
53
  export { DocSkeletonManagerService } from './services/doc-skeleton-manager.service';
45
54
  export { DocStateChangeManagerService, IDocStateChangeInterceptorService, } from './services/doc-state-change-manager.service';
@@ -47,6 +56,9 @@ export type { IDocStateChangeInfo, IDocStateChangeParams } from './services/doc-
47
56
  export { DocStateEmitService } from './services/doc-state-emit.service';
48
57
  export { DocTextResolverService } from './services/doc-text-resolver.service';
49
58
  export type { IDocTextReplacement, IDocTextResolver, IResolvedDocText, IResolvedDocTextCharacter, } from './services/doc-text-resolver.service';
59
+ export { canEditDocumentTargets, createDocumentPermissionPoint, DOCUMENT_UNIT_PERMISSION_ACTIONS, getDocumentEntityPermissionObjectId, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, setDocumentPermissionValue, } from './services/permission/document-permission';
60
+ export type { DocumentUnitPermissionAction } from './services/permission/document-permission';
61
+ export { getDocumentDrawingSegmentId, getDocumentEditTargetObjectIds, getDocumentEntityParentPermissionObjectIds, getDocumentParagraphParentPermissionObjectIds, } from './services/permission/document-permission-resolver';
50
62
  export { addCustomRangeBySelectionFactory, addCustomRangeFactory, deleteCustomRangeFactory, } from './utils/custom-range-factory';
51
63
  export { generateParagraphs } from './utils/paragraphs';
52
64
  export { replaceSelectionFactory } from './utils/replace-selection-factory';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export declare const DOCS_LAYOUT_WORKER_PLUGIN_CONFIG_KEY = "docs-layout-worker.config";
17
+ export declare const configSymbol: unique symbol;
18
+ export declare const DEFAULT_DOCS_LAYOUT_WORKER_REQUEST_TIMEOUT_MS = 15000;
19
+ export interface IUniverDocsLayoutWorkerConfig {
20
+ workerFactory?: () => Worker;
21
+ /** Maximum time allowed for one Worker RPC request before recovery starts. */
22
+ requestTimeoutMs?: number;
23
+ }
24
+ export declare const defaultPluginDocsLayoutWorkerConfig: IUniverDocsLayoutWorkerConfig;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /** Collect once from the snapshot, then only from mutation payloads (including JSON1 font replacements). */
17
+ export declare function collectDocumentFontFamilies(value: unknown, families: Set<string>): void;
18
+ export declare function measureDocumentFontFamilies(families: Set<string>): Record<string, number>;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDocLayoutCancelRequest, IDocLayoutCreateSessionRequest, IDocLayoutDisposeMountRequest, IDocLayoutDisposeSessionRequest, IDocLayoutExecutor, IDocLayoutPageRequest, IDocLayoutPageResult, IDocLayoutPerformanceMetrics, IDocLayoutStartRequest, IDocLayoutStartResult, IDocLayoutStepRequest, IDocLayoutStepResult } from '../services/doc-layout-executor.service';
17
+ import type { IUniverDocsLayoutWorkerConfig } from './config/config';
18
+ import type { IDocsLayoutWorkerCapabilities } from './protocol';
19
+ import { Disposable, IConfigService, Injector, Plugin } from '@univerjs/core';
20
+ import { DocLayoutExecutorService, DocLayoutExecutorType } from '../services/doc-layout-executor.service';
21
+ import { startDocsLayoutWorker } from './worker';
22
+ export declare class DocsLayoutWorkerCapabilityError extends Error {
23
+ constructor(message: string);
24
+ }
25
+ export declare class DocsLayoutWorkerClientService extends Disposable implements IDocLayoutExecutor {
26
+ private readonly _workerFactory;
27
+ private readonly _requestTimeoutMs;
28
+ readonly type = DocLayoutExecutorType.WORKER;
29
+ private _worker;
30
+ private _channelService;
31
+ private _runtime;
32
+ private _initialization;
33
+ private _initialized;
34
+ private readonly _performanceTracker;
35
+ private readonly _fontFamilies;
36
+ constructor(_workerFactory: () => Worker, _requestTimeoutMs?: number);
37
+ initialize(): Promise<void>;
38
+ getCapabilities(): Promise<IDocsLayoutWorkerCapabilities>;
39
+ recover(): Promise<void>;
40
+ createSession(request: IDocLayoutCreateSessionRequest): Promise<void>;
41
+ startLayout(request: IDocLayoutStartRequest): Promise<IDocLayoutStartResult>;
42
+ stepLayout(request: IDocLayoutStepRequest): Promise<IDocLayoutStepResult>;
43
+ publishBacklog(request: Omit<IDocLayoutStepRequest, 'budgetMs'>): Promise<IDocLayoutStepResult>;
44
+ getLayoutPage(request: IDocLayoutPageRequest): Promise<IDocLayoutPageResult>;
45
+ cancelLayout(request: IDocLayoutCancelRequest): Promise<void>;
46
+ getPerformanceMetrics(unitId: string): Promise<Omit<IDocLayoutPerformanceMetrics, 'hydrationMs'>>;
47
+ resetPerformanceMetrics(unitId: string): Promise<void>;
48
+ disposeLayoutMount(request: IDocLayoutDisposeMountRequest): Promise<void>;
49
+ disposeSession(request: IDocLayoutDisposeSessionRequest): Promise<void>;
50
+ dispose(): void;
51
+ private _replaceRuntime;
52
+ private _disposeRuntime;
53
+ private _getRuntime;
54
+ private _withTimeout;
55
+ private _verifyCapabilities;
56
+ }
57
+ export declare class UniverDocsLayoutWorkerPlugin extends Plugin {
58
+ private readonly _config;
59
+ readonly _injector: Injector;
60
+ private readonly _layoutExecutorService;
61
+ private readonly _configService;
62
+ static pluginName: string;
63
+ static packageName: string;
64
+ static version: string;
65
+ constructor(_config: Partial<IUniverDocsLayoutWorkerConfig> | undefined, _injector: Injector, _layoutExecutorService: DocLayoutExecutorService, _configService: IConfigService);
66
+ onStarting(): void;
67
+ }
68
+ export type { IUniverDocsLayoutWorkerConfig } from './config/config';
69
+ export type { IDocsLayoutWorkerCapabilities, IDocsLayoutWorkerFontProbe, IDocsLayoutWorkerRuntime } from './protocol';
70
+ export { startDocsLayoutWorker };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDocLayoutPerformanceMetrics } from '../services/doc-layout-executor.service';
17
+ type WorkerTransferMetrics = Omit<IDocLayoutPerformanceMetrics, 'hydrationMs'>;
18
+ export declare class DocsLayoutWorkerPerformanceTracker {
19
+ private readonly _metrics;
20
+ recordRequest(message: unknown, durationMs: number): void;
21
+ recordResponse(message: unknown, durationMs: number): void;
22
+ getMetrics(unitId: string): WorkerTransferMetrics;
23
+ reset(unitId: string): void;
24
+ resetAll(): void;
25
+ private _append;
26
+ }
27
+ export {};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DocLayoutExecutorType, IDocLayoutExecutor } from '../services/doc-layout-executor.service';
17
+ export declare const DOCS_LAYOUT_WORKER_CHANNEL = "univer.docs-layout-worker";
18
+ export declare const DOCS_LAYOUT_WORKER_PROTOCOL_VERSION = 5;
19
+ export interface IDocsLayoutWorkerFontProbe {
20
+ content: string;
21
+ font: string;
22
+ width: number;
23
+ actualBoundingBoxAscent: number;
24
+ actualBoundingBoxDescent: number;
25
+ }
26
+ export interface IDocsLayoutWorkerCapabilities {
27
+ protocolVersion: typeof DOCS_LAYOUT_WORKER_PROTOCOL_VERSION;
28
+ executor: DocLayoutExecutorType.WORKER;
29
+ offscreenCanvas: boolean;
30
+ structuredClone: boolean;
31
+ fontProbe: IDocsLayoutWorkerFontProbe;
32
+ }
33
+ export interface IDocsLayoutWorkerRuntime extends IDocLayoutExecutor {
34
+ getCapabilities(): Promise<IDocsLayoutWorkerCapabilities>;
35
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDocLayoutCancelRequest, IDocLayoutCreateSessionRequest, IDocLayoutDisposeMountRequest, IDocLayoutDisposeSessionRequest, IDocLayoutPageRequest, IDocLayoutPageResult, IDocLayoutPerformanceMetrics, IDocLayoutStartRequest, IDocLayoutStartResult, IDocLayoutStepRequest, IDocLayoutStepResult } from '../services/doc-layout-executor.service';
17
+ import type { IDocsLayoutWorkerCapabilities, IDocsLayoutWorkerRuntime } from './protocol';
18
+ import { ChannelService } from '@univerjs/rpc';
19
+ import { DocLayoutExecutorType } from '../services/doc-layout-executor.service';
20
+ import { DocsLayoutWorkerPerformanceTracker } from './performance-tracker';
21
+ export declare class DocsLayoutWorkerRuntime implements IDocsLayoutWorkerRuntime {
22
+ private readonly _performanceTracker;
23
+ private readonly _sessions;
24
+ readonly type = DocLayoutExecutorType.WORKER;
25
+ constructor(_performanceTracker?: DocsLayoutWorkerPerformanceTracker);
26
+ initialize(): Promise<void>;
27
+ getCapabilities(): Promise<IDocsLayoutWorkerCapabilities>;
28
+ recover(): Promise<void>;
29
+ createSession(request: IDocLayoutCreateSessionRequest): Promise<void>;
30
+ startLayout(request: IDocLayoutStartRequest): Promise<IDocLayoutStartResult>;
31
+ private _applyMutations;
32
+ private _applyCustomRangePresentations;
33
+ private _updateCustomRangePresentations;
34
+ stepLayout(request: IDocLayoutStepRequest): Promise<IDocLayoutStepResult>;
35
+ publishBacklog(request: Omit<IDocLayoutStepRequest, 'budgetMs'>): Promise<IDocLayoutStepResult>;
36
+ getLayoutPage(request: IDocLayoutPageRequest): Promise<IDocLayoutPageResult>;
37
+ cancelLayout(request: IDocLayoutCancelRequest): Promise<void>;
38
+ getPerformanceMetrics(unitId: string): Promise<Omit<IDocLayoutPerformanceMetrics, 'hydrationMs'>>;
39
+ resetPerformanceMetrics(unitId: string): Promise<void>;
40
+ disposeLayoutMount(request: IDocLayoutDisposeMountRequest): Promise<void>;
41
+ disposeSession(request: IDocLayoutDisposeSessionRequest): Promise<void>;
42
+ dispose(): void;
43
+ private _getSession;
44
+ private _getLayoutMount;
45
+ private _runLayoutStep;
46
+ private _runWithCustomBlockViewports;
47
+ private _disposeSession;
48
+ }
49
+ export declare function startDocsLayoutWorker(): ChannelService;
@@ -13,11 +13,12 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import type { ICustomDecoration, ICustomDecorationForInterceptor, ICustomRange, ICustomRangeForInterceptor } from '@univerjs/core';
16
+ import type { ICustomDecoration, ICustomDecorationForInterceptor, ICustomRange, ICustomRangeForInterceptor, IDocumentBody } from '@univerjs/core';
17
17
  export declare const DOC_INTERCEPTOR_POINT: {
18
18
  CUSTOM_RANGE: import("@univerjs/core").IInterceptor<ICustomRangeForInterceptor, {
19
19
  index: number;
20
20
  unitId: string;
21
+ body: IDocumentBody | undefined;
21
22
  customRanges: ICustomRange[];
22
23
  }>;
23
24
  CUSTOM_DECORATION: import("@univerjs/core").IInterceptor<ICustomDecorationForInterceptor, {
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ICustomRange, IDisposable, IDocumentBody, IDocumentData, ILanguagePack, JSONXActions, LocaleType, Nullable } from '@univerjs/core';
17
+ import type { IDocsCustomBlockRenderViewport, IDocumentLayoutPagePublication, IDocumentLayoutSessionStartOptions, IDocumentLayoutStepResult } from '@univerjs/engine-render';
18
+ import { Disposable, ICommandService, ILogService, IUniverInstanceService, LocaleService } from '@univerjs/core';
19
+ export declare enum DocLayoutExecutorType {
20
+ MAIN_THREAD = "main-thread",
21
+ WORKER = "worker"
22
+ }
23
+ export declare enum DocLayoutSessionStatus {
24
+ ACCEPTED = "accepted",
25
+ NOT_FOUND = "not-found",
26
+ RESNAPSHOT_REQUIRED = "resnapshot-required",
27
+ SUPERSEDED = "superseded"
28
+ }
29
+ export declare enum DocLayoutExecutorState {
30
+ UNREGISTERED = "unregistered",
31
+ INITIALIZING = "initializing",
32
+ ACTIVE = "active",
33
+ RECOVERING = "recovering",
34
+ FAILED = "failed"
35
+ }
36
+ export interface IDocLayoutExecutorStatus {
37
+ state: DocLayoutExecutorState;
38
+ executor: DocLayoutExecutorType | null;
39
+ diagnostic: string | null;
40
+ recoveryUnitId: string | null;
41
+ }
42
+ export interface IDocLayoutPerformanceMetrics {
43
+ hydrationMs: number[];
44
+ mutationTransferMs: number[];
45
+ patchTransferMs: number[];
46
+ snapshotTransferMs: number[];
47
+ }
48
+ export interface IDocLayoutCreateSessionRequest {
49
+ normalFontLineHeights?: Record<string, number>;
50
+ unitId: string;
51
+ sessionEpoch: number;
52
+ snapshot: IDocumentData;
53
+ modelRevision: number;
54
+ locale: LocaleType;
55
+ localeData?: ILanguagePack;
56
+ direction: 'ltr' | 'rtl';
57
+ }
58
+ export interface IDocLayoutDisposeSessionRequest {
59
+ unitId: string;
60
+ sessionEpoch: number;
61
+ }
62
+ export interface IDocLayoutMutationProjection {
63
+ baseRevision: number;
64
+ modelRevision: number;
65
+ actions: JSONXActions;
66
+ }
67
+ export interface IDocLayoutMountIdentity {
68
+ unitId: string;
69
+ mountId: string;
70
+ mountEpoch: number;
71
+ viewportEpoch: number;
72
+ }
73
+ export interface IDocLayoutStartRequest extends IDocLayoutMountIdentity {
74
+ normalFontLineHeights?: Record<string, number>;
75
+ metricsRevision: number;
76
+ baseRevision: number;
77
+ modelRevision: number;
78
+ mutations: IDocLayoutMutationProjection[];
79
+ reason: 'initial' | 'edit';
80
+ anchor?: number;
81
+ priorityAnchor?: number;
82
+ invalidation?: IDocumentLayoutSessionStartOptions['invalidation'];
83
+ customBlockViewports?: Record<string, IDocsCustomBlockRenderViewport>;
84
+ customBlockViewportPatch?: IDocLayoutRecordPatch<IDocsCustomBlockRenderViewport>;
85
+ customRangePresentations?: IDocLayoutCustomRangePresentationEntry[];
86
+ customRangePresentationPatch?: IDocLayoutCustomRangePresentationPatch;
87
+ budgetMs: number;
88
+ }
89
+ export interface IDocLayoutRecordPatch<T> {
90
+ removals: string[];
91
+ upserts: Record<string, T>;
92
+ }
93
+ export interface IDocLayoutCustomRangePresentation {
94
+ active?: boolean;
95
+ glyphAscentEm?: number;
96
+ glyphDescentEm?: number;
97
+ glyphWidthEm?: number;
98
+ show?: boolean;
99
+ }
100
+ export interface IDocLayoutCustomRangePresentationEntry {
101
+ segmentId: string;
102
+ rangeId: string;
103
+ presentation: IDocLayoutCustomRangePresentation;
104
+ }
105
+ export interface IDocLayoutCustomRangePresentationPatch {
106
+ removals: Array<Pick<IDocLayoutCustomRangePresentationEntry, 'segmentId' | 'rangeId'>>;
107
+ upserts: IDocLayoutCustomRangePresentationEntry[];
108
+ }
109
+ export interface IDocLayoutCustomRangePresentationContext {
110
+ segmentId: string;
111
+ body: IDocumentBody;
112
+ }
113
+ type DocLayoutCustomRangePresentationProvider = (unitId: string, range: ICustomRange, context: IDocLayoutCustomRangePresentationContext) => IDocLayoutCustomRangePresentation | null | undefined;
114
+ export type IDocLayoutStartResult = {
115
+ status: DocLayoutSessionStatus.ACCEPTED;
116
+ step: IDocLayoutStepResult;
117
+ } | {
118
+ status: DocLayoutSessionStatus.NOT_FOUND;
119
+ } | {
120
+ status: DocLayoutSessionStatus.SUPERSEDED;
121
+ } | {
122
+ status: DocLayoutSessionStatus.RESNAPSHOT_REQUIRED;
123
+ modelRevision: number;
124
+ };
125
+ export interface IDocLayoutStepRequest extends IDocLayoutMountIdentity {
126
+ generation: number;
127
+ budgetMs: number;
128
+ }
129
+ export interface IDocLayoutPageRequest extends IDocLayoutMountIdentity {
130
+ pageIndex: number;
131
+ }
132
+ export interface IDocLayoutPageResult extends IDocLayoutMountIdentity {
133
+ modelRevision: number;
134
+ metricsRevision: number;
135
+ page: IDocumentLayoutPagePublication | null;
136
+ }
137
+ export interface IDocLayoutCancelRequest extends IDocLayoutMountIdentity {
138
+ generation?: number;
139
+ }
140
+ export type IDocLayoutDisposeMountRequest = IDocLayoutMountIdentity;
141
+ export interface IDocLayoutStepResult extends IDocumentLayoutStepResult, IDocLayoutMountIdentity {
142
+ modelRevision: number;
143
+ metricsRevision: number;
144
+ }
145
+ export interface IDocLayoutExecutor {
146
+ readonly type: DocLayoutExecutorType;
147
+ initialize(): Promise<void>;
148
+ recover(): Promise<void>;
149
+ /**
150
+ * Capture the request synchronously before returning. The source document model remains mutable
151
+ * while the returned promise tracks remote session creation.
152
+ */
153
+ createSession(request: IDocLayoutCreateSessionRequest): Promise<void>;
154
+ startLayout(request: IDocLayoutStartRequest): Promise<IDocLayoutStartResult>;
155
+ stepLayout(request: IDocLayoutStepRequest): Promise<IDocLayoutStepResult>;
156
+ publishBacklog(request: Omit<IDocLayoutStepRequest, 'budgetMs'>): Promise<IDocLayoutStepResult>;
157
+ getLayoutPage(request: IDocLayoutPageRequest): Promise<IDocLayoutPageResult>;
158
+ cancelLayout(request: IDocLayoutCancelRequest): Promise<void>;
159
+ getPerformanceMetrics(unitId: string): Promise<Omit<IDocLayoutPerformanceMetrics, 'hydrationMs'>>;
160
+ resetPerformanceMetrics(unitId: string): Promise<void>;
161
+ disposeLayoutMount(request: IDocLayoutDisposeMountRequest): Promise<void>;
162
+ disposeSession(request: IDocLayoutDisposeSessionRequest): Promise<void>;
163
+ }
164
+ export interface IDocLayoutStartOptions {
165
+ reason: 'initial' | 'edit';
166
+ anchor?: number;
167
+ priorityAnchor?: number;
168
+ invalidation?: IDocumentLayoutSessionStartOptions['invalidation'];
169
+ }
170
+ export declare class DocLayoutExecutorService extends Disposable {
171
+ private readonly _univerInstanceService;
172
+ private readonly _commandService;
173
+ private readonly _localeService;
174
+ private readonly _logService;
175
+ private static readonly _performanceSampleLimit;
176
+ private _executor;
177
+ private _executorReady;
178
+ private _recoveryFailure;
179
+ private _sessionEpoch;
180
+ private readonly _sessions;
181
+ private readonly _hydrationSamples;
182
+ private readonly _customRangePresentationProviders;
183
+ private readonly _executorStatus$;
184
+ readonly executorStatus$: import("rxjs").Observable<IDocLayoutExecutorStatus>;
185
+ constructor(_univerInstanceService: IUniverInstanceService, _commandService: ICommandService, _localeService: LocaleService, _logService: ILogService);
186
+ register(executor: IDocLayoutExecutor): IDisposable;
187
+ getExecutor(): Nullable<IDocLayoutExecutor>;
188
+ getExecutorStatus(): IDocLayoutExecutorStatus;
189
+ registerCustomRangePresentationProvider(provider: DocLayoutCustomRangePresentationProvider): IDisposable;
190
+ getPerformanceMetrics(unitId: string): Promise<IDocLayoutPerformanceMetrics>;
191
+ resetPerformanceMetrics(unitId: string): Promise<void>;
192
+ recordHydrationDuration(unitId: string, durationMs: number): void;
193
+ recoverExecutor(unitId: string, diagnostic: string): Promise<void>;
194
+ completeRecovery(unitId: string): void;
195
+ startLayout(identity: IDocLayoutMountIdentity, options: IDocLayoutStartOptions, budgetMs: number): Promise<IDocLayoutStartResult | null>;
196
+ stepLayout(request: IDocLayoutStepRequest): Promise<IDocLayoutStepResult>;
197
+ publishBacklog(request: Omit<IDocLayoutStepRequest, 'budgetMs'>): Promise<IDocLayoutStepResult>;
198
+ getLayoutPage(request: IDocLayoutPageRequest): Promise<IDocLayoutPageResult>;
199
+ cancelLayout(request: IDocLayoutCancelRequest): Promise<void>;
200
+ disposeLayoutMount(request: IDocLayoutDisposeMountRequest): Promise<void>;
201
+ dispose(): void;
202
+ private _createSessionIfEligible;
203
+ private _enqueueCommittedMutation;
204
+ private _startSynchronizedLayout;
205
+ private _createLayoutProjectionPayload;
206
+ private _replaceSession;
207
+ private _disposeSession;
208
+ private _getEligibleModel;
209
+ private _getRequiredModel;
210
+ private _collectCustomRangePresentations;
211
+ private _isEligible;
212
+ private _requireExecutor;
213
+ private _appendPerformanceSample;
214
+ private _createSessionOnNextMacroTask;
215
+ private _markSessionDisposed;
216
+ private _disposeManagedSessions;
217
+ }
218
+ export {};
@@ -50,7 +50,7 @@ export declare class DocSelectionManagerService extends RxDisposable {
50
50
  private _listenCurrentUnit;
51
51
  __getCurrentSelection(): Nullable<IDocSelectionManagerSearchParam>;
52
52
  getSelectionInfo(params?: Nullable<IDocSelectionManagerSearchParam>): IDocSelectionInnerParam | undefined;
53
- refreshSelection(params?: Nullable<IDocSelectionManagerSearchParam>): void;
53
+ refreshSelection(params?: Nullable<IDocSelectionManagerSearchParam>, isEditing?: boolean): void;
54
54
  __TEST_ONLY_setCurrentSelection(param: IDocSelectionManagerSearchParam): void;
55
55
  getTextRanges(params?: Nullable<IDocSelectionManagerSearchParam>): Readonly<Nullable<ITextRangeWithStyle[]>>;
56
56
  getRectRanges(params?: Nullable<IDocSelectionManagerSearchParam>): Readonly<Nullable<IRectRangeWithStyle[]>>;
@@ -60,6 +60,12 @@ export declare class DocSelectionManagerService extends RxDisposable {
60
60
  replaceDocRanges(docRanges: ISuccinctDocRangeParam[], params?: Nullable<IDocSelectionManagerSearchParam>, isEditing?: boolean, options?: {
61
61
  [key: string]: boolean;
62
62
  }): void;
63
+ /**
64
+ * Replaces logical selection state without rebuilding render ranges. Atomic
65
+ * external mutations use this before applying document actions so layout can
66
+ * follow transformed offsets, then refresh after new geometry is available.
67
+ */
68
+ replaceSelectionInfoWithoutRefresh(selectionInfo: IDocSelectionInnerParam, params?: Nullable<IDocSelectionManagerSearchParam>): void;
63
69
  __replaceTextRangesWithNoRefresh(textSelectionInfo: IDocSelectionInnerParam, search: IDocSelectionManagerSearchParam): void;
64
70
  dispose(): void;
65
71
  private _setCurrentSelectionNotRefresh;
@@ -17,6 +17,7 @@ import type { DocumentDataModel, Nullable } from '@univerjs/core';
17
17
  import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
18
18
  import { IUniverInstanceService, LocaleService, RxDisposable } from '@univerjs/core';
19
19
  import { DocumentSkeleton, DocumentViewModel } from '@univerjs/engine-render';
20
+ import { DocLayoutExecutorService } from './doc-layout-executor.service';
20
21
  /**
21
22
  * This service is for document build and manage doc skeletons. It also manages
22
23
  * DocumentViewModels.
@@ -25,6 +26,7 @@ export declare class DocSkeletonManagerService extends RxDisposable implements I
25
26
  private readonly _context;
26
27
  private readonly _localeService;
27
28
  private readonly _univerInstanceService;
29
+ private readonly _docLayoutExecutorService;
28
30
  private _skeleton;
29
31
  private _docViewModel;
30
32
  private readonly _currentSkeleton$;
@@ -33,11 +35,14 @@ export declare class DocSkeletonManagerService extends RxDisposable implements I
33
35
  readonly currentSkeletonBefore$: import("rxjs").Observable<Nullable<DocumentSkeleton>>;
34
36
  private readonly _currentViewModel$;
35
37
  readonly currentViewModel$: import("rxjs").Observable<Nullable<DocumentViewModel>>;
36
- constructor(_context: IRenderContext<DocumentDataModel>, _localeService: LocaleService, _univerInstanceService: IUniverInstanceService);
38
+ constructor(_context: Pick<IRenderContext<DocumentDataModel>, 'type' | 'unit' | 'unitId'>, _localeService: LocaleService, _univerInstanceService: IUniverInstanceService, _docLayoutExecutorService: DocLayoutExecutorService);
37
39
  dispose(): void;
38
40
  getSkeleton(): DocumentSkeleton;
39
41
  getViewModel(): DocumentViewModel;
42
+ getLayoutPerformanceMetrics(): ReturnType<DocLayoutExecutorService['getPerformanceMetrics']>;
43
+ supportsIncrementalLayout(): boolean;
40
44
  recalculate(): DocumentSkeleton;
45
+ private _publishSkeleton;
41
46
  private _init;
42
47
  private _update;
43
48
  private _buildSkeleton;
@@ -43,6 +43,7 @@ export declare class DocStateChangeManagerService extends RxDisposable {
43
43
  collaboration: IDocStateChangeParams[];
44
44
  };
45
45
  setStateCache(unitId: string, cache: IStateCache): void;
46
+ clearHistory(unitId: string): void;
46
47
  private _setChangeState;
47
48
  private _initialize;
48
49
  private _listenDocStateChange;
@@ -19,6 +19,10 @@ import { RxDisposable } from '@univerjs/core';
19
19
  interface IDocChangeState {
20
20
  actions: JSONXActions;
21
21
  textRanges: Nullable<ITextRangeWithStyle[]>;
22
+ options?: {
23
+ [key: string]: boolean;
24
+ };
25
+ isEditing?: boolean;
22
26
  }
23
27
  export interface IDocStateChangeParams {
24
28
  commandId: string;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDocumentData } from '@univerjs/core';
17
+ /**
18
+ * Builds the model snapshot owned by the layout Worker. Exchange-only payloads
19
+ * remain in the authoritative Main model and are deliberately excluded from
20
+ * the structured-clone boundary because they do not affect document geometry.
21
+ */
22
+ export declare function createDocumentLayoutSnapshot(snapshot: IDocumentData): IDocumentData;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DocumentDataModel, IDocumentBody, JSONXActions } from '@univerjs/core';
17
+ export interface IDocumentPermissionRange {
18
+ startOffset: number;
19
+ endOffset: number;
20
+ }
21
+ export declare function getDocumentDrawingSegmentId(documentDataModel: DocumentDataModel, drawingId: string): string;
22
+ export declare function getDocumentEditTargetObjectIds(documentDataModel: DocumentDataModel, segmentId: string, range: IDocumentPermissionRange): string[];
23
+ export declare function getDocumentEditTargetObjectIdsFromActions(documentDataModel: DocumentDataModel, segmentId: string, actions: JSONXActions): string[];
24
+ export declare function getDocumentEntityParentPermissionObjectIds(documentDataModel: DocumentDataModel, segmentId: string, entityType: string, entityId: string): string[];
25
+ export declare function getDocumentParagraphParentPermissionObjectIds(documentDataModel: DocumentDataModel, segmentId: string, paragraphId: string): string[];
26
+ export declare function getDocumentSectionPermissionObjectIdsByIds(sectionIds: Iterable<string>): string[];
27
+ export declare function getDocumentSectionIdsAtOffset(body: IDocumentBody, offset: number): string[];