@univerjs/docs 0.2.9 → 0.2.10
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/es/index.js
CHANGED
|
@@ -1903,6 +1903,19 @@ function getCellOffsets(viewModel, range, position) {
|
|
|
1903
1903
|
}
|
|
1904
1904
|
}
|
|
1905
1905
|
__name(getCellOffsets, "getCellOffsets");
|
|
1906
|
+
function getCustomBlockIdsInSelections(body, selections) {
|
|
1907
|
+
const customBlockIds = [], { customBlocks = [] } = body;
|
|
1908
|
+
for (const selection of selections) {
|
|
1909
|
+
const { startOffset, endOffset } = selection;
|
|
1910
|
+
if (!(startOffset == null || endOffset == null))
|
|
1911
|
+
for (const customBlock of customBlocks) {
|
|
1912
|
+
const { startIndex } = customBlock;
|
|
1913
|
+
startIndex >= startOffset && startIndex < endOffset && customBlockIds.push(customBlock.blockId);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
return customBlockIds;
|
|
1917
|
+
}
|
|
1918
|
+
__name(getCustomBlockIdsInSelections, "getCustomBlockIdsInSelections");
|
|
1906
1919
|
function hasRangeInTable(ranges) {
|
|
1907
1920
|
return ranges.some((range) => {
|
|
1908
1921
|
const { anchorNodePosition } = range;
|
|
@@ -1913,10 +1926,10 @@ __name(hasRangeInTable, "hasRangeInTable");
|
|
|
1913
1926
|
const InnerPasteCommand = {
|
|
1914
1927
|
id: "doc.command.inner-paste",
|
|
1915
1928
|
type: CommandType.COMMAND,
|
|
1916
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1929
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
1917
1930
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1918
|
-
var _a11;
|
|
1919
|
-
const { segmentId, textRanges, doc } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges(), { body, tableSource } = doc;
|
|
1931
|
+
var _a11, _b, _c, _d;
|
|
1932
|
+
const { segmentId, textRanges, doc } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges(), { body, tableSource, drawings } = doc;
|
|
1920
1933
|
if (!Array.isArray(selections) || selections.length === 0 || body == null)
|
|
1921
1934
|
return !1;
|
|
1922
1935
|
const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
@@ -1932,7 +1945,7 @@ const InnerPasteCommand = {
|
|
|
1932
1945
|
}
|
|
1933
1946
|
}, memoryCursor = new MemoryCursor();
|
|
1934
1947
|
memoryCursor.reset();
|
|
1935
|
-
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], hasTable = !!((_a11 = body.tables) != null && _a11.length);
|
|
1948
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], hasTable = !!((_a11 = body.tables) != null && _a11.length), hasCustomBlock = !!((_b = body.customBlocks) != null && _b.length);
|
|
1936
1949
|
if (hasTable && segmentId || hasTable && hasRangeInTable(selections))
|
|
1937
1950
|
return !1;
|
|
1938
1951
|
for (const selection of selections) {
|
|
@@ -1946,6 +1959,17 @@ const InnerPasteCommand = {
|
|
|
1946
1959
|
const action = jsonX.insertOp(["tableSource", tableId], table);
|
|
1947
1960
|
rawActions.push(action);
|
|
1948
1961
|
}
|
|
1962
|
+
if (hasCustomBlock && drawings) {
|
|
1963
|
+
const drawingLen = (_d = (_c = docDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _c.length) != null ? _d : 0;
|
|
1964
|
+
for (const block of cloneBody.customBlocks) {
|
|
1965
|
+
const { blockId } = block, drawingId = Tools.generateRandomId(6);
|
|
1966
|
+
block.blockId = drawingId;
|
|
1967
|
+
const drawing = Tools.deepClone(drawings[blockId]);
|
|
1968
|
+
drawing.drawingId = drawingId;
|
|
1969
|
+
const action = jsonX.insertOp(["drawings", drawingId], drawing), orderAction = jsonX.insertOp(["drawingsOrder", drawingLen], drawingId);
|
|
1970
|
+
rawActions.push(action), rawActions.push(orderAction);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1949
1973
|
if (collapsed)
|
|
1950
1974
|
textX.push({
|
|
1951
1975
|
t: TextXActionType.RETAIN,
|
|
@@ -2070,11 +2094,23 @@ function getCutActionsFromRectRanges(ranges, docDataModel, viewModel, segmentId)
|
|
|
2070
2094
|
return rawActions.push(jsonX.editOp(textX.serialize(), path)), rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
|
|
2071
2095
|
}
|
|
2072
2096
|
__name(getCutActionsFromRectRanges, "getCutActionsFromRectRanges");
|
|
2097
|
+
function getCutActionsFromDocRanges(textRanges, rectRanges, docDataModel, viewModel, segmentId) {
|
|
2098
|
+
let rawActions = [];
|
|
2099
|
+
if (Array.isArray(textRanges) && (textRanges == null ? void 0 : textRanges.length) !== 0 && (rawActions = getCutActionsFromTextRanges(textRanges, docDataModel, segmentId)), Array.isArray(rectRanges) && (rectRanges == null ? void 0 : rectRanges.length) !== 0) {
|
|
2100
|
+
const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
|
|
2101
|
+
rawActions == null || rawActions.length === 0 ? rawActions = actions : rawActions = JSONX.compose(
|
|
2102
|
+
rawActions,
|
|
2103
|
+
JSONX.transform(actions, rawActions, "right")
|
|
2104
|
+
);
|
|
2105
|
+
}
|
|
2106
|
+
return rawActions;
|
|
2107
|
+
}
|
|
2108
|
+
__name(getCutActionsFromDocRanges, "getCutActionsFromDocRanges");
|
|
2073
2109
|
const INNER_CUT_COMMAND_ID = "doc.command.inner-cut", CutContentCommand = {
|
|
2074
2110
|
id: INNER_CUT_COMMAND_ID,
|
|
2075
2111
|
type: CommandType.COMMAND,
|
|
2076
2112
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
2077
|
-
var _a11, _b
|
|
2113
|
+
var _a11, _b;
|
|
2078
2114
|
const { segmentId, textRanges } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = (_a11 = params.selections) != null ? _a11 : textSelectionManagerService.getCurrentTextRanges(), rectRanges = textSelectionManagerService.getCurrentRectRanges();
|
|
2079
2115
|
if ((!Array.isArray(selections) || selections.length === 0) && (!Array.isArray(rectRanges) || rectRanges.length === 0))
|
|
2080
2116
|
return !1;
|
|
@@ -2095,30 +2131,9 @@ const INNER_CUT_COMMAND_ID = "doc.command.inner-cut", CutContentCommand = {
|
|
|
2095
2131
|
textRanges
|
|
2096
2132
|
}
|
|
2097
2133
|
};
|
|
2098
|
-
|
|
2099
|
-
const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
|
|
2100
|
-
((_c = doMutation.params.actions) == null ? void 0 : _c.length) === 0 || doMutation.params.actions == null ? doMutation.params.actions = actions : doMutation.params.actions = JSONX.compose(
|
|
2101
|
-
doMutation.params.actions,
|
|
2102
|
-
JSONX.transform(actions, doMutation.params.actions, "right")
|
|
2103
|
-
);
|
|
2104
|
-
}
|
|
2105
|
-
return !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
2134
|
+
return doMutation.params.actions = getCutActionsFromDocRanges(selections, rectRanges, docDataModel, viewModel, segmentId), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
2106
2135
|
}, "handler")
|
|
2107
|
-
}
|
|
2108
|
-
function getCustomBlockIdsInSelections(body, selections) {
|
|
2109
|
-
const customBlockIds = [], { customBlocks = [] } = body;
|
|
2110
|
-
for (const selection of selections) {
|
|
2111
|
-
const { startOffset, endOffset } = selection;
|
|
2112
|
-
if (!(startOffset == null || endOffset == null))
|
|
2113
|
-
for (const customBlock of customBlocks) {
|
|
2114
|
-
const { startIndex } = customBlock;
|
|
2115
|
-
startIndex >= startOffset && startIndex < endOffset && customBlockIds.push(customBlock.blockId);
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
return customBlockIds;
|
|
2119
|
-
}
|
|
2120
|
-
__name(getCustomBlockIdsInSelections, "getCustomBlockIdsInSelections");
|
|
2121
|
-
const DeleteCustomBlockCommand = {
|
|
2136
|
+
}, DeleteCustomBlockCommand = {
|
|
2122
2137
|
id: "doc.command.delete-custom-block",
|
|
2123
2138
|
type: CommandType.COMMAND,
|
|
2124
2139
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
@@ -4614,7 +4629,9 @@ export {
|
|
|
4614
4629
|
generateParagraphs,
|
|
4615
4630
|
getCommandSkeleton,
|
|
4616
4631
|
getCursorWhenDelete,
|
|
4632
|
+
getCustomBlockIdsInSelections,
|
|
4617
4633
|
getCustomRangesInterestsWithRange,
|
|
4634
|
+
getCutActionsFromDocRanges,
|
|
4618
4635
|
getDeleteSelection,
|
|
4619
4636
|
getDocObject,
|
|
4620
4637
|
getDocObjectById,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { ICommand, IDocumentData, ITextRange } from '@univerjs/core';
|
|
2
|
-
import { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
1
|
+
import { DocumentDataModel, ICommand, IDocumentBody, IDocumentData, ITextRange, JSONXActions, Nullable } from '@univerjs/core';
|
|
2
|
+
import { DocumentViewModel, ITextRangeWithStyle, RectRange, TextRange } from '@univerjs/engine-render';
|
|
3
|
+
export declare function getCustomBlockIdsInSelections(body: IDocumentBody, selections: ITextRange[]): string[];
|
|
3
4
|
export interface IInnerPasteCommandParams {
|
|
4
5
|
segmentId: string;
|
|
5
6
|
doc: Partial<IDocumentData>;
|
|
6
7
|
textRanges: ITextRangeWithStyle[];
|
|
7
8
|
}
|
|
8
9
|
export declare const InnerPasteCommand: ICommand<IInnerPasteCommandParams>;
|
|
10
|
+
export declare function getCutActionsFromDocRanges(textRanges: Readonly<Nullable<(ITextRange | TextRange)[]>>, rectRanges: Readonly<Nullable<RectRange[]>>, docDataModel: DocumentDataModel, viewModel: DocumentViewModel, segmentId: string): JSONXActions;
|
|
9
11
|
export interface IInnerCutCommandParams {
|
|
10
12
|
segmentId: string;
|
|
11
13
|
textRanges: ITextRangeWithStyle[];
|
package/lib/types/index.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export { ChangeListNestingLevelType } from './commands/commands/list.command';
|
|
|
55
55
|
export { getCommandSkeleton } from './commands/util';
|
|
56
56
|
export { generateParagraphs } from './commands/commands/break-line.command';
|
|
57
57
|
export type { IInnerCutCommandParams } from './commands/commands/clipboard.inner.command';
|
|
58
|
+
export { getCutActionsFromDocRanges, getCustomBlockIdsInSelections } from './commands/commands/clipboard.inner.command';
|
|
58
59
|
export { CreateDocTableCommand, type ICreateDocTableCommandParams } from './commands/commands/table/doc-table-create.command';
|
|
59
60
|
export { DocTableDeleteRowsCommand, DocTableDeleteColumnsCommand, DocTableDeleteTableCommand } from './commands/commands/table/doc-table-delete.command';
|
|
60
61
|
export type { IDocTableDeleteRowsCommandParams, IDocTableDeleteColumnsCommandParams, IDocTableDeleteTableCommandParams } from './commands/commands/table/doc-table-delete.command';
|