@univerjs/docs 1.0.0-alpha.3 → 1.0.0-alpha.4

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.
package/lib/cjs/index.js CHANGED
@@ -1151,7 +1151,7 @@ function composeActions(actions) {
1151
1151
  //#endregion
1152
1152
  //#region package.json
1153
1153
  var name = "@univerjs/docs";
1154
- var version = "1.0.0-alpha.3";
1154
+ var version = "1.0.0-alpha.4";
1155
1155
 
1156
1156
  //#endregion
1157
1157
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -1761,6 +1761,56 @@ function createSectionColumnProperties(documentStyle, section, columnCount, gap,
1761
1761
  }));
1762
1762
  }
1763
1763
 
1764
+ //#endregion
1765
+ //#region src/utils/transform-position.ts
1766
+ function buildDocTransform(width, height, position) {
1767
+ var _position$left, _position$top;
1768
+ return {
1769
+ size: {
1770
+ width,
1771
+ height
1772
+ },
1773
+ positionH: {
1774
+ relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
1775
+ posOffset: (_position$left = position === null || position === void 0 ? void 0 : position.left) !== null && _position$left !== void 0 ? _position$left : 0
1776
+ },
1777
+ positionV: {
1778
+ relativeFrom: _univerjs_core.ObjectRelativeFromV.PARAGRAPH,
1779
+ posOffset: (_position$top = position === null || position === void 0 ? void 0 : position.top) !== null && _position$top !== void 0 ? _position$top : 0
1780
+ },
1781
+ angle: 0
1782
+ };
1783
+ }
1784
+ function docDrawingPositionToTransform(position) {
1785
+ return {
1786
+ left: position.positionH.posOffset,
1787
+ top: position.positionV.posOffset,
1788
+ width: position.size.width,
1789
+ height: position.size.height,
1790
+ flipX: position.flipX,
1791
+ flipY: position.flipY
1792
+ };
1793
+ }
1794
+ function transformToDocDrawingPosition(transform, marginLeft = 0, marginTop = 0) {
1795
+ return {
1796
+ size: {
1797
+ width: transform.width,
1798
+ height: transform.height
1799
+ },
1800
+ positionH: {
1801
+ relativeFrom: _univerjs_core.ObjectRelativeFromH.MARGIN,
1802
+ posOffset: (transform.left || 0) - marginLeft
1803
+ },
1804
+ positionV: {
1805
+ relativeFrom: _univerjs_core.ObjectRelativeFromV.PAGE,
1806
+ posOffset: (transform.top || 0) - marginTop
1807
+ },
1808
+ angle: transform.angle || 0,
1809
+ flipX: transform.flipX,
1810
+ flipY: transform.flipY
1811
+ };
1812
+ }
1813
+
1764
1814
  //#endregion
1765
1815
  //#region src/utils/util.ts
1766
1816
  function consumeContentInsertRange(accessor, unitId) {
@@ -1770,9 +1820,30 @@ function consumeContentInsertRange(accessor, unitId) {
1770
1820
  return null;
1771
1821
  }
1772
1822
  }
1823
+ function getContentInsertRange(accessor, unitId) {
1824
+ var _accessor$get$getCurr;
1825
+ const _unitId = unitId !== null && unitId !== void 0 ? unitId : (_accessor$get$getCurr = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _accessor$get$getCurr === void 0 ? void 0 : _accessor$get$getCurr.getUnitId();
1826
+ if (!_unitId) return null;
1827
+ const insertRange = consumeContentInsertRange(accessor, _unitId);
1828
+ if (!insertRange) return null;
1829
+ return {
1830
+ ...insertRange,
1831
+ collapsed: (insertRange === null || insertRange === void 0 ? void 0 : insertRange.startOffset) === (insertRange === null || insertRange === void 0 ? void 0 : insertRange.endOffset)
1832
+ };
1833
+ }
1773
1834
  function isHeaderFooterSelection(range) {
1774
1835
  return Boolean(range === null || range === void 0 ? void 0 : range.segmentId);
1775
1836
  }
1837
+ function normalizeTextRange(textRange) {
1838
+ var _textRange$endOffset, _textRange$collapsed, _textRange$segmentId;
1839
+ const endOffset = (_textRange$endOffset = textRange.endOffset) !== null && _textRange$endOffset !== void 0 ? _textRange$endOffset : textRange.startOffset;
1840
+ return {
1841
+ ...textRange,
1842
+ endOffset,
1843
+ collapsed: (_textRange$collapsed = textRange.collapsed) !== null && _textRange$collapsed !== void 0 ? _textRange$collapsed : textRange.startOffset === endOffset,
1844
+ segmentId: (_textRange$segmentId = textRange.segmentId) !== null && _textRange$segmentId !== void 0 ? _textRange$segmentId : ""
1845
+ };
1846
+ }
1776
1847
 
1777
1848
  //#endregion
1778
1849
  exports.CreateHeaderFooterCommand = CreateHeaderFooterCommand;
@@ -1825,6 +1896,7 @@ exports.UpdateDocumentSectionCommand = UpdateDocumentSectionCommand;
1825
1896
  exports.UpdateTextCommand = UpdateTextCommand;
1826
1897
  exports.addCustomRangeBySelectionFactory = addCustomRangeBySelectionFactory;
1827
1898
  exports.addCustomRangeFactory = addCustomRangeFactory;
1899
+ exports.buildDocTransform = buildDocTransform;
1828
1900
  exports.consumeContentInsertRange = consumeContentInsertRange;
1829
1901
  exports.createDocsCustomBlockDrawing = createDocsCustomBlockDrawing;
1830
1902
  exports.createDocsCustomBlockInsertMutation = createDocsCustomBlockInsertMutation;
@@ -1834,11 +1906,15 @@ exports.createInsertCustomBlockActions = createInsertCustomBlockActions;
1834
1906
  exports.createRemoveCustomBlockActions = createRemoveCustomBlockActions;
1835
1907
  exports.createSectionColumnProperties = createSectionColumnProperties;
1836
1908
  exports.deleteCustomRangeFactory = deleteCustomRangeFactory;
1909
+ exports.docDrawingPositionToTransform = docDrawingPositionToTransform;
1837
1910
  exports.generateParagraphs = generateParagraphs;
1911
+ exports.getContentInsertRange = getContentInsertRange;
1838
1912
  exports.getTopLevelSectionBreaks = getTopLevelSectionBreaks;
1839
1913
  exports.isEmbedDocsCustomBlockData = isEmbedDocsCustomBlockData;
1840
1914
  exports.isHeaderFooterSelection = isHeaderFooterSelection;
1841
1915
  exports.isSheetLikeDocsCustomBlockChildType = isSheetLikeDocsCustomBlockChildType;
1916
+ exports.normalizeTextRange = normalizeTextRange;
1842
1917
  exports.replaceSelectionFactory = replaceSelectionFactory;
1843
1918
  exports.resolveDocsCustomBlockSize = resolveDocsCustomBlockSize;
1844
- exports.shouldUseInlineTextSelectionForDocsCustomBlockDrawing = shouldUseInlineTextSelectionForDocsCustomBlockDrawing;
1919
+ exports.shouldUseInlineTextSelectionForDocsCustomBlockDrawing = shouldUseInlineTextSelectionForDocsCustomBlockDrawing;
1920
+ exports.transformToDocDrawingPosition = transformToDocDrawingPosition;
package/lib/es/index.js CHANGED
@@ -1150,7 +1150,7 @@ function composeActions(actions) {
1150
1150
  //#endregion
1151
1151
  //#region package.json
1152
1152
  var name = "@univerjs/docs";
1153
- var version = "1.0.0-alpha.3";
1153
+ var version = "1.0.0-alpha.4";
1154
1154
 
1155
1155
  //#endregion
1156
1156
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -1760,6 +1760,56 @@ function createSectionColumnProperties(documentStyle, section, columnCount, gap,
1760
1760
  }));
1761
1761
  }
1762
1762
 
1763
+ //#endregion
1764
+ //#region src/utils/transform-position.ts
1765
+ function buildDocTransform(width, height, position) {
1766
+ var _position$left, _position$top;
1767
+ return {
1768
+ size: {
1769
+ width,
1770
+ height
1771
+ },
1772
+ positionH: {
1773
+ relativeFrom: ObjectRelativeFromH.PAGE,
1774
+ posOffset: (_position$left = position === null || position === void 0 ? void 0 : position.left) !== null && _position$left !== void 0 ? _position$left : 0
1775
+ },
1776
+ positionV: {
1777
+ relativeFrom: ObjectRelativeFromV.PARAGRAPH,
1778
+ posOffset: (_position$top = position === null || position === void 0 ? void 0 : position.top) !== null && _position$top !== void 0 ? _position$top : 0
1779
+ },
1780
+ angle: 0
1781
+ };
1782
+ }
1783
+ function docDrawingPositionToTransform(position) {
1784
+ return {
1785
+ left: position.positionH.posOffset,
1786
+ top: position.positionV.posOffset,
1787
+ width: position.size.width,
1788
+ height: position.size.height,
1789
+ flipX: position.flipX,
1790
+ flipY: position.flipY
1791
+ };
1792
+ }
1793
+ function transformToDocDrawingPosition(transform, marginLeft = 0, marginTop = 0) {
1794
+ return {
1795
+ size: {
1796
+ width: transform.width,
1797
+ height: transform.height
1798
+ },
1799
+ positionH: {
1800
+ relativeFrom: ObjectRelativeFromH.MARGIN,
1801
+ posOffset: (transform.left || 0) - marginLeft
1802
+ },
1803
+ positionV: {
1804
+ relativeFrom: ObjectRelativeFromV.PAGE,
1805
+ posOffset: (transform.top || 0) - marginTop
1806
+ },
1807
+ angle: transform.angle || 0,
1808
+ flipX: transform.flipX,
1809
+ flipY: transform.flipY
1810
+ };
1811
+ }
1812
+
1763
1813
  //#endregion
1764
1814
  //#region src/utils/util.ts
1765
1815
  function consumeContentInsertRange(accessor, unitId) {
@@ -1769,9 +1819,30 @@ function consumeContentInsertRange(accessor, unitId) {
1769
1819
  return null;
1770
1820
  }
1771
1821
  }
1822
+ function getContentInsertRange(accessor, unitId) {
1823
+ var _accessor$get$getCurr;
1824
+ const _unitId = unitId !== null && unitId !== void 0 ? unitId : (_accessor$get$getCurr = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _accessor$get$getCurr === void 0 ? void 0 : _accessor$get$getCurr.getUnitId();
1825
+ if (!_unitId) return null;
1826
+ const insertRange = consumeContentInsertRange(accessor, _unitId);
1827
+ if (!insertRange) return null;
1828
+ return {
1829
+ ...insertRange,
1830
+ collapsed: (insertRange === null || insertRange === void 0 ? void 0 : insertRange.startOffset) === (insertRange === null || insertRange === void 0 ? void 0 : insertRange.endOffset)
1831
+ };
1832
+ }
1772
1833
  function isHeaderFooterSelection(range) {
1773
1834
  return Boolean(range === null || range === void 0 ? void 0 : range.segmentId);
1774
1835
  }
1836
+ function normalizeTextRange(textRange) {
1837
+ var _textRange$endOffset, _textRange$collapsed, _textRange$segmentId;
1838
+ const endOffset = (_textRange$endOffset = textRange.endOffset) !== null && _textRange$endOffset !== void 0 ? _textRange$endOffset : textRange.startOffset;
1839
+ return {
1840
+ ...textRange,
1841
+ endOffset,
1842
+ collapsed: (_textRange$collapsed = textRange.collapsed) !== null && _textRange$collapsed !== void 0 ? _textRange$collapsed : textRange.startOffset === endOffset,
1843
+ segmentId: (_textRange$segmentId = textRange.segmentId) !== null && _textRange$segmentId !== void 0 ? _textRange$segmentId : ""
1844
+ };
1845
+ }
1775
1846
 
1776
1847
  //#endregion
1777
- export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, generateParagraphs, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing };
1848
+ export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformToDocDrawingPosition };
package/lib/index.js CHANGED
@@ -1150,7 +1150,7 @@ function composeActions(actions) {
1150
1150
  //#endregion
1151
1151
  //#region package.json
1152
1152
  var name = "@univerjs/docs";
1153
- var version = "1.0.0-alpha.3";
1153
+ var version = "1.0.0-alpha.4";
1154
1154
 
1155
1155
  //#endregion
1156
1156
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -1760,6 +1760,56 @@ function createSectionColumnProperties(documentStyle, section, columnCount, gap,
1760
1760
  }));
1761
1761
  }
1762
1762
 
1763
+ //#endregion
1764
+ //#region src/utils/transform-position.ts
1765
+ function buildDocTransform(width, height, position) {
1766
+ var _position$left, _position$top;
1767
+ return {
1768
+ size: {
1769
+ width,
1770
+ height
1771
+ },
1772
+ positionH: {
1773
+ relativeFrom: ObjectRelativeFromH.PAGE,
1774
+ posOffset: (_position$left = position === null || position === void 0 ? void 0 : position.left) !== null && _position$left !== void 0 ? _position$left : 0
1775
+ },
1776
+ positionV: {
1777
+ relativeFrom: ObjectRelativeFromV.PARAGRAPH,
1778
+ posOffset: (_position$top = position === null || position === void 0 ? void 0 : position.top) !== null && _position$top !== void 0 ? _position$top : 0
1779
+ },
1780
+ angle: 0
1781
+ };
1782
+ }
1783
+ function docDrawingPositionToTransform(position) {
1784
+ return {
1785
+ left: position.positionH.posOffset,
1786
+ top: position.positionV.posOffset,
1787
+ width: position.size.width,
1788
+ height: position.size.height,
1789
+ flipX: position.flipX,
1790
+ flipY: position.flipY
1791
+ };
1792
+ }
1793
+ function transformToDocDrawingPosition(transform, marginLeft = 0, marginTop = 0) {
1794
+ return {
1795
+ size: {
1796
+ width: transform.width,
1797
+ height: transform.height
1798
+ },
1799
+ positionH: {
1800
+ relativeFrom: ObjectRelativeFromH.MARGIN,
1801
+ posOffset: (transform.left || 0) - marginLeft
1802
+ },
1803
+ positionV: {
1804
+ relativeFrom: ObjectRelativeFromV.PAGE,
1805
+ posOffset: (transform.top || 0) - marginTop
1806
+ },
1807
+ angle: transform.angle || 0,
1808
+ flipX: transform.flipX,
1809
+ flipY: transform.flipY
1810
+ };
1811
+ }
1812
+
1763
1813
  //#endregion
1764
1814
  //#region src/utils/util.ts
1765
1815
  function consumeContentInsertRange(accessor, unitId) {
@@ -1769,9 +1819,30 @@ function consumeContentInsertRange(accessor, unitId) {
1769
1819
  return null;
1770
1820
  }
1771
1821
  }
1822
+ function getContentInsertRange(accessor, unitId) {
1823
+ var _accessor$get$getCurr;
1824
+ const _unitId = unitId !== null && unitId !== void 0 ? unitId : (_accessor$get$getCurr = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _accessor$get$getCurr === void 0 ? void 0 : _accessor$get$getCurr.getUnitId();
1825
+ if (!_unitId) return null;
1826
+ const insertRange = consumeContentInsertRange(accessor, _unitId);
1827
+ if (!insertRange) return null;
1828
+ return {
1829
+ ...insertRange,
1830
+ collapsed: (insertRange === null || insertRange === void 0 ? void 0 : insertRange.startOffset) === (insertRange === null || insertRange === void 0 ? void 0 : insertRange.endOffset)
1831
+ };
1832
+ }
1772
1833
  function isHeaderFooterSelection(range) {
1773
1834
  return Boolean(range === null || range === void 0 ? void 0 : range.segmentId);
1774
1835
  }
1836
+ function normalizeTextRange(textRange) {
1837
+ var _textRange$endOffset, _textRange$collapsed, _textRange$segmentId;
1838
+ const endOffset = (_textRange$endOffset = textRange.endOffset) !== null && _textRange$endOffset !== void 0 ? _textRange$endOffset : textRange.startOffset;
1839
+ return {
1840
+ ...textRange,
1841
+ endOffset,
1842
+ collapsed: (_textRange$collapsed = textRange.collapsed) !== null && _textRange$collapsed !== void 0 ? _textRange$collapsed : textRange.startOffset === endOffset,
1843
+ segmentId: (_textRange$segmentId = textRange.segmentId) !== null && _textRange$segmentId !== void 0 ? _textRange$segmentId : ""
1844
+ };
1845
+ }
1775
1846
 
1776
1847
  //#endregion
1777
- export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, generateParagraphs, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing };
1848
+ export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformToDocDrawingPosition };
@@ -47,4 +47,5 @@ export { generateParagraphs } from './utils/paragraphs';
47
47
  export { replaceSelectionFactory } from './utils/replace-selection-factory';
48
48
  export { createSectionColumnProperties } from './utils/section-columns';
49
49
  export { getTopLevelSectionBreaks } from './utils/sections';
50
- export { consumeContentInsertRange, isHeaderFooterSelection } from './utils/util';
50
+ export { buildDocTransform, docDrawingPositionToTransform, transformToDocDrawingPosition } from './utils/transform-position';
51
+ export { consumeContentInsertRange, getContentInsertRange, isHeaderFooterSelection, normalizeTextRange } from './utils/util';
@@ -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 { IDocDrawingPosition, ITransformState } from '@univerjs/core';
17
+ export declare function buildDocTransform(width: number, height: number, position?: {
18
+ left?: number;
19
+ top?: number;
20
+ }): IDocDrawingPosition;
21
+ export declare function docDrawingPositionToTransform(position: IDocDrawingPosition): ITransformState;
22
+ export declare function transformToDocDrawingPosition(transform: ITransformState, marginLeft?: number, marginTop?: number): IDocDrawingPosition;
@@ -13,7 +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 { IAccessor } from '@univerjs/core';
16
+ import type { IAccessor, ITextRangeParam } from '@univerjs/core';
17
17
  import type { ITextRangeWithStyle } from '@univerjs/engine-render';
18
- export declare function consumeContentInsertRange(accessor: IAccessor, unitId: string): import("..").IDocContentInsertRange | null;
18
+ import type { IDocContentInsertRange } from '../services/doc-content-insert.service';
19
+ export declare function consumeContentInsertRange(accessor: IAccessor, unitId: string): IDocContentInsertRange | null;
20
+ export declare function getContentInsertRange(accessor: IAccessor, unitId?: string): (IDocContentInsertRange & {
21
+ collapsed: boolean;
22
+ }) | null;
19
23
  export declare function isHeaderFooterSelection(range?: ITextRangeWithStyle): boolean;
24
+ export declare function normalizeTextRange(textRange: ITextRangeParam): ITextRangeParam;
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocs={},e.UniverCore,e.UniverEngineRender,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i={id:`doc.operation.set-selections`,type:t.CommandType.OPERATION,handler:()=>!0};function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends t.RxDisposable{constructor(e,t){super(),this._commandService=e,this._univerInstanceService=t,c(this,`_currentSelection`,null),c(this,`_textSelectionInfo`,new Map),c(this,`_textSelection$`,new r.Subject),c(this,`textSelection$`,this._textSelection$.asObservable()),c(this,`_refreshSelection$`,new r.BehaviorSubject(null)),c(this,`refreshSelection$`,this._refreshSelection$.asObservable()),this._listenCurrentUnit()}_listenCurrentUnit(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{if(e==null)return;let t=e.getUnitId();this._setCurrentSelectionNotRefresh({unitId:t,subUnitId:t})})}__getCurrentSelection(){return this._currentSelection}getSelectionInfo(e=this._currentSelection){return this._getTextRanges(e)}refreshSelection(e=this._currentSelection){e!=null&&this._refresh(e)}__TEST_ONLY_setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}getTextRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.textRanges}getRectRanges(e=this._currentSelection){var t;return(t=this._getTextRanges(e))==null?void 0:t.rectRanges}getDocRanges(e=this._currentSelection){var t,n;let r=(t=this.getTextRanges(e))==null?[]:t,i=(n=this.getRectRanges(e))==null?[]:n;return[...r,...i].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0)}getActiveTextRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{textRanges:t}=e;return t.find(e=>e.isActive)}getActiveRectRange(){let e=this._getTextRanges(this._currentSelection);if(e==null)return;let{rectRanges:t}=e;return t.find(e=>e.isActive)}__TEST_ONLY_add(e,t=!0){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,rectRanges:[],segmentId:``,segmentPage:-1,isEditing:t,style:n.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e,t=!0,n){return this.replaceDocRanges(e,this._currentSelection,t,n)}replaceDocRanges(e,t=this._currentSelection,n=!0,r){if(t==null)return;let{unitId:i,subUnitId:a}=t;this._refreshSelection$.next({unitId:i,subUnitId:a,docRanges:e,isEditing:n,options:r})}__replaceTextRangesWithNoRefresh(e,t){if(this._currentSelection==null)return;let n={...e,...t};this._replaceByParam(n),this._textSelection$.next(n);let{unitId:r,subUnitId:a,segmentId:o,style:s,textRanges:c,rectRanges:l,isEditing:u}=n,d=[...c,...l].filter(e=>e.startOffset!=null&&e.endOffset!=null).sort((e,t)=>e.startOffset>t.startOffset?1:e.startOffset<t.startOffset?-1:0);this._commandService.executeCommand(i.id,{unitId:r,subUnitId:a,segmentId:o,style:s,isEditing:u,ranges:d})}dispose(){this._textSelection$.complete(),this._refreshSelection$.complete()}_setCurrentSelectionNotRefresh(e){this._currentSelection=e}_getTextRanges(e){var t;if(e==null)return;let{unitId:n,subUnitId:r=``}=e;return(t=this._textSelectionInfo.get(n))==null?void 0:t.get(r)}_refresh(e){let t=this._getTextRanges(e);if(t==null)return;let{textRanges:n,rectRanges:r}=t,i=[...n,...r],{unitId:a,subUnitId:o}=e;this._refreshSelection$.next({unitId:a,subUnitId:o,docRanges:i,isEditing:!1})}_replaceByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,{...r})}_addByParam(e){let{unitId:t,subUnitId:n,...r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);let i=this._textSelectionInfo.get(t);i.has(n)?i.get(n).textRanges.push(...e.textRanges):i.set(n,{...r})}};d=u([l(0,t.ICommandService),l(1,t.IUniverInstanceService)],d);let f=class extends t.RxDisposable{constructor(e,n,i){super(),this._context=e,this._localeService=n,this._univerInstanceService=i,c(this,`_skeleton`,void 0),c(this,`_docViewModel`,void 0),c(this,`_currentSkeleton$`,new r.BehaviorSubject(null)),c(this,`currentSkeleton$`,this._currentSkeleton$.asObservable()),c(this,`_currentSkeletonBefore$`,new r.BehaviorSubject(null)),c(this,`currentSkeletonBefore$`,this._currentSkeletonBefore$.asObservable()),c(this,`_currentViewModel$`,new r.BehaviorSubject(null)),c(this,`currentViewModel$`,this._currentViewModel$.asObservable()),this._init(),this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC).pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{e&&e.getUnitId()===this._context.unitId&&this._update(e)})}dispose(){super.dispose(),this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete()}getSkeleton(){return this._skeleton}getViewModel(){return this._docViewModel}_init(){let e=this._context.unit;this._update(e)}_update(e){let n=this._context.unitId;if(e.getBody()==null)return;this._docViewModel&&(0,t.isInternalEditorID)(n)?(this._docViewModel.reset(e),this._context.unit=e):this._docViewModel||(this._docViewModel=this._buildDocViewModel(e)),this._skeleton||(this._skeleton=this._buildSkeleton(this._docViewModel));let r=this._skeleton;r.calculate(),this._currentSkeletonBefore$.next(r),this._currentSkeleton$.next(r),this._currentViewModel$.next(this._docViewModel)}_buildSkeleton(e){return n.DocumentSkeleton.create(e,this._localeService)}_buildDocViewModel(e){return new n.DocumentViewModel(e)}};f=u([l(1,(0,t.Inject)(t.LocaleService)),l(2,t.IUniverInstanceService)],f);var p=class extends t.RxDisposable{constructor(){super(),c(this,`_docStateChangeParams$`,new r.BehaviorSubject(null)),c(this,`docStateChangeParams$`,this._docStateChangeParams$.asObservable())}emitStateChangeInfo(e){this._docStateChangeParams$.next(e)}dispose(){super.dispose(),this._docStateChangeParams$.complete()}};let m=`doc.mutation.rich-text-editing`;function h(e,t){if(!t)return`body`;let{headers:n,footers:r}=e.getSnapshot();return n!=null&&n[t]?`header`:r!=null&&r[t]?`footer`:`body`}function g(e,n){let r=e.getSelfOrHeaderFooterModel(n),i=r==null?void 0:r.getBody();if(!i)return;let a=h(e,n),o=(0,t.validateDocBodyStructure)(i,{segmentType:a,segmentId:n||void 0});if(!o.length)return;let s=o.map(e=>`${e.code}${e.index==null?``:`@${e.index}`}`).join(`, `),c=n?`${a} ${n}`:a;throw Error(`[DocStructure] ${c}: ${s}`)}let _={id:m,type:t.CommandType.MUTATION,handler:(e,r,i)=>{var a,o;let{unitId:s,segmentId:c=``,actions:l,textRanges:u,prevTextRanges:h,trigger:_,noHistory:v,isCompositionEnd:y,noNeedSetTextRange:b,debounce:x,isEditing:S=!0,isSync:C,syncer:w}=r,T=C||(i==null?void 0:i.fromCollab)||(i==null?void 0:i.fromChangeset),E=e.get(t.IUniverInstanceService),D=e.get(n.IRenderManagerService),O=e.get(p),k=E.getUnit(s,t.UniverInstanceType.UNIVER_DOC),A=(a=D.getRenderUnitById(s))==null?void 0:a.with(f).getViewModel();if(k==null)throw Error(`DocumentDataModel not found for unitId: ${s}`);let j=e.get(d),M=(o=j.getDocRanges())==null?[]:o,N=!!k.getSnapshot().disabled;if(t.JSONX.isNoop(l)||l&&l.length===0||N)return{unitId:s,actions:[],textRanges:M};let P=t.JSONX.invertWithDoc(l,k.getSnapshot());k.apply(l);try{g(k,c)}catch(e){throw k.apply(P),e}A==null||A.reset(k),!b&&u&&_!=null&&!T&&queueMicrotask(()=>{j.replaceDocRanges(u,{unitId:s,subUnitId:s},S,r.options)});let F={commandId:m,unitId:s,segmentId:c,trigger:_,noHistory:v,debounce:x,redoState:{actions:l,textRanges:u},undoState:{actions:P,textRanges:h==null?M:h},isCompositionEnd:y,isSync:T,syncer:w};return O.emitStateChangeInfo(F),{unitId:s,actions:P,textRanges:M}}},v={id:`doc.command.insert-text`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i,a;let o=e.get(t.ICommandService),{range:s,segmentId:c,body:l,unitId:u,cursorOffset:f}=n,p=e.get(d),m=e.get(t.IUniverInstanceService).getUnit(u,t.UniverInstanceType.UNIVER_DOC);if(m==null)return!1;let h=p.getActiveTextRange(),g=`segmentId`in s?s.segmentId:void 0,v=(r=(i=c==null?g:c)==null?h==null?void 0:h.segmentId:i)==null?``:r,y=(a=m.getSelfOrHeaderFooterModel(v))==null?void 0:a.getBody();if(y==null)return!1;let{startOffset:b,collapsed:x}=s,S=f==null?l.dataStream.length:f,C=[{startOffset:b+S,endOffset:b+S,style:h==null?void 0:h.style,collapsed:x}],w={id:_.id,params:{unitId:u,actions:[],textRanges:C,debounce:!0}},T=new t.TextX,E=t.JSONX.getInstance();if(x)b>0&&T.push({t:t.TextXActionType.RETAIN,len:b}),T.push({t:t.TextXActionType.INSERT,body:l,len:l.dataStream.length});else{let e=t.BuildTextUtils.selection.delete([s],y,0,l);T.push(...e)}w.params.textRanges=[{startOffset:b+S,endOffset:b+S,collapsed:x}];let D=(0,t.getRichTextEditPath)(m,c);return w.params.actions=E.editOp(T.serialize(),D),!!o.syncExecuteCommand(w.id,w.params)}},y={id:`doc.command.delete-text`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i;let a=e.get(t.ICommandService),o=e.get(t.IUniverInstanceService),{range:s,segmentId:c,unitId:l,direction:u,len:d=1}=n,f=o.getUnit(l,t.UniverInstanceType.UNIVER_DOC),p=f==null||(r=f.getSelfOrHeaderFooterModel(c))==null?void 0:r.getBody();if(f==null||p==null)return!1;let{startOffset:m}=s,h=u===t.DeleteDirection.LEFT?m-d:m,g=u===t.DeleteDirection.LEFT?m-1:m+d-1,v=(i=p.customRanges)==null?void 0:i.find(e=>e.startIndex<=h&&e.endIndex>=g);v!=null&&v.wholeEntity&&(h=v.startIndex,g=Math.max(g,v.endIndex));let y={id:_.id,params:{unitId:l,actions:[],textRanges:[{startOffset:h,endOffset:h,collapsed:!0}],debounce:!0}},b=new t.TextX,x=t.JSONX.getInstance();b.push(...t.BuildTextUtils.selection.delete([{...s,startOffset:h,endOffset:g+1,collapsed:!1}],p));let S=(0,t.getRichTextEditPath)(f,c);return y.params.actions=x.editOp(b.serialize(),S),!!a.syncExecuteCommand(y.id,y.params)}},b={id:`doc.command.update-text`,type:t.CommandType.COMMAND,handler:(e,n)=>{let{range:r,segmentId:i,updateBody:a,coverType:o,unitId:s,textRanges:c}=n,l=e.get(t.ICommandService),u=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;let d={id:_.id,params:{unitId:s,actions:[],textRanges:c}},f=new t.TextX,p=t.JSONX.getInstance(),{startOffset:m,endOffset:h}=r;f.push({t:t.TextXActionType.RETAIN,len:m}),f.push({t:t.TextXActionType.RETAIN,body:a,len:h-m,coverType:o});let g=(0,t.getRichTextEditPath)(u,i);return d.params.actions=p.editOp(f.serialize(),g),!!l.syncExecuteCommand(d.id,d.params)}},x=function(e){return e[e.FIRST_PAGE_HEADER=0]=`FIRST_PAGE_HEADER`,e[e.FIRST_PAGE_FOOTER=1]=`FIRST_PAGE_FOOTER`,e[e.DEFAULT_HEADER=2]=`DEFAULT_HEADER`,e[e.DEFAULT_FOOTER=3]=`DEFAULT_FOOTER`,e[e.EVEN_PAGE_HEADER=4]=`EVEN_PAGE_HEADER`,e[e.EVEN_PAGE_FOOTER=5]=`EVEN_PAGE_FOOTER`,e}({});function S(){return{dataStream:`\r
2
- `,textRuns:[{st:0,ed:0,ts:{fs:9}}],customBlocks:[],paragraphs:[{startIndex:0,paragraphId:(0,t.createParagraphId)(new Set),paragraphStyle:{spaceAbove:{v:0},lineSpacing:1.5,spaceBelow:{v:0}}}],sectionBreaks:[{sectionId:(0,t.createSectionId)(new Set),startIndex:1}]}}function C(e,n,r,i,a=`single`,o=[`documentStyle`]){let s=t.JSONX.getInstance(),c=e==null?(0,t.generateRandomId)(6):e,l=n===2||n===0||n===4,u=s.insertOp([l?`headers`:`footers`,c],{[l?`headerId`:`footerId`]:c,body:S()});i.push(u);let d=`defaultHeaderId`,f=`defaultFooterId`;switch(n){case 2:d=`defaultHeaderId`,f=`defaultFooterId`;break;case 3:d=`defaultFooterId`,f=`defaultHeaderId`;break;case 0:d=`firstPageHeaderId`,f=`firstPageFooterId`;break;case 1:d=`firstPageFooterId`,f=`firstPageHeaderId`;break;case 4:d=`evenPageHeaderId`,f=`evenPageFooterId`;break;case 5:d=`evenPageFooterId`,f=`evenPageHeaderId`;break;default:throw Error(`Unknown header footer type: ${n}`)}let p=[[d,c]];if(a===`pair`&&f!=null){let e=(0,t.generateRandomId)(6),n=s.insertOp([l?`footers`:`headers`,e],{[l?`footerId`:`headerId`]:e,body:S()});i.push(n),p.push([f,e])}for(let[e,t]of p)if(r[e]!=null){let n=s.replaceOp([...o,e],r[e],t);i.push(n)}else{let n=s.insertOp([...o,e],t);i.push(n)}return i}let w={id:`doc.command.create-header-footer`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i,a;let o=e.get(t.ICommandService),s=e.get(t.IUniverInstanceService),{unitId:c,segmentId:l,createType:u,headerFooterProps:d,createMode:f=`single`,sectionId:p}=n,m=s.getUnit(c,t.UniverInstanceType.UNIVER_DOC);if(m==null)return!1;let{documentStyle:h,body:g}=m.getSnapshot();if(h.documentFlavor===t.DocumentFlavor.MODERN)return!1;let v=[],y=t.JSONX.getInstance(),b=p==null||(r=g==null||(i=g.sectionBreaks)==null?void 0:i.findIndex(e=>e.sectionId===p))==null?-1:r,x=b<0||g==null||(a=g.sectionBreaks)==null?void 0:a[b];if(p!=null&&!x)return!1;let S=x==null?h:x,w=p==null?[`documentStyle`]:[`body`,`sectionBreaks`,b];if(u!=null&&C(l,u,S,v,f,w),d!=null&&Object.keys(d).forEach(e=>{let t=d[e],n=S[e];if(t===n)return;let r=n===void 0?y.insertOp([...w,e],t):y.replaceOp([...w,e],n,t);v.push(r)}),v.length===0)return!1;let T={id:_.id,params:{unitId:c,actions:v.reduce((e,n)=>t.JSONX.compose(e,n),null),textRanges:[{startOffset:0,endOffset:0,collapsed:!0}],debounce:!0}};return((d==null?void 0:d.marginFooter)!=null||(d==null?void 0:d.marginHeader)!=null)&&(T.params.noNeedSetTextRange=!0),!!o.syncExecuteCommand(T.id,T.params)}},T={id:`doc.command.set-default-paragraph-style`,type:t.CommandType.COMMAND,handler:(e,n)=>{if(n==null)return!1;let r=e.get(t.ICommandService),i=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);if(i==null)return!1;let a=i.getSnapshot().documentStyle.defaultParagraphStyle,o=t.JSONX.getInstance(),s=[`documentStyle`,`defaultParagraphStyle`],c=[];if(n.defaultParagraphStyle==null)a!=null&&c.push(o.removeOp(s,a));else if(a==null){let e=Object.fromEntries(Object.entries(n.defaultParagraphStyle).filter(([,e])=>e!=null).map(([e,n])=>[e,t.Tools.deepClone(n)]));Object.keys(e).length>0&&c.push(o.insertOp(s,e))}else Object.entries(n.defaultParagraphStyle).forEach(([e,n])=>{let r=a[e],i=[...s,e];n==null?r!=null&&c.push(o.removeOp(i,r)):r==null?c.push(o.insertOp(i,t.Tools.deepClone(n))):c.push(o.replaceOp(i,r,t.Tools.deepClone(n)))});let l=c.reduce((e,n)=>t.JSONX.compose(e,n),null);if(c.length===0||t.JSONX.isNoop(l))return!1;let u={id:_.id,params:{unitId:n.unitId,actions:l,textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1}};return!!r.syncExecuteCommand(u.id,u.params)}};function E(e){var n;let r=new Map(((n=e.sectionBreaks)==null?[]:n).map(e=>[e.startIndex,e])),i=[],a=0,o=0;for(let n=0;n<e.dataStream.length;n++){let s=e.dataStream[n];if(s===t.DataStreamTreeTokenType.TABLE_CELL_START)a++;else if(s===t.DataStreamTreeTokenType.TABLE_CELL_END)a=Math.max(0,a-1);else if(s===t.DataStreamTreeTokenType.COLUMN_START)o++;else if(s===t.DataStreamTreeTokenType.COLUMN_END)o=Math.max(0,o-1);else if(s===t.DataStreamTreeTokenType.SECTION_BREAK&&a===0&&o===0){let e=r.get(n);e&&i.push(e)}}return i}let D={id:`doc.command.set-section-header-footer-link`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i;if(!n)return!1;let a=e.get(t.IUniverInstanceService),o=e.get(t.ICommandService),s=a.getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC),c=s==null?void 0:s.getSnapshot();if(!s||!(c!=null&&c.body)||c.documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)return!1;let l=E(c.body),u=l.findIndex(e=>e.sectionId===n.sectionId);if(u<=0)return!1;let d=(r=(i=c.body.sectionBreaks)==null?void 0:i.findIndex(e=>e.sectionId===n.sectionId))==null?-1:r;if(d<0)return!1;let f={snapshot:c,sections:l,sectionIndex:u,storageIndex:d,key:(0,t.getSectionHeaderFooterReferenceKey)(n.kind,n.variant)},p=n.linkedToPrevious?O(f,n.kind):k(f,n.kind,n.segmentId);if(!p)return!1;let m={id:_.id,params:{unitId:n.unitId,actions:p.reduce((e,n)=>t.JSONX.compose(e,n),null),textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1,trigger:D.id}};return!!o.syncExecuteCommand(m.id,m.params)}};function O(e,n){let{snapshot:r,sections:i,sectionIndex:a,storageIndex:o,key:s}=e,c=i[a],l=c[s];if(typeof l!=`string`||!l)return null;let u=t.JSONX.getInstance(),d=[u.removeOp([`body`,`sectionBreaks`,o,s],l)],f=n===`header`?[`defaultHeaderId`,`firstPageHeaderId`,`evenPageHeaderId`]:[`defaultFooterId`,`firstPageFooterId`,`evenPageFooterId`],p=f.some(e=>r.documentStyle[e]===l),m=i.some(e=>f.some(t=>!(e.sectionId===c.sectionId&&t===s)&&e[t]===l)),h=n===`header`?r.headers:r.footers;return!p&&!m&&h!=null&&h[l]&&d.push(u.removeOp([n===`header`?`headers`:`footers`,l],h[l])),d}function k(e,n,r){let{snapshot:i,sections:a,sectionIndex:o,storageIndex:s,key:c}=e,l=a[o][c];if(typeof l==`string`&&l)return null;let u=(0,t.resolveSectionHeaderFooterReference)(i.documentStyle,a,o-1,c).segmentId,d=r==null?(0,t.generateRandomId)(6):r,f=n===`header`?i.headers:i.footers;if(f!=null&&f[d])return null;let p=u?f==null?void 0:f[u]:void 0,m=n===`header`?`headerId`:`footerId`,h=p?{...t.Tools.deepClone(p),[m]:d}:{[m]:d,body:S()},g=t.JSONX.getInstance();return[g.insertOp([n===`header`?`headers`:`footers`,d],h),g.insertOp([`body`,`sectionBreaks`,s,c],d)]}let A={id:`doc.command.update-section`,type:t.CommandType.COMMAND,handler:(e,n)=>{if(!(n!=null&&n.updates.length)||n.updates.some(({sectionId:e,config:t})=>!e||Object.keys(t).length===0))return!1;let r=e.get(t.IUniverInstanceService),i=e.get(t.ICommandService),a=r.getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);if(!a||a.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL)return!1;let o=a.getBody();if(!o)return!1;let s=new Map(n.updates.map(({sectionId:e,config:t})=>[e,t]));if(s.size!==n.updates.length)return!1;let c=new Set(s.keys()),l=E(o).filter(e=>c.has(e.sectionId)).sort((e,t)=>e.startIndex-t.startIndex);if(l.length!==c.size)return!1;let u=new t.MemoryCursor,d=new t.TextX;for(let e of l)d.push({t:t.TextXActionType.RETAIN,len:e.startIndex-u.cursor}),d.push({t:t.TextXActionType.RETAIN,len:1,coverType:t.UpdateDocsAttributeType.REPLACE,body:{dataStream:``,sectionBreaks:[{...t.Tools.deepClone(e),...t.Tools.deepClone(s.get(e.sectionId)),sectionId:e.sectionId,startIndex:0}]}}),u.moveCursorTo(e.startIndex+1);let f=t.JSONX.getInstance(),p={id:_.id,params:{unitId:n.unitId,actions:f.editOp(d.serialize(),(0,t.getRichTextEditPath)(a)),textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1,trigger:A.id}};return!!i.syncExecuteCommand(p.id,p.params)}},j={id:`doc.command.insert-section-break`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i,a,o,s;if(!n)return!1;let c=N(e,n.unitId);if(!c||!n.sectionId||!Number.isInteger(n.offset))return!1;let{body:l,documentDataModel:u,commandService:d}=c;if(n.offset<0||n.offset>l.dataStream.length||(r=l.sectionBreaks)!=null&&r.some(e=>e.sectionId===n.sectionId)||(i=l.tables)!=null&&i.some(e=>(0,t.containsInteriorInsertionOffset)((0,t.getTableRangeInterval)(e),n.offset))||(a=l.columnGroups)!=null&&a.some(e=>(0,t.containsInteriorInsertionOffset)((0,t.getColumnGroupRangeInterval)(e),n.offset))||(o=l.blockRanges)!=null&&o.some(e=>(0,t.containsInteriorInsertionOffset)((0,t.getBlockRangeInterval)(e),n.offset)))return!1;let f=new t.TextX;return f.retain(n.offset),f.insert(1,{dataStream:t.DataStreamTreeTokenType.SECTION_BREAK,sectionBreaks:[{...t.Tools.deepClone((s=n.config)==null?{}:s),sectionId:n.sectionId,startIndex:0}]}),P(d,u,f,j.id)}},M={id:`doc.command.delete-section-break`,type:t.CommandType.COMMAND,handler:(e,n)=>{if(!n)return!1;let r=N(e,n.unitId);if(!r||!n.sectionId)return!1;let i=E(r.body);if(i.length<=1)return!1;let a=i.find(e=>e.sectionId===n.sectionId);if(!a)return!1;let o=new t.TextX;return o.retain(a.startIndex),o.delete(1),P(r.commandService,r.documentDataModel,o,M.id)}};function N(e,n){if(!n)return null;let r=e.get(t.IUniverInstanceService).getUnit(n,t.UniverInstanceType.UNIVER_DOC),i=r==null?void 0:r.getBody();return!r||!i||r.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL?null:{body:i,documentDataModel:r,commandService:e.get(t.ICommandService)}}function P(e,n,r,i){let a=t.JSONX.getInstance().editOp(r.serialize(),(0,t.getRichTextEditPath)(n));return!!e.syncExecuteCommand(_.id,{unitId:n.getUnitId(),actions:a,textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1,trigger:i})}let F=`UniverEmbedDocsCustomBlock`,ee={width:720,height:360},te={width:960,height:480},ne={width:720,height:405};function re(e){return H(e.unitId,e.segmentId,I(e))}function ie(e){return H(e.unitId,e.segmentId,L(e))}function I(e){let n=new t.TextX;return e.startIndex>0&&n.push({t:t.TextXActionType.RETAIN,len:e.startIndex}),n.push({t:t.TextXActionType.INSERT,body:{dataStream:`\b`,customBlocks:[{startIndex:0,blockId:e.blockId}]},len:1}),W([U(n,e.segmentId),se(e)])}function L(e){let n=new t.TextX;return e.startIndex>0&&n.push({t:t.TextXActionType.RETAIN,len:e.startIndex}),n.push({t:t.TextXActionType.DELETE,len:1}),W([U(n,e.segmentId),ce(e)])}function R(e){var n;let r=z(e.childType),i=e.interactionMode===`inline`;return{unitId:e.unitId,subUnitId:e.unitId,drawingId:e.blockId,drawingType:t.DrawingTypeEnum.DRAWING_DOM,componentKey:(n=e.componentKey)==null?F:n,data:B(e),title:e.blockId,description:`Univer embedded unit custom block`,layoutType:i?t.PositionedObjectLayoutType.INLINE:t.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM,allowTransform:!1,docTransform:{size:{width:r.width,height:r.height},positionH:{relativeFrom:i?t.ObjectRelativeFromH.PAGE:t.ObjectRelativeFromH.COLUMN,...i?{posOffset:0}:{align:t.AlignTypeH.LEFT}},positionV:{relativeFrom:i?t.ObjectRelativeFromV.PAGE:t.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},transform:{left:0,top:0,width:r.width,height:r.height}}}function z(e){return e===t.UniverInstanceType.UNIVER_SHEET||e===t.UniverInstanceType.UNIVER_BASE?te:e===t.UniverInstanceType.UNIVER_SLIDE?ne:ee}function ae(e){return e===t.UniverInstanceType.UNIVER_SHEET||e===t.UniverInstanceType.UNIVER_BASE}function B(e){var t,n;return{version:1,embedId:(t=e.embedId)==null?e.blockId:t,hostUnitId:e.unitId,hostAnchorId:e.blockId,childUnitId:e.childUnitId,childType:e.childType,interactionMode:(n=e.interactionMode)==null?`block`:n}}function V(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.version===1&&typeof t.embedId==`string`&&typeof t.hostAnchorId==`string`}function oe(e){let t=e&&typeof e==`object`?e.data:void 0;return V(t)?t.interactionMode===`inline`:!0}function H(e,t,n){return{id:_.id,params:{unitId:e,segmentId:t,actions:n,textRanges:[],isEditing:!1,noNeedSetTextRange:!0}}}function U(e,n){let r=t.JSONX.getInstance().editOp(e.serialize(),n?[`headers`,n,`body`]:[`body`]);return r==null?[]:r}function se(e){var n,r,i;if(e.segmentId)return[];let a=t.JSONX.getInstance(),o=R(e);return W([(n=a.insertOp([`drawings`,e.blockId],o))==null?[]:n,(r=a.insertOp([`drawingsOrder`,(i=e.drawingOrderIndex)==null?0:i],e.blockId))==null?[]:r])}function ce(e){var n,r,i;if(e.segmentId)return[];let a=t.JSONX.getInstance(),o=R(e);return W([(n=a.removeOp([`drawings`,e.blockId],o))==null?[]:n,(r=a.removeOp([`drawingsOrder`,(i=e.drawingOrderIndex)==null?0:i],e.blockId))==null?[]:r])}function W(e){return e.reduce((e,n)=>{var r;return!n||t.JSONX.isNoop(n)||n.length===0?e:!e||t.JSONX.isNoop(e)||e.length===0?n:(r=t.JSONX.compose(e,n))==null?[]:r},[])}var le=`@univerjs/docs`,ue=`1.0.0-alpha.3`;let de={id:`doc.mutation.rename-doc`,type:t.CommandType.MUTATION,handler:(e,n)=>{let r=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);return r?(r.setName(n.name),!0):!1}},G={},K=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._initSelectionChange()}_transformCustomRange(e,n){var r;let{startOffset:i,endOffset:a,collapsed:o}=n,s=(r=e.getCustomRanges())==null?void 0:r.filter(e=>!e.wholeEntity||i<=e.startIndex&&a>e.endIndex?!1:o?e.startIndex<i&&e.endIndex>=a:t.BuildTextUtils.range.isIntersects(i,a-1,e.startIndex,e.endIndex));if(s!=null&&s.length){let e=i,t=a;return s.forEach(n=>{e=Math.min(n.startIndex,e),t=Math.max(n.endIndex+1,t)}),{...n,startOffset:e,endOffset:t,collapsed:e===t}}return n}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.id){let{unitId:t,ranges:n,isEditing:r}=e.params,i=this._univerInstanceService.getUnit(t);if(!i)return;let a=n.map(e=>this._transformCustomRange(i,e));a.some((e,t)=>n[t]!==e)&&this._textSelectionManagerService.replaceTextRanges(a,r)}}))}};K=u([l(0,t.ICommandService),l(1,(0,t.Inject)(d)),l(2,t.IUniverInstanceService)],K);var q=class extends t.Disposable{constructor(...e){super(...e),c(this,`_validators`,[]),c(this,`_transformers`,[])}registerValidator(e){return this._validators.push(e),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._validators,e)))}registerTransformer(e){return this._transformers.push(e),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._transformers,e)))}canMoveBlock(e){return this._validators.every(t=>t(e))}transformMoveResult(e){return this._transformers.reduce((t,n)=>n({...e,result:t}),e.result)}},J=class extends t.Disposable{constructor(...e){super(...e),c(this,`_range`,null)}setInsertRange(e){this._range=e}consumeInsertRange(e){if(!this._range||e&&this._range.unitId!==e)return null;let t=this._range;return this._range=null,t}clearInsertRange(){this._range=null}};let Y=(0,t.createIdentifier)(`doc.state-change-interceptor-service`),X=class extends t.RxDisposable{constructor(e,t,n,i,a){super(),this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._docStateEmitService=i,this._docStateChangeInterceptorService=a,c(this,`_docStateChange$`,new r.BehaviorSubject(null)),c(this,`docStateChange$`,this._docStateChange$.asObservable()),c(this,`_historyStateCache`,new Map),c(this,`_changeStateCache`,new Map),c(this,`_historyTimer`,null),c(this,`_changeStateCacheTimer`,null),this._initialize(),this._listenDocStateChange()}getStateCache(e){var t,n;return{history:(t=this._historyStateCache.get(e))==null?[]:t,collaboration:(n=this._changeStateCache.get(e))==null?[]:n}}setStateCache(e,t){this._historyStateCache.set(e,t.history),this._changeStateCache.set(e,t.collaboration)}_setChangeState(e){this._cacheChangeState(e,`history`),this._cacheChangeState(e,`collaboration`)}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===t.UndoCommandId||e.id===t.RedoCommandId){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(e==null)return;let n=e.getUnitId();this._pushHistory(n),this._emitChangeState(n)}}))}_listenDocStateChange(){this._docStateEmitService.docStateChangeParams$.pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{var t,n;if(e==null)return;let r=(t=(n=this._docStateChangeInterceptorService)==null?void 0:n.transformChangeStateInfo(e))==null?e:t;if(r==null||r.isSync)return;let{isCompositionEnd:i,isSync:a,syncer:o,...s}=r;this._setChangeState(s)})}_cacheChangeState(e,n=`history`){let{trigger:r,unitId:i,noHistory:a,debounce:o=!1}=e;if(a||n===`history`&&r==null||n===`history`&&(r===t.RedoCommandId||r===t.UndoCommandId))return;let s=n===`history`?this._historyStateCache:this._changeStateCache,c=n===`history`?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(s.has(i)){let t=s.get(i);t==null||t.push(e)}else s.set(i,[e]);o?n===`history`?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{c(i)},300)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{c(i)},300)):c(i)}_pushHistory(e){let n=this._undoRedoService,r=this._historyStateCache.get(e);if(n==null||!Array.isArray(r)||r.length===0)return;let i=r.length,a=r[0].commandId,o=r[0],s=r[i-1],c={unitId:e,actions:r.reduce((e,n)=>t.JSONX.compose(e,n.redoState.actions),null),textRanges:s.redoState.textRanges},l={unitId:e,actions:r.reverse().reduce((e,n)=>t.JSONX.compose(e,n.undoState.actions),null),textRanges:o.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:l}],redoMutations:[{id:a,params:c}]}),r.length=0}_emitChangeState(e){let n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;let r=n.length,{commandId:i,trigger:a,segmentId:o,noHistory:s,debounce:c}=n[0],l=n[0],u=n[r-1],d={commandId:i,unitId:e,trigger:a,redoState:{unitId:e,actions:n.reduce((e,n)=>t.JSONX.compose(e,n.redoState.actions),null),textRanges:u.redoState.textRanges},undoState:{unitId:e,actions:n.reverse().reduce((e,n)=>t.JSONX.compose(e,n.undoState.actions),null),textRanges:l.undoState.textRanges},segmentId:o,noHistory:s,debounce:c};n.length=0,this._docStateChange$.next(d)}};X=u([l(0,(0,t.Optional)(t.IUndoRedoService)),l(1,t.ICommandService),l(2,t.IUniverInstanceService),l(3,(0,t.Inject)(p)),l(4,(0,t.Optional)(Y))],X);let Z=class extends t.Plugin{constructor(e=G,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},G,this._config);this._configService.setConfig(`docs.config`,i)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[v,y,b,w,T,D,A,j,M,_,de,i].forEach(e=>{this._injector.get(t.ICommandService).registerCommand(e)})}_initializeDependencies(){[[d],[p],[X],[q],[J],[K]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(X),this._injector.get(K)}};c(Z,`pluginName`,`DOCS_PLUGIN`),c(Z,`packageName`,le),c(Z,`version`,ue),Z=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.IConfigService)],Z);let Q={CUSTOM_RANGE:(0,t.createInterceptorKey)(`CUSTOM_RANGE`),CUSTOM_DECORATION:(0,t.createInterceptorKey)(`CUSTOM_DECORATION`)},$=class extends t.Disposable{constructor(e,n){super(),this._context=e,this._docSkeletonManagerService=n,c(this,`_interceptorsByName`,new Map);let r=this._docSkeletonManagerService.getViewModel(),i=r.getDataModel().getUnitId();if(i===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(r)),this.disposeWithMe(this.intercept(Q.CUSTOM_RANGE,{priority:-1,handler:(e,t,n)=>n(e)}));let a=new t.DisposableCollection;r.segmentViewModels$.subscribe(e=>{a.dispose(),a=new t.DisposableCollection,e.forEach(e=>{a.add(this.interceptDocumentViewModel(e))})}),this.disposeWithMe(a)}intercept(e,n){let r=e;this._interceptorsByName.has(r)||this._interceptorsByName.set(r,[]);let i=this._interceptorsByName.get(r);return i.push(n),this._interceptorsByName.set(r,i.sort((e,t)=>{var n,r;return((n=t.priority)==null?0:n)-((r=e.priority)==null?0:r)})),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._interceptorsByName.get(r),n)))}fetchThroughInterceptors(e){let n=e;return(0,t.composeInterceptors)(this._interceptorsByName.get(n)||[])}interceptDocumentViewModel(e){let n=new t.DisposableCollection;return n.add(e.registerCustomRangeInterceptor({getCustomRange:t=>{var n;return this.fetchThroughInterceptors(Q.CUSTOM_RANGE)(e.getCustomRangeRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customRanges:(n=e.getDataModel().getCustomRanges())==null?[]:n})},getCustomDecoration:t=>{var n;return this.fetchThroughInterceptors(Q.CUSTOM_DECORATION)(e.getCustomDecorationRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customDecorations:(n=e.getDataModel().getCustomDecorations())==null?[]:n})}})),n}};$=u([l(1,(0,t.Inject)(f))],$);function fe(e,n,r){let{unitId:i,segmentId:a}=n,o=e.get(t.IUniverInstanceService).getUnit(i);if(!o)return!1;let s={id:_.id,params:{unitId:n.unitId,actions:[],textRanges:void 0}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.add({...n,body:r});if(!l)return!1;let u=(0,t.getRichTextEditPath)(o,a);return s.params.actions=c.editOp(l.serialize(),u),s}function pe(e,n){var r,i;let{rangeId:a,rangeType:o,wholeEntity:s,properties:c,unitId:l,selections:u}=n,f=e.get(d),p=e.get(t.IUniverInstanceService),m=u==null?f.getTextRanges({unitId:l,subUnitId:l}):u,h=m==null||(r=m[0])==null?void 0:r.segmentId;if(!(m!=null&&m.length))return!1;let g=p.getUnit(l,t.UniverInstanceType.UNIVER_DOC);if(!g)return!1;let v=(i=g.getSelfOrHeaderFooterModel(h))==null?void 0:i.getBody();if(!v)return!1;let y=t.BuildTextUtils.customRange.add({ranges:m,rangeId:a,rangeType:o,segmentId:h,wholeEntity:s,properties:c,body:v});if(!y)return!1;let b=t.JSONX.getInstance(),x={id:_.id,params:{unitId:l,actions:[],textRanges:y.selections,segmentId:h},textX:y},S=(0,t.getRichTextEditPath)(g,h);return x.params.actions=b.editOp(y.serialize(),S),x}function me(e,n){let{unitId:r,segmentId:i,insert:a}=n,o=e.get(t.IUniverInstanceService).getUnit(r);if(!o)return!1;let s={id:_.id,params:{unitId:n.unitId,actions:[],textRanges:void 0,segmentId:i}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:n.rangeId,insert:a,segmentId:i});if(!l)return!1;let u=(0,t.getRichTextEditPath)(o,i);return s.params.actions=c.editOp(l.serialize(),u),s.params.textRanges=l.selections,s}function he(e,n,r,i=[]){let a=[],o=new Set(i);for(let n=0,r=e.length;n<r;n++)e[n]===t.DataStreamTreeTokenType.PARAGRAPH&&a.push({startIndex:n,paragraphId:(0,t.createParagraphId)(o)});for(let e of a)n!=null&&n.bullet&&(e.bullet=t.Tools.deepClone(n.bullet)),n!=null&&n.paragraphStyle&&(e.paragraphStyle=t.Tools.deepClone(n.paragraphStyle),delete e.paragraphStyle.borderBottom,n.paragraphStyle.headingId&&(e.paragraphStyle.headingId=(0,t.generateRandomId)(6))),r&&(e.paragraphStyle!=null||(e.paragraphStyle={}),e.paragraphStyle.borderBottom=t.Tools.deepClone(r));return a}function ge(e,n){var r,i,a,o;let{unitId:s,body:c,doc:l}=n,u=l;if(u||(u=e.get(t.IUniverInstanceService).getUnit(s)),!u)return!1;let f=(r=n.selection)==null?void 0:r.segmentId,p=(i=u.getSelfOrHeaderFooterModel(f))==null?void 0:i.getBody();if(!p)return!1;let m=e.get(d),h=(a=n.selection)==null?m.getActiveTextRange():a;if(!h||!p)return!1;let g=(o=n.textRanges)==null?[{startOffset:h.startOffset+c.dataStream.length,endOffset:h.startOffset+c.dataStream.length,collapsed:!0,segmentId:f}]:o,v=t.BuildTextUtils.selection.replace({selection:h,body:c,doc:u});if(!v)return!1;let y={id:_.id,params:{unitId:s,actions:[],textRanges:g,debounce:!0,segmentId:f},textX:v},b=t.JSONX.getInstance();return y.params.actions=b.editOp(v.serialize()),y}function _e(e,n,r,i,a){var o,s,c,l,u,d,f,p;if(r<=1)return[];let m=Math.max(0,i),h=(o=(s=n==null||(c=n.pageSize)==null?void 0:c.width)==null?e==null||(l=e.pageSize)==null?void 0:l.width:s)==null?t.PAGE_SIZE[t.PaperType.A4].width:o,g=Math.max(0,h-((u=(d=n==null?void 0:n.marginLeft)==null?e==null?void 0:e.marginLeft:d)==null?72:u)-((f=(p=n==null?void 0:n.marginRight)==null?e==null?void 0:e.marginRight:p)==null?72:f)),_=Math.max(0,g-m*(r-1));return(a==null?Array.from({length:r},()=>_/r):a).map((e,t)=>({width:Math.max(0,e),paddingEnd:t===r-1?0:m}))}function ve(e,t){try{return e.get(J).consumeInsertRange(t)}catch{return null}}function ye(e){return!!(e!=null&&e.segmentId)}e.CreateHeaderFooterCommand=w,e.DOC_INTERCEPTOR_POINT=Q,e.DeleteDocumentSectionBreakCommand=M,e.DeleteTextCommand=y,e.DocBlockMoveValidatorService=q,e.DocContentInsertService=J,Object.defineProperty(e,"DocInterceptorService",{enumerable:!0,get:function(){return $}}),Object.defineProperty(e,"DocSelectionManagerService",{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,"DocSkeletonManagerService",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"DocStateChangeManagerService",{enumerable:!0,get:function(){return X}}),e.DocStateEmitService=p,e.EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY=F,e.HeaderFooterType=x,e.IDocStateChangeInterceptorService=Y,e.InsertDocumentSectionBreakCommand=j,e.InsertTextCommand=v,e.RichTextEditingMutation=_,e.SetDocumentDefaultParagraphStyleCommand=T,e.SetSectionHeaderFooterLinkCommand=D,e.SetTextSelectionsOperation=i,Object.defineProperty(e,"UniverDocsPlugin",{enumerable:!0,get:function(){return Z}}),e.UpdateDocumentSectionCommand=A,e.UpdateTextCommand=b,e.addCustomRangeBySelectionFactory=pe,e.addCustomRangeFactory=fe,e.consumeContentInsertRange=ve,e.createDocsCustomBlockDrawing=R,e.createDocsCustomBlockInsertMutation=re,e.createDocsCustomBlockRemoveMutation=ie,e.createEmbedDocsCustomBlockData=B,e.createInsertCustomBlockActions=I,e.createRemoveCustomBlockActions=L,e.createSectionColumnProperties=_e,e.deleteCustomRangeFactory=me,e.generateParagraphs=he,e.getTopLevelSectionBreaks=E,e.isEmbedDocsCustomBlockData=V,e.isHeaderFooterSelection=ye,e.isSheetLikeDocsCustomBlockChildType=ae,e.replaceSelectionFactory=ge,e.resolveDocsCustomBlockSize=z,e.shouldUseInlineTextSelectionForDocsCustomBlockDrawing=oe});
2
+ `,textRuns:[{st:0,ed:0,ts:{fs:9}}],customBlocks:[],paragraphs:[{startIndex:0,paragraphId:(0,t.createParagraphId)(new Set),paragraphStyle:{spaceAbove:{v:0},lineSpacing:1.5,spaceBelow:{v:0}}}],sectionBreaks:[{sectionId:(0,t.createSectionId)(new Set),startIndex:1}]}}function C(e,n,r,i,a=`single`,o=[`documentStyle`]){let s=t.JSONX.getInstance(),c=e==null?(0,t.generateRandomId)(6):e,l=n===2||n===0||n===4,u=s.insertOp([l?`headers`:`footers`,c],{[l?`headerId`:`footerId`]:c,body:S()});i.push(u);let d=`defaultHeaderId`,f=`defaultFooterId`;switch(n){case 2:d=`defaultHeaderId`,f=`defaultFooterId`;break;case 3:d=`defaultFooterId`,f=`defaultHeaderId`;break;case 0:d=`firstPageHeaderId`,f=`firstPageFooterId`;break;case 1:d=`firstPageFooterId`,f=`firstPageHeaderId`;break;case 4:d=`evenPageHeaderId`,f=`evenPageFooterId`;break;case 5:d=`evenPageFooterId`,f=`evenPageHeaderId`;break;default:throw Error(`Unknown header footer type: ${n}`)}let p=[[d,c]];if(a===`pair`&&f!=null){let e=(0,t.generateRandomId)(6),n=s.insertOp([l?`footers`:`headers`,e],{[l?`footerId`:`headerId`]:e,body:S()});i.push(n),p.push([f,e])}for(let[e,t]of p)if(r[e]!=null){let n=s.replaceOp([...o,e],r[e],t);i.push(n)}else{let n=s.insertOp([...o,e],t);i.push(n)}return i}let w={id:`doc.command.create-header-footer`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i,a;let o=e.get(t.ICommandService),s=e.get(t.IUniverInstanceService),{unitId:c,segmentId:l,createType:u,headerFooterProps:d,createMode:f=`single`,sectionId:p}=n,m=s.getUnit(c,t.UniverInstanceType.UNIVER_DOC);if(m==null)return!1;let{documentStyle:h,body:g}=m.getSnapshot();if(h.documentFlavor===t.DocumentFlavor.MODERN)return!1;let v=[],y=t.JSONX.getInstance(),b=p==null||(r=g==null||(i=g.sectionBreaks)==null?void 0:i.findIndex(e=>e.sectionId===p))==null?-1:r,x=b<0||g==null||(a=g.sectionBreaks)==null?void 0:a[b];if(p!=null&&!x)return!1;let S=x==null?h:x,w=p==null?[`documentStyle`]:[`body`,`sectionBreaks`,b];if(u!=null&&C(l,u,S,v,f,w),d!=null&&Object.keys(d).forEach(e=>{let t=d[e],n=S[e];if(t===n)return;let r=n===void 0?y.insertOp([...w,e],t):y.replaceOp([...w,e],n,t);v.push(r)}),v.length===0)return!1;let T={id:_.id,params:{unitId:c,actions:v.reduce((e,n)=>t.JSONX.compose(e,n),null),textRanges:[{startOffset:0,endOffset:0,collapsed:!0}],debounce:!0}};return((d==null?void 0:d.marginFooter)!=null||(d==null?void 0:d.marginHeader)!=null)&&(T.params.noNeedSetTextRange=!0),!!o.syncExecuteCommand(T.id,T.params)}},T={id:`doc.command.set-default-paragraph-style`,type:t.CommandType.COMMAND,handler:(e,n)=>{if(n==null)return!1;let r=e.get(t.ICommandService),i=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);if(i==null)return!1;let a=i.getSnapshot().documentStyle.defaultParagraphStyle,o=t.JSONX.getInstance(),s=[`documentStyle`,`defaultParagraphStyle`],c=[];if(n.defaultParagraphStyle==null)a!=null&&c.push(o.removeOp(s,a));else if(a==null){let e=Object.fromEntries(Object.entries(n.defaultParagraphStyle).filter(([,e])=>e!=null).map(([e,n])=>[e,t.Tools.deepClone(n)]));Object.keys(e).length>0&&c.push(o.insertOp(s,e))}else Object.entries(n.defaultParagraphStyle).forEach(([e,n])=>{let r=a[e],i=[...s,e];n==null?r!=null&&c.push(o.removeOp(i,r)):r==null?c.push(o.insertOp(i,t.Tools.deepClone(n))):c.push(o.replaceOp(i,r,t.Tools.deepClone(n)))});let l=c.reduce((e,n)=>t.JSONX.compose(e,n),null);if(c.length===0||t.JSONX.isNoop(l))return!1;let u={id:_.id,params:{unitId:n.unitId,actions:l,textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1}};return!!r.syncExecuteCommand(u.id,u.params)}};function E(e){var n;let r=new Map(((n=e.sectionBreaks)==null?[]:n).map(e=>[e.startIndex,e])),i=[],a=0,o=0;for(let n=0;n<e.dataStream.length;n++){let s=e.dataStream[n];if(s===t.DataStreamTreeTokenType.TABLE_CELL_START)a++;else if(s===t.DataStreamTreeTokenType.TABLE_CELL_END)a=Math.max(0,a-1);else if(s===t.DataStreamTreeTokenType.COLUMN_START)o++;else if(s===t.DataStreamTreeTokenType.COLUMN_END)o=Math.max(0,o-1);else if(s===t.DataStreamTreeTokenType.SECTION_BREAK&&a===0&&o===0){let e=r.get(n);e&&i.push(e)}}return i}let D={id:`doc.command.set-section-header-footer-link`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i;if(!n)return!1;let a=e.get(t.IUniverInstanceService),o=e.get(t.ICommandService),s=a.getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC),c=s==null?void 0:s.getSnapshot();if(!s||!(c!=null&&c.body)||c.documentStyle.documentFlavor!==t.DocumentFlavor.TRADITIONAL)return!1;let l=E(c.body),u=l.findIndex(e=>e.sectionId===n.sectionId);if(u<=0)return!1;let d=(r=(i=c.body.sectionBreaks)==null?void 0:i.findIndex(e=>e.sectionId===n.sectionId))==null?-1:r;if(d<0)return!1;let f={snapshot:c,sections:l,sectionIndex:u,storageIndex:d,key:(0,t.getSectionHeaderFooterReferenceKey)(n.kind,n.variant)},p=n.linkedToPrevious?O(f,n.kind):k(f,n.kind,n.segmentId);if(!p)return!1;let m={id:_.id,params:{unitId:n.unitId,actions:p.reduce((e,n)=>t.JSONX.compose(e,n),null),textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1,trigger:D.id}};return!!o.syncExecuteCommand(m.id,m.params)}};function O(e,n){let{snapshot:r,sections:i,sectionIndex:a,storageIndex:o,key:s}=e,c=i[a],l=c[s];if(typeof l!=`string`||!l)return null;let u=t.JSONX.getInstance(),d=[u.removeOp([`body`,`sectionBreaks`,o,s],l)],f=n===`header`?[`defaultHeaderId`,`firstPageHeaderId`,`evenPageHeaderId`]:[`defaultFooterId`,`firstPageFooterId`,`evenPageFooterId`],p=f.some(e=>r.documentStyle[e]===l),m=i.some(e=>f.some(t=>!(e.sectionId===c.sectionId&&t===s)&&e[t]===l)),h=n===`header`?r.headers:r.footers;return!p&&!m&&h!=null&&h[l]&&d.push(u.removeOp([n===`header`?`headers`:`footers`,l],h[l])),d}function k(e,n,r){let{snapshot:i,sections:a,sectionIndex:o,storageIndex:s,key:c}=e,l=a[o][c];if(typeof l==`string`&&l)return null;let u=(0,t.resolveSectionHeaderFooterReference)(i.documentStyle,a,o-1,c).segmentId,d=r==null?(0,t.generateRandomId)(6):r,f=n===`header`?i.headers:i.footers;if(f!=null&&f[d])return null;let p=u?f==null?void 0:f[u]:void 0,m=n===`header`?`headerId`:`footerId`,h=p?{...t.Tools.deepClone(p),[m]:d}:{[m]:d,body:S()},g=t.JSONX.getInstance();return[g.insertOp([n===`header`?`headers`:`footers`,d],h),g.insertOp([`body`,`sectionBreaks`,s,c],d)]}let A={id:`doc.command.update-section`,type:t.CommandType.COMMAND,handler:(e,n)=>{if(!(n!=null&&n.updates.length)||n.updates.some(({sectionId:e,config:t})=>!e||Object.keys(t).length===0))return!1;let r=e.get(t.IUniverInstanceService),i=e.get(t.ICommandService),a=r.getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);if(!a||a.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL)return!1;let o=a.getBody();if(!o)return!1;let s=new Map(n.updates.map(({sectionId:e,config:t})=>[e,t]));if(s.size!==n.updates.length)return!1;let c=new Set(s.keys()),l=E(o).filter(e=>c.has(e.sectionId)).sort((e,t)=>e.startIndex-t.startIndex);if(l.length!==c.size)return!1;let u=new t.MemoryCursor,d=new t.TextX;for(let e of l)d.push({t:t.TextXActionType.RETAIN,len:e.startIndex-u.cursor}),d.push({t:t.TextXActionType.RETAIN,len:1,coverType:t.UpdateDocsAttributeType.REPLACE,body:{dataStream:``,sectionBreaks:[{...t.Tools.deepClone(e),...t.Tools.deepClone(s.get(e.sectionId)),sectionId:e.sectionId,startIndex:0}]}}),u.moveCursorTo(e.startIndex+1);let f=t.JSONX.getInstance(),p={id:_.id,params:{unitId:n.unitId,actions:f.editOp(d.serialize(),(0,t.getRichTextEditPath)(a)),textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1,trigger:A.id}};return!!i.syncExecuteCommand(p.id,p.params)}},j={id:`doc.command.insert-section-break`,type:t.CommandType.COMMAND,handler:(e,n)=>{var r,i,a,o,s;if(!n)return!1;let c=N(e,n.unitId);if(!c||!n.sectionId||!Number.isInteger(n.offset))return!1;let{body:l,documentDataModel:u,commandService:d}=c;if(n.offset<0||n.offset>l.dataStream.length||(r=l.sectionBreaks)!=null&&r.some(e=>e.sectionId===n.sectionId)||(i=l.tables)!=null&&i.some(e=>(0,t.containsInteriorInsertionOffset)((0,t.getTableRangeInterval)(e),n.offset))||(a=l.columnGroups)!=null&&a.some(e=>(0,t.containsInteriorInsertionOffset)((0,t.getColumnGroupRangeInterval)(e),n.offset))||(o=l.blockRanges)!=null&&o.some(e=>(0,t.containsInteriorInsertionOffset)((0,t.getBlockRangeInterval)(e),n.offset)))return!1;let f=new t.TextX;return f.retain(n.offset),f.insert(1,{dataStream:t.DataStreamTreeTokenType.SECTION_BREAK,sectionBreaks:[{...t.Tools.deepClone((s=n.config)==null?{}:s),sectionId:n.sectionId,startIndex:0}]}),P(d,u,f,j.id)}},M={id:`doc.command.delete-section-break`,type:t.CommandType.COMMAND,handler:(e,n)=>{if(!n)return!1;let r=N(e,n.unitId);if(!r||!n.sectionId)return!1;let i=E(r.body);if(i.length<=1)return!1;let a=i.find(e=>e.sectionId===n.sectionId);if(!a)return!1;let o=new t.TextX;return o.retain(a.startIndex),o.delete(1),P(r.commandService,r.documentDataModel,o,M.id)}};function N(e,n){if(!n)return null;let r=e.get(t.IUniverInstanceService).getUnit(n,t.UniverInstanceType.UNIVER_DOC),i=r==null?void 0:r.getBody();return!r||!i||r.getDocumentStyle().documentFlavor!==t.DocumentFlavor.TRADITIONAL?null:{body:i,documentDataModel:r,commandService:e.get(t.ICommandService)}}function P(e,n,r,i){let a=t.JSONX.getInstance().editOp(r.serialize(),(0,t.getRichTextEditPath)(n));return!!e.syncExecuteCommand(_.id,{unitId:n.getUnitId(),actions:a,textRanges:null,noNeedSetTextRange:!0,debounce:!0,isEditing:!1,trigger:i})}let F=`UniverEmbedDocsCustomBlock`,ee={width:720,height:360},te={width:960,height:480},ne={width:720,height:405};function re(e){return H(e.unitId,e.segmentId,I(e))}function ie(e){return H(e.unitId,e.segmentId,L(e))}function I(e){let n=new t.TextX;return e.startIndex>0&&n.push({t:t.TextXActionType.RETAIN,len:e.startIndex}),n.push({t:t.TextXActionType.INSERT,body:{dataStream:`\b`,customBlocks:[{startIndex:0,blockId:e.blockId}]},len:1}),W([U(n,e.segmentId),se(e)])}function L(e){let n=new t.TextX;return e.startIndex>0&&n.push({t:t.TextXActionType.RETAIN,len:e.startIndex}),n.push({t:t.TextXActionType.DELETE,len:1}),W([U(n,e.segmentId),ce(e)])}function R(e){var n;let r=z(e.childType),i=e.interactionMode===`inline`;return{unitId:e.unitId,subUnitId:e.unitId,drawingId:e.blockId,drawingType:t.DrawingTypeEnum.DRAWING_DOM,componentKey:(n=e.componentKey)==null?F:n,data:B(e),title:e.blockId,description:`Univer embedded unit custom block`,layoutType:i?t.PositionedObjectLayoutType.INLINE:t.PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM,allowTransform:!1,docTransform:{size:{width:r.width,height:r.height},positionH:{relativeFrom:i?t.ObjectRelativeFromH.PAGE:t.ObjectRelativeFromH.COLUMN,...i?{posOffset:0}:{align:t.AlignTypeH.LEFT}},positionV:{relativeFrom:i?t.ObjectRelativeFromV.PAGE:t.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},transform:{left:0,top:0,width:r.width,height:r.height}}}function z(e){return e===t.UniverInstanceType.UNIVER_SHEET||e===t.UniverInstanceType.UNIVER_BASE?te:e===t.UniverInstanceType.UNIVER_SLIDE?ne:ee}function ae(e){return e===t.UniverInstanceType.UNIVER_SHEET||e===t.UniverInstanceType.UNIVER_BASE}function B(e){var t,n;return{version:1,embedId:(t=e.embedId)==null?e.blockId:t,hostUnitId:e.unitId,hostAnchorId:e.blockId,childUnitId:e.childUnitId,childType:e.childType,interactionMode:(n=e.interactionMode)==null?`block`:n}}function V(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.version===1&&typeof t.embedId==`string`&&typeof t.hostAnchorId==`string`}function oe(e){let t=e&&typeof e==`object`?e.data:void 0;return V(t)?t.interactionMode===`inline`:!0}function H(e,t,n){return{id:_.id,params:{unitId:e,segmentId:t,actions:n,textRanges:[],isEditing:!1,noNeedSetTextRange:!0}}}function U(e,n){let r=t.JSONX.getInstance().editOp(e.serialize(),n?[`headers`,n,`body`]:[`body`]);return r==null?[]:r}function se(e){var n,r,i;if(e.segmentId)return[];let a=t.JSONX.getInstance(),o=R(e);return W([(n=a.insertOp([`drawings`,e.blockId],o))==null?[]:n,(r=a.insertOp([`drawingsOrder`,(i=e.drawingOrderIndex)==null?0:i],e.blockId))==null?[]:r])}function ce(e){var n,r,i;if(e.segmentId)return[];let a=t.JSONX.getInstance(),o=R(e);return W([(n=a.removeOp([`drawings`,e.blockId],o))==null?[]:n,(r=a.removeOp([`drawingsOrder`,(i=e.drawingOrderIndex)==null?0:i],e.blockId))==null?[]:r])}function W(e){return e.reduce((e,n)=>{var r;return!n||t.JSONX.isNoop(n)||n.length===0?e:!e||t.JSONX.isNoop(e)||e.length===0?n:(r=t.JSONX.compose(e,n))==null?[]:r},[])}var le=`@univerjs/docs`,ue=`1.0.0-alpha.4`;let de={id:`doc.mutation.rename-doc`,type:t.CommandType.MUTATION,handler:(e,n)=>{let r=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);return r?(r.setName(n.name),!0):!1}},G={},K=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._initSelectionChange()}_transformCustomRange(e,n){var r;let{startOffset:i,endOffset:a,collapsed:o}=n,s=(r=e.getCustomRanges())==null?void 0:r.filter(e=>!e.wholeEntity||i<=e.startIndex&&a>e.endIndex?!1:o?e.startIndex<i&&e.endIndex>=a:t.BuildTextUtils.range.isIntersects(i,a-1,e.startIndex,e.endIndex));if(s!=null&&s.length){let e=i,t=a;return s.forEach(n=>{e=Math.min(n.startIndex,e),t=Math.max(n.endIndex+1,t)}),{...n,startOffset:e,endOffset:t,collapsed:e===t}}return n}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.id){let{unitId:t,ranges:n,isEditing:r}=e.params,i=this._univerInstanceService.getUnit(t);if(!i)return;let a=n.map(e=>this._transformCustomRange(i,e));a.some((e,t)=>n[t]!==e)&&this._textSelectionManagerService.replaceTextRanges(a,r)}}))}};K=u([l(0,t.ICommandService),l(1,(0,t.Inject)(d)),l(2,t.IUniverInstanceService)],K);var q=class extends t.Disposable{constructor(...e){super(...e),c(this,`_validators`,[]),c(this,`_transformers`,[])}registerValidator(e){return this._validators.push(e),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._validators,e)))}registerTransformer(e){return this._transformers.push(e),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._transformers,e)))}canMoveBlock(e){return this._validators.every(t=>t(e))}transformMoveResult(e){return this._transformers.reduce((t,n)=>n({...e,result:t}),e.result)}},J=class extends t.Disposable{constructor(...e){super(...e),c(this,`_range`,null)}setInsertRange(e){this._range=e}consumeInsertRange(e){if(!this._range||e&&this._range.unitId!==e)return null;let t=this._range;return this._range=null,t}clearInsertRange(){this._range=null}};let Y=(0,t.createIdentifier)(`doc.state-change-interceptor-service`),X=class extends t.RxDisposable{constructor(e,t,n,i,a){super(),this._undoRedoService=e,this._commandService=t,this._univerInstanceService=n,this._docStateEmitService=i,this._docStateChangeInterceptorService=a,c(this,`_docStateChange$`,new r.BehaviorSubject(null)),c(this,`docStateChange$`,this._docStateChange$.asObservable()),c(this,`_historyStateCache`,new Map),c(this,`_changeStateCache`,new Map),c(this,`_historyTimer`,null),c(this,`_changeStateCacheTimer`,null),this._initialize(),this._listenDocStateChange()}getStateCache(e){var t,n;return{history:(t=this._historyStateCache.get(e))==null?[]:t,collaboration:(n=this._changeStateCache.get(e))==null?[]:n}}setStateCache(e,t){this._historyStateCache.set(e,t.history),this._changeStateCache.set(e,t.collaboration)}_setChangeState(e){this._cacheChangeState(e,`history`),this._cacheChangeState(e,`collaboration`)}_initialize(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===t.UndoCommandId||e.id===t.RedoCommandId){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(e==null)return;let n=e.getUnitId();this._pushHistory(n),this._emitChangeState(n)}}))}_listenDocStateChange(){this._docStateEmitService.docStateChangeParams$.pipe((0,r.takeUntil)(this.dispose$)).subscribe(e=>{var t,n;if(e==null)return;let r=(t=(n=this._docStateChangeInterceptorService)==null?void 0:n.transformChangeStateInfo(e))==null?e:t;if(r==null||r.isSync)return;let{isCompositionEnd:i,isSync:a,syncer:o,...s}=r;this._setChangeState(s)})}_cacheChangeState(e,n=`history`){let{trigger:r,unitId:i,noHistory:a,debounce:o=!1}=e;if(a||n===`history`&&r==null||n===`history`&&(r===t.RedoCommandId||r===t.UndoCommandId))return;let s=n===`history`?this._historyStateCache:this._changeStateCache,c=n===`history`?this._pushHistory.bind(this):this._emitChangeState.bind(this);if(s.has(i)){let t=s.get(i);t==null||t.push(e)}else s.set(i,[e]);o?n===`history`?(this._historyTimer&&clearTimeout(this._historyTimer),this._historyTimer=setTimeout(()=>{c(i)},300)):(this._changeStateCacheTimer&&clearTimeout(this._changeStateCacheTimer),this._changeStateCacheTimer=setTimeout(()=>{c(i)},300)):c(i)}_pushHistory(e){let n=this._undoRedoService,r=this._historyStateCache.get(e);if(n==null||!Array.isArray(r)||r.length===0)return;let i=r.length,a=r[0].commandId,o=r[0],s=r[i-1],c={unitId:e,actions:r.reduce((e,n)=>t.JSONX.compose(e,n.redoState.actions),null),textRanges:s.redoState.textRanges},l={unitId:e,actions:r.reverse().reduce((e,n)=>t.JSONX.compose(e,n.undoState.actions),null),textRanges:o.undoState.textRanges};n.pushUndoRedo({unitID:e,undoMutations:[{id:a,params:l}],redoMutations:[{id:a,params:c}]}),r.length=0}_emitChangeState(e){let n=this._changeStateCache.get(e);if(!Array.isArray(n)||n.length===0)return;let r=n.length,{commandId:i,trigger:a,segmentId:o,noHistory:s,debounce:c}=n[0],l=n[0],u=n[r-1],d={commandId:i,unitId:e,trigger:a,redoState:{unitId:e,actions:n.reduce((e,n)=>t.JSONX.compose(e,n.redoState.actions),null),textRanges:u.redoState.textRanges},undoState:{unitId:e,actions:n.reverse().reduce((e,n)=>t.JSONX.compose(e,n.undoState.actions),null),textRanges:l.undoState.textRanges},segmentId:o,noHistory:s,debounce:c};n.length=0,this._docStateChange$.next(d)}};X=u([l(0,(0,t.Optional)(t.IUndoRedoService)),l(1,t.ICommandService),l(2,t.IUniverInstanceService),l(3,(0,t.Inject)(p)),l(4,(0,t.Optional)(Y))],X);let Z=class extends t.Plugin{constructor(e=G,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},G,this._config);this._configService.setConfig(`docs.config`,i)}onStarting(){this._initializeDependencies(),this._initializeCommands()}_initializeCommands(){[v,y,b,w,T,D,A,j,M,_,de,i].forEach(e=>{this._injector.get(t.ICommandService).registerCommand(e)})}_initializeDependencies(){[[d],[p],[X],[q],[J],[K]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(X),this._injector.get(K)}};c(Z,`pluginName`,`DOCS_PLUGIN`),c(Z,`packageName`,le),c(Z,`version`,ue),Z=u([l(1,(0,t.Inject)(t.Injector)),l(2,t.IConfigService)],Z);let Q={CUSTOM_RANGE:(0,t.createInterceptorKey)(`CUSTOM_RANGE`),CUSTOM_DECORATION:(0,t.createInterceptorKey)(`CUSTOM_DECORATION`)},$=class extends t.Disposable{constructor(e,n){super(),this._context=e,this._docSkeletonManagerService=n,c(this,`_interceptorsByName`,new Map);let r=this._docSkeletonManagerService.getViewModel(),i=r.getDataModel().getUnitId();if(i===t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY||i===t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)return;this.disposeWithMe(this.interceptDocumentViewModel(r)),this.disposeWithMe(this.intercept(Q.CUSTOM_RANGE,{priority:-1,handler:(e,t,n)=>n(e)}));let a=new t.DisposableCollection;r.segmentViewModels$.subscribe(e=>{a.dispose(),a=new t.DisposableCollection,e.forEach(e=>{a.add(this.interceptDocumentViewModel(e))})}),this.disposeWithMe(a)}intercept(e,n){let r=e;this._interceptorsByName.has(r)||this._interceptorsByName.set(r,[]);let i=this._interceptorsByName.get(r);return i.push(n),this._interceptorsByName.set(r,i.sort((e,t)=>{var n,r;return((n=t.priority)==null?0:n)-((r=e.priority)==null?0:r)})),this.disposeWithMe((0,t.toDisposable)(()=>(0,t.remove)(this._interceptorsByName.get(r),n)))}fetchThroughInterceptors(e){let n=e;return(0,t.composeInterceptors)(this._interceptorsByName.get(n)||[])}interceptDocumentViewModel(e){let n=new t.DisposableCollection;return n.add(e.registerCustomRangeInterceptor({getCustomRange:t=>{var n;return this.fetchThroughInterceptors(Q.CUSTOM_RANGE)(e.getCustomRangeRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customRanges:(n=e.getDataModel().getCustomRanges())==null?[]:n})},getCustomDecoration:t=>{var n;return this.fetchThroughInterceptors(Q.CUSTOM_DECORATION)(e.getCustomDecorationRaw(t),{index:t,unitId:e.getDataModel().getUnitId(),customDecorations:(n=e.getDataModel().getCustomDecorations())==null?[]:n})}})),n}};$=u([l(1,(0,t.Inject)(f))],$);function fe(e,n,r){let{unitId:i,segmentId:a}=n,o=e.get(t.IUniverInstanceService).getUnit(i);if(!o)return!1;let s={id:_.id,params:{unitId:n.unitId,actions:[],textRanges:void 0}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.add({...n,body:r});if(!l)return!1;let u=(0,t.getRichTextEditPath)(o,a);return s.params.actions=c.editOp(l.serialize(),u),s}function pe(e,n){var r,i;let{rangeId:a,rangeType:o,wholeEntity:s,properties:c,unitId:l,selections:u}=n,f=e.get(d),p=e.get(t.IUniverInstanceService),m=u==null?f.getTextRanges({unitId:l,subUnitId:l}):u,h=m==null||(r=m[0])==null?void 0:r.segmentId;if(!(m!=null&&m.length))return!1;let g=p.getUnit(l,t.UniverInstanceType.UNIVER_DOC);if(!g)return!1;let v=(i=g.getSelfOrHeaderFooterModel(h))==null?void 0:i.getBody();if(!v)return!1;let y=t.BuildTextUtils.customRange.add({ranges:m,rangeId:a,rangeType:o,segmentId:h,wholeEntity:s,properties:c,body:v});if(!y)return!1;let b=t.JSONX.getInstance(),x={id:_.id,params:{unitId:l,actions:[],textRanges:y.selections,segmentId:h},textX:y},S=(0,t.getRichTextEditPath)(g,h);return x.params.actions=b.editOp(y.serialize(),S),x}function me(e,n){let{unitId:r,segmentId:i,insert:a}=n,o=e.get(t.IUniverInstanceService).getUnit(r);if(!o)return!1;let s={id:_.id,params:{unitId:n.unitId,actions:[],textRanges:void 0,segmentId:i}},c=t.JSONX.getInstance(),l=t.BuildTextUtils.customRange.delete({documentDataModel:o,rangeId:n.rangeId,insert:a,segmentId:i});if(!l)return!1;let u=(0,t.getRichTextEditPath)(o,i);return s.params.actions=c.editOp(l.serialize(),u),s.params.textRanges=l.selections,s}function he(e,n,r,i=[]){let a=[],o=new Set(i);for(let n=0,r=e.length;n<r;n++)e[n]===t.DataStreamTreeTokenType.PARAGRAPH&&a.push({startIndex:n,paragraphId:(0,t.createParagraphId)(o)});for(let e of a)n!=null&&n.bullet&&(e.bullet=t.Tools.deepClone(n.bullet)),n!=null&&n.paragraphStyle&&(e.paragraphStyle=t.Tools.deepClone(n.paragraphStyle),delete e.paragraphStyle.borderBottom,n.paragraphStyle.headingId&&(e.paragraphStyle.headingId=(0,t.generateRandomId)(6))),r&&(e.paragraphStyle!=null||(e.paragraphStyle={}),e.paragraphStyle.borderBottom=t.Tools.deepClone(r));return a}function ge(e,n){var r,i,a,o;let{unitId:s,body:c,doc:l}=n,u=l;if(u||(u=e.get(t.IUniverInstanceService).getUnit(s)),!u)return!1;let f=(r=n.selection)==null?void 0:r.segmentId,p=(i=u.getSelfOrHeaderFooterModel(f))==null?void 0:i.getBody();if(!p)return!1;let m=e.get(d),h=(a=n.selection)==null?m.getActiveTextRange():a;if(!h||!p)return!1;let g=(o=n.textRanges)==null?[{startOffset:h.startOffset+c.dataStream.length,endOffset:h.startOffset+c.dataStream.length,collapsed:!0,segmentId:f}]:o,v=t.BuildTextUtils.selection.replace({selection:h,body:c,doc:u});if(!v)return!1;let y={id:_.id,params:{unitId:s,actions:[],textRanges:g,debounce:!0,segmentId:f},textX:v},b=t.JSONX.getInstance();return y.params.actions=b.editOp(v.serialize()),y}function _e(e,n,r,i,a){var o,s,c,l,u,d,f,p;if(r<=1)return[];let m=Math.max(0,i),h=(o=(s=n==null||(c=n.pageSize)==null?void 0:c.width)==null?e==null||(l=e.pageSize)==null?void 0:l.width:s)==null?t.PAGE_SIZE[t.PaperType.A4].width:o,g=Math.max(0,h-((u=(d=n==null?void 0:n.marginLeft)==null?e==null?void 0:e.marginLeft:d)==null?72:u)-((f=(p=n==null?void 0:n.marginRight)==null?e==null?void 0:e.marginRight:p)==null?72:f)),_=Math.max(0,g-m*(r-1));return(a==null?Array.from({length:r},()=>_/r):a).map((e,t)=>({width:Math.max(0,e),paddingEnd:t===r-1?0:m}))}function ve(e,n,r){var i,a;return{size:{width:e,height:n},positionH:{relativeFrom:t.ObjectRelativeFromH.PAGE,posOffset:(i=r==null?void 0:r.left)==null?0:i},positionV:{relativeFrom:t.ObjectRelativeFromV.PARAGRAPH,posOffset:(a=r==null?void 0:r.top)==null?0:a},angle:0}}function ye(e){return{left:e.positionH.posOffset,top:e.positionV.posOffset,width:e.size.width,height:e.size.height,flipX:e.flipX,flipY:e.flipY}}function be(e,n=0,r=0){return{size:{width:e.width,height:e.height},positionH:{relativeFrom:t.ObjectRelativeFromH.MARGIN,posOffset:(e.left||0)-n},positionV:{relativeFrom:t.ObjectRelativeFromV.PAGE,posOffset:(e.top||0)-r},angle:e.angle||0,flipX:e.flipX,flipY:e.flipY}}function xe(e,t){try{return e.get(J).consumeInsertRange(t)}catch{return null}}function Se(e,n){var r;let i=n==null?(r=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC))==null?void 0:r.getUnitId():n;if(!i)return null;let a=xe(e,i);return a?{...a,collapsed:(a==null?void 0:a.startOffset)===(a==null?void 0:a.endOffset)}:null}function Ce(e){return!!(e!=null&&e.segmentId)}function we(e){var t,n,r;let i=(t=e.endOffset)==null?e.startOffset:t;return{...e,endOffset:i,collapsed:(n=e.collapsed)==null?e.startOffset===i:n,segmentId:(r=e.segmentId)==null?``:r}}e.CreateHeaderFooterCommand=w,e.DOC_INTERCEPTOR_POINT=Q,e.DeleteDocumentSectionBreakCommand=M,e.DeleteTextCommand=y,e.DocBlockMoveValidatorService=q,e.DocContentInsertService=J,Object.defineProperty(e,"DocInterceptorService",{enumerable:!0,get:function(){return $}}),Object.defineProperty(e,"DocSelectionManagerService",{enumerable:!0,get:function(){return d}}),Object.defineProperty(e,"DocSkeletonManagerService",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"DocStateChangeManagerService",{enumerable:!0,get:function(){return X}}),e.DocStateEmitService=p,e.EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY=F,e.HeaderFooterType=x,e.IDocStateChangeInterceptorService=Y,e.InsertDocumentSectionBreakCommand=j,e.InsertTextCommand=v,e.RichTextEditingMutation=_,e.SetDocumentDefaultParagraphStyleCommand=T,e.SetSectionHeaderFooterLinkCommand=D,e.SetTextSelectionsOperation=i,Object.defineProperty(e,"UniverDocsPlugin",{enumerable:!0,get:function(){return Z}}),e.UpdateDocumentSectionCommand=A,e.UpdateTextCommand=b,e.addCustomRangeBySelectionFactory=pe,e.addCustomRangeFactory=fe,e.buildDocTransform=ve,e.consumeContentInsertRange=xe,e.createDocsCustomBlockDrawing=R,e.createDocsCustomBlockInsertMutation=re,e.createDocsCustomBlockRemoveMutation=ie,e.createEmbedDocsCustomBlockData=B,e.createInsertCustomBlockActions=I,e.createRemoveCustomBlockActions=L,e.createSectionColumnProperties=_e,e.deleteCustomRangeFactory=me,e.docDrawingPositionToTransform=ye,e.generateParagraphs=he,e.getContentInsertRange=Se,e.getTopLevelSectionBreaks=E,e.isEmbedDocsCustomBlockData=V,e.isHeaderFooterSelection=Ce,e.isSheetLikeDocsCustomBlockChildType=ae,e.normalizeTextRange=we,e.replaceSelectionFactory=ge,e.resolveDocsCustomBlockSize=z,e.shouldUseInlineTextSelectionForDocsCustomBlockDrawing=oe,e.transformToDocDrawingPosition=be});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "private": false,
5
5
  "description": "Core document model and rich-text operations for Univer Docs.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -62,14 +62,14 @@
62
62
  "rxjs": ">=7.0.0"
63
63
  },
64
64
  "dependencies": {
65
- "@univerjs/core": "1.0.0-alpha.3",
66
- "@univerjs/engine-render": "1.0.0-alpha.3"
65
+ "@univerjs/core": "1.0.0-alpha.4",
66
+ "@univerjs/engine-render": "1.0.0-alpha.4"
67
67
  },
68
68
  "devDependencies": {
69
69
  "rxjs": "^7.8.2",
70
70
  "typescript": "^6.0.3",
71
71
  "vitest": "^4.1.10",
72
- "@univerjs-infra/shared": "1.0.0-alpha.3"
72
+ "@univerjs-infra/shared": "1.0.0-alpha.4"
73
73
  },
74
74
  "scripts": {
75
75
  "test": "vitest run",