@univerjs/docs 1.0.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/lib/cjs/facade.js +10 -10
- package/lib/cjs/index.js +704 -617
- package/lib/es/facade.js +6 -6
- package/lib/es/index.js +698 -612
- package/lib/facade.js +6 -6
- package/lib/index.js +698 -612
- package/lib/types/commands/commands/set-heading-collapsed.command.d.ts +22 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/doc-skeleton-manager.service.d.ts +3 -2
- package/lib/types/utils/section-columns.d.ts +2 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +8 -8
package/lib/cjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ const SetTextSelectionsOperation = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
|
-
//#region \0@oxc-project+runtime@0.
|
|
18
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
19
19
|
function _typeof(o) {
|
|
20
20
|
"@babel/helpers - typeof";
|
|
21
21
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -26,7 +26,7 @@ function _typeof(o) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
|
-
//#region \0@oxc-project+runtime@0.
|
|
29
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
30
30
|
function toPrimitive(t, r) {
|
|
31
31
|
if ("object" != _typeof(t) || !t) return t;
|
|
32
32
|
var e = t[Symbol.toPrimitive];
|
|
@@ -39,14 +39,14 @@ function toPrimitive(t, r) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
//#endregion
|
|
42
|
-
//#region \0@oxc-project+runtime@0.
|
|
42
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
43
43
|
function toPropertyKey(t) {
|
|
44
44
|
var i = toPrimitive(t, "string");
|
|
45
45
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
//#endregion
|
|
49
|
-
//#region \0@oxc-project+runtime@0.
|
|
49
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
50
50
|
function _defineProperty(e, r, t) {
|
|
51
51
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
52
52
|
value: t,
|
|
@@ -57,7 +57,7 @@ function _defineProperty(e, r, t) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
//#endregion
|
|
60
|
-
//#region \0@oxc-project+runtime@0.
|
|
60
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
61
61
|
function __decorateParam(paramIndex, decorator) {
|
|
62
62
|
return function(target, key) {
|
|
63
63
|
decorator(target, key, paramIndex);
|
|
@@ -65,7 +65,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
//#endregion
|
|
68
|
-
//#region \0@oxc-project+runtime@0.
|
|
68
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
69
69
|
function __decorate(decorators, target, key, desc) {
|
|
70
70
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
71
71
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -160,7 +160,10 @@ let DocSelectionManagerService = class DocSelectionManagerService extends _unive
|
|
|
160
160
|
subUnitId,
|
|
161
161
|
docRanges,
|
|
162
162
|
isEditing,
|
|
163
|
-
options
|
|
163
|
+
options: {
|
|
164
|
+
...options,
|
|
165
|
+
preserveInputStyle: false
|
|
166
|
+
}
|
|
164
167
|
});
|
|
165
168
|
}
|
|
166
169
|
/**
|
|
@@ -180,7 +183,13 @@ let DocSelectionManagerService = class DocSelectionManagerService extends _unive
|
|
|
180
183
|
...textSelectionInfo,
|
|
181
184
|
...search
|
|
182
185
|
};
|
|
183
|
-
this._replaceByParam(
|
|
186
|
+
this._replaceByParam({
|
|
187
|
+
...params,
|
|
188
|
+
options: {
|
|
189
|
+
...params.options,
|
|
190
|
+
preserveInputStyle: true
|
|
191
|
+
}
|
|
192
|
+
});
|
|
184
193
|
this._textSelection$.next(params);
|
|
185
194
|
const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params;
|
|
186
195
|
const ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => {
|
|
@@ -221,10 +230,11 @@ let DocSelectionManagerService = class DocSelectionManagerService extends _unive
|
|
|
221
230
|
subUnitId,
|
|
222
231
|
docRanges,
|
|
223
232
|
isEditing,
|
|
224
|
-
options:
|
|
233
|
+
options: {
|
|
225
234
|
...options,
|
|
226
|
-
forceFocus: false
|
|
227
|
-
|
|
235
|
+
forceFocus: false,
|
|
236
|
+
preserveInputStyle: (options === null || options === void 0 ? void 0 : options.preserveInputStyle) ?? true
|
|
237
|
+
}
|
|
228
238
|
});
|
|
229
239
|
}
|
|
230
240
|
_replaceByParam(insertParam) {
|
|
@@ -636,9 +646,11 @@ let DocLayoutExecutorService = _DocLayoutExecutorService = class DocLayoutExecut
|
|
|
636
646
|
});
|
|
637
647
|
}
|
|
638
648
|
_enqueueCommittedMutation(params) {
|
|
649
|
+
var _params$actions;
|
|
639
650
|
const executor = this._executor;
|
|
640
651
|
const dataModel = this._getEligibleModel(params.unitId);
|
|
641
652
|
if (executor == null || dataModel == null) return;
|
|
653
|
+
if (_univerjs_core.JSONX.isNoop(params.actions) || ((_params$actions = params.actions) === null || _params$actions === void 0 ? void 0 : _params$actions.length) === 0) return;
|
|
642
654
|
const session = this._sessions.get(params.unitId);
|
|
643
655
|
if (session == null) {
|
|
644
656
|
this._replaceSession(dataModel).catch((error) => {
|
|
@@ -646,7 +658,6 @@ let DocLayoutExecutorService = _DocLayoutExecutorService = class DocLayoutExecut
|
|
|
646
658
|
});
|
|
647
659
|
return;
|
|
648
660
|
}
|
|
649
|
-
if (_univerjs_core.JSONX.isNoop(params.actions)) return;
|
|
650
661
|
const sourceMutationRevision = dataModel.getMutationRevision();
|
|
651
662
|
if (sourceMutationRevision !== session.sourceMutationRevision + 1) {
|
|
652
663
|
session.needsResnapshot = true;
|
|
@@ -900,12 +911,13 @@ DocLayoutExecutorService = _DocLayoutExecutorService = __decorate([
|
|
|
900
911
|
//#endregion
|
|
901
912
|
//#region src/services/doc-skeleton-manager.service.ts
|
|
902
913
|
let DocSkeletonManagerService = class DocSkeletonManagerService extends _univerjs_core.RxDisposable {
|
|
903
|
-
constructor(_context, _localeService, _univerInstanceService, _docLayoutExecutorService) {
|
|
914
|
+
constructor(_context, _localeService, _univerInstanceService, _docLayoutExecutorService, _configService) {
|
|
904
915
|
super();
|
|
905
916
|
this._context = _context;
|
|
906
917
|
this._localeService = _localeService;
|
|
907
918
|
this._univerInstanceService = _univerInstanceService;
|
|
908
919
|
this._docLayoutExecutorService = _docLayoutExecutorService;
|
|
920
|
+
this._configService = _configService;
|
|
909
921
|
_defineProperty(this, "_skeleton", void 0);
|
|
910
922
|
_defineProperty(this, "_docViewModel", void 0);
|
|
911
923
|
_defineProperty(this, "_currentSkeleton$", new rxjs.BehaviorSubject(null));
|
|
@@ -965,7 +977,8 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends _univerj
|
|
|
965
977
|
this._currentViewModel$.next(this._docViewModel);
|
|
966
978
|
}
|
|
967
979
|
_buildSkeleton(documentViewModel) {
|
|
968
|
-
|
|
980
|
+
const isSheetEditor = this._context.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY || this._context.unitId === _univerjs_core.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
|
|
981
|
+
return _univerjs_engine_render.DocumentSkeleton.create(documentViewModel, this._localeService, { lineGap: isSheetEditor ? this._configService.getConfig(_univerjs_core.SHEET_TEXT_LINE_GAP) : void 0 });
|
|
969
982
|
}
|
|
970
983
|
_buildDocViewModel(documentDataModel) {
|
|
971
984
|
return new _univerjs_engine_render.DocumentViewModel(documentDataModel);
|
|
@@ -974,7 +987,8 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends _univerj
|
|
|
974
987
|
DocSkeletonManagerService = __decorate([
|
|
975
988
|
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
976
989
|
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
977
|
-
__decorateParam(3, (0, _univerjs_core.Inject)(DocLayoutExecutorService))
|
|
990
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(DocLayoutExecutorService)),
|
|
991
|
+
__decorateParam(4, _univerjs_core.IConfigService)
|
|
978
992
|
], DocSkeletonManagerService);
|
|
979
993
|
|
|
980
994
|
//#endregion
|
|
@@ -1373,13 +1387,15 @@ function scheduleDocumentSelectionUpdate(selectionManager, params, isSync) {
|
|
|
1373
1387
|
textRanges: logicalTextRanges,
|
|
1374
1388
|
rectRanges: [],
|
|
1375
1389
|
isEditing,
|
|
1376
|
-
options:
|
|
1390
|
+
options: {
|
|
1391
|
+
...params.options,
|
|
1392
|
+
preserveInputStyle: false
|
|
1393
|
+
}
|
|
1377
1394
|
}, selectionTarget);
|
|
1378
1395
|
const updatedSelection = selectionManager.getSelectionInfo(selectionTarget);
|
|
1379
1396
|
queueMicrotask(() => {
|
|
1380
1397
|
if (selectionManager.getSelectionInfo(selectionTarget) !== updatedSelection) return;
|
|
1381
|
-
|
|
1382
|
-
else selectionManager.refreshSelection(selectionTarget, isEditing);
|
|
1398
|
+
selectionManager.replaceDocRanges(logicalTextRanges, selectionTarget, isEditing, params.options);
|
|
1383
1399
|
});
|
|
1384
1400
|
}
|
|
1385
1401
|
/**
|
|
@@ -2111,384 +2127,717 @@ function getTopLevelSectionBreaks(body) {
|
|
|
2111
2127
|
}
|
|
2112
2128
|
|
|
2113
2129
|
//#endregion
|
|
2114
|
-
//#region src/
|
|
2115
|
-
const
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
noNeedSetTextRange: true,
|
|
2147
|
-
debounce: true,
|
|
2148
|
-
isEditing: false,
|
|
2149
|
-
trigger: SetSectionHeaderFooterLinkCommand.id
|
|
2150
|
-
}
|
|
2151
|
-
};
|
|
2152
|
-
return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
|
|
2130
|
+
//#region src/services/permission/document-permission-resolver.ts
|
|
2131
|
+
const HEADER_FOOTER_REFERENCE_KEYS = [
|
|
2132
|
+
"defaultHeaderId",
|
|
2133
|
+
"defaultFooterId",
|
|
2134
|
+
"firstPageHeaderId",
|
|
2135
|
+
"firstPageFooterId",
|
|
2136
|
+
"evenPageHeaderId",
|
|
2137
|
+
"evenPageFooterId"
|
|
2138
|
+
];
|
|
2139
|
+
const documentPermissionResolverIndexCache = /* @__PURE__ */ new WeakMap();
|
|
2140
|
+
function getDocumentPermissionResolverIndex(documentDataModel) {
|
|
2141
|
+
var _getMutationRevision, _snapshot$body;
|
|
2142
|
+
const mutationRevision = ((_getMutationRevision = documentDataModel.getMutationRevision) === null || _getMutationRevision === void 0 ? void 0 : _getMutationRevision.call(documentDataModel)) ?? NaN;
|
|
2143
|
+
const cached = documentPermissionResolverIndexCache.get(documentDataModel);
|
|
2144
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.mutationRevision) === mutationRevision) return cached;
|
|
2145
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
2146
|
+
const topLevelSections = snapshot.body ? getTopLevelSectionBreaks(snapshot.body) : [];
|
|
2147
|
+
const drawingSegmentIds = /* @__PURE__ */ new Map();
|
|
2148
|
+
const addDrawingSegments = (body, segmentId) => {
|
|
2149
|
+
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) if (!drawingSegmentIds.has(block.blockId)) drawingSegmentIds.set(block.blockId, segmentId);
|
|
2150
|
+
};
|
|
2151
|
+
addDrawingSegments(snapshot.body, "");
|
|
2152
|
+
Object.entries(snapshot.headers ?? {}).forEach(([segmentId, header]) => addDrawingSegments(header.body, segmentId));
|
|
2153
|
+
Object.entries(snapshot.footers ?? {}).forEach(([segmentId, footer]) => addDrawingSegments(footer.body, segmentId));
|
|
2154
|
+
Object.entries(snapshot.notes ?? {}).forEach(([segmentId, footnote]) => addDrawingSegments(footnote.body, segmentId));
|
|
2155
|
+
const footnoteReferenceRanges = /* @__PURE__ */ new Map();
|
|
2156
|
+
for (const reference of ((_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.customRanges) ?? []) {
|
|
2157
|
+
var _reference$properties;
|
|
2158
|
+
if ((reference.rangeType === _univerjs_core.CustomRangeType.FOOTNOTE || reference.rangeType === _univerjs_core.CustomRangeType.ENDNOTE) && typeof ((_reference$properties = reference.properties) === null || _reference$properties === void 0 ? void 0 : _reference$properties.noteId) === "string") footnoteReferenceRanges.set(reference.properties.noteId, {
|
|
2159
|
+
startOffset: reference.startIndex,
|
|
2160
|
+
endOffset: reference.endIndex + 1
|
|
2161
|
+
});
|
|
2153
2162
|
}
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
"sectionBreaks",
|
|
2164
|
-
storageIndex,
|
|
2165
|
-
key
|
|
2166
|
-
], explicitSegmentId)];
|
|
2167
|
-
const referenceKeys = kind === "header" ? [
|
|
2168
|
-
"defaultHeaderId",
|
|
2169
|
-
"firstPageHeaderId",
|
|
2170
|
-
"evenPageHeaderId"
|
|
2171
|
-
] : [
|
|
2172
|
-
"defaultFooterId",
|
|
2173
|
-
"firstPageFooterId",
|
|
2174
|
-
"evenPageFooterId"
|
|
2175
|
-
];
|
|
2176
|
-
const referencedByDocument = referenceKeys.some((referenceKey) => snapshot.documentStyle[referenceKey] === explicitSegmentId);
|
|
2177
|
-
const referencedBySection = sections.some((item) => referenceKeys.some((referenceKey) => !(item.sectionId === section.sectionId && referenceKey === key) && item[referenceKey] === explicitSegmentId));
|
|
2178
|
-
const resources = kind === "header" ? snapshot.headers : snapshot.footers;
|
|
2179
|
-
if (!referencedByDocument && !referencedBySection && (resources === null || resources === void 0 ? void 0 : resources[explicitSegmentId])) actions.push(jsonX.removeOp([kind === "header" ? "headers" : "footers", explicitSegmentId], resources[explicitSegmentId]));
|
|
2180
|
-
return actions;
|
|
2163
|
+
const index = {
|
|
2164
|
+
drawingSegmentIds,
|
|
2165
|
+
footnoteReferenceRanges,
|
|
2166
|
+
mutationRevision,
|
|
2167
|
+
segments: /* @__PURE__ */ new Map(),
|
|
2168
|
+
topLevelSections
|
|
2169
|
+
};
|
|
2170
|
+
documentPermissionResolverIndexCache.set(documentDataModel, index);
|
|
2171
|
+
return index;
|
|
2181
2172
|
}
|
|
2182
|
-
function
|
|
2183
|
-
|
|
2184
|
-
const
|
|
2185
|
-
if (
|
|
2186
|
-
const
|
|
2187
|
-
const
|
|
2188
|
-
const
|
|
2189
|
-
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
body
|
|
2173
|
+
function getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
|
|
2174
|
+
var _documentDataModel$ge, _snapshot$notes;
|
|
2175
|
+
const cached = resolverIndex.segments.get(segmentId);
|
|
2176
|
+
if (cached) return cached;
|
|
2177
|
+
const body = ((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody()) ?? null;
|
|
2178
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
2179
|
+
const note = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
|
|
2180
|
+
const drawings = (note ? note.drawings : snapshot.drawings) ?? {};
|
|
2181
|
+
const entities = body == null ? [] : [
|
|
2182
|
+
...(body.tables ?? []).map((item) => ({
|
|
2183
|
+
type: "table",
|
|
2184
|
+
id: item.tableId,
|
|
2185
|
+
startOffset: item.startIndex,
|
|
2186
|
+
endOffset: item.endIndex
|
|
2187
|
+
})),
|
|
2188
|
+
...(body.customBlocks ?? []).map((item) => ({
|
|
2189
|
+
type: drawings[item.blockId] ? "drawing" : "custom-block",
|
|
2190
|
+
id: item.blockId,
|
|
2191
|
+
startOffset: item.startIndex,
|
|
2192
|
+
endOffset: item.startIndex + 1
|
|
2193
|
+
})),
|
|
2194
|
+
...(body.blockRanges ?? []).map((item) => ({
|
|
2195
|
+
type: "block-range",
|
|
2196
|
+
id: item.blockId,
|
|
2197
|
+
startOffset: item.startIndex,
|
|
2198
|
+
endOffset: item.endIndex + 1
|
|
2199
|
+
})),
|
|
2200
|
+
...(body.customRanges ?? []).map((item) => ({
|
|
2201
|
+
type: "custom-range",
|
|
2202
|
+
id: item.rangeId,
|
|
2203
|
+
startOffset: item.startIndex,
|
|
2204
|
+
endOffset: item.endIndex + 1
|
|
2205
|
+
})),
|
|
2206
|
+
...(body.columnGroups ?? []).map((item) => ({
|
|
2207
|
+
type: "column-group",
|
|
2208
|
+
id: item.columnGroupId,
|
|
2209
|
+
startOffset: item.startIndex,
|
|
2210
|
+
endOffset: item.endIndex + 1
|
|
2211
|
+
}))
|
|
2212
|
+
];
|
|
2213
|
+
const entityRanges = new Map(entities.map((entity) => [`${entity.type}:${entity.id}`, {
|
|
2214
|
+
startOffset: entity.startOffset,
|
|
2215
|
+
endOffset: entity.endOffset
|
|
2216
|
+
}]));
|
|
2217
|
+
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) {
|
|
2218
|
+
const range = {
|
|
2219
|
+
startOffset: block.startIndex,
|
|
2220
|
+
endOffset: block.startIndex + 1
|
|
2221
|
+
};
|
|
2222
|
+
entityRanges.set(`custom-block:${block.blockId}`, range);
|
|
2223
|
+
entityRanges.set(`drawing:${block.blockId}`, range);
|
|
2224
|
+
}
|
|
2225
|
+
const segmentIndex = {
|
|
2226
|
+
body,
|
|
2227
|
+
entities,
|
|
2228
|
+
entityRanges,
|
|
2229
|
+
paragraphContentStartOffsets: body == null ? /* @__PURE__ */ new Map() : (0, _univerjs_core.getParagraphContentStartOffsets)(body),
|
|
2230
|
+
paragraphsById: new Map(((body === null || body === void 0 ? void 0 : body.paragraphs) ?? []).filter((paragraph) => paragraph.paragraphId != null).map((paragraph) => [paragraph.paragraphId, paragraph]))
|
|
2198
2231
|
};
|
|
2199
|
-
|
|
2200
|
-
return
|
|
2201
|
-
"body",
|
|
2202
|
-
"sectionBreaks",
|
|
2203
|
-
storageIndex,
|
|
2204
|
-
key
|
|
2205
|
-
], segmentId)];
|
|
2232
|
+
resolverIndex.segments.set(segmentId, segmentIndex);
|
|
2233
|
+
return segmentIndex;
|
|
2206
2234
|
}
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
//#region src/commands/commands/update-document-paragraph-style.command.ts
|
|
2210
|
-
function isValidParams(params) {
|
|
2211
|
-
return Boolean((params === null || params === void 0 ? void 0 : params.unitId) && params.paragraphId && Number.isInteger(params.startOffset) && Number.isInteger(params.endOffset) && params.startOffset >= 0 && params.endOffset >= params.startOffset && params.style && Object.keys(params.style).length > 0);
|
|
2235
|
+
function getDocumentDrawingSegmentId(documentDataModel, drawingId) {
|
|
2236
|
+
return getDocumentPermissionResolverIndex(documentDataModel).drawingSegmentIds.get(drawingId) ?? "";
|
|
2212
2237
|
}
|
|
2213
|
-
function
|
|
2214
|
-
const
|
|
2215
|
-
|
|
2216
|
-
const
|
|
2217
|
-
|
|
2238
|
+
function getDocumentEditTargetObjectIds(documentDataModel, segmentId, range) {
|
|
2239
|
+
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
2240
|
+
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
2241
|
+
const { body } = segmentIndex;
|
|
2242
|
+
if (!body) return [];
|
|
2243
|
+
return [
|
|
2244
|
+
...getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex),
|
|
2245
|
+
...getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex),
|
|
2246
|
+
...getEntityPermissionObjectIds(segmentId, range, segmentIndex)
|
|
2247
|
+
];
|
|
2218
2248
|
}
|
|
2219
|
-
function
|
|
2220
|
-
const
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
}
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2249
|
+
function getDocumentEditTargetObjectIdsFromActions(documentDataModel, segmentId, actions) {
|
|
2250
|
+
const result = /* @__PURE__ */ new Set();
|
|
2251
|
+
if (actions == null) return [];
|
|
2252
|
+
const cursor = _univerjs_core.JSON1.type.readCursor(actions);
|
|
2253
|
+
cursor.traverse(null, () => {
|
|
2254
|
+
const path = cursor.getPath();
|
|
2255
|
+
const edit = cursor.getComponent();
|
|
2256
|
+
const scopedSegment = [
|
|
2257
|
+
"headers",
|
|
2258
|
+
"footers",
|
|
2259
|
+
"notes"
|
|
2260
|
+
].includes(String(path[0])) && typeof path[1] === "string" ? path[1] : segmentId;
|
|
2261
|
+
if (path[0] === "notes" && typeof path[1] === "string") getSectionPermissionObjectIds(documentDataModel, path[1], {
|
|
2262
|
+
startOffset: 0,
|
|
2263
|
+
endOffset: 0
|
|
2264
|
+
}).forEach((objectId) => result.add(objectId));
|
|
2265
|
+
if (path[0] === "noteSettings") getDocumentPermissionResolverIndex(documentDataModel).topLevelSections.forEach((section) => {
|
|
2266
|
+
result.add(getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
2267
|
+
});
|
|
2268
|
+
if (path[0] === "body" && path[1] === "sectionBreaks" && typeof path[2] === "number" && (path[3] === "noteProperties" || path[3] === "suppressEndnotes")) {
|
|
2269
|
+
var _documentDataModel$ge2;
|
|
2270
|
+
const sectionId = (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2.sectionBreaks) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2[path[2]]) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.sectionId;
|
|
2271
|
+
if (sectionId) result.add(getDocumentSectionPermissionObjectId("", sectionId));
|
|
2272
|
+
}
|
|
2273
|
+
if (path[path.length - 1] !== "body" || (edit === null || edit === void 0 ? void 0 : edit.et) !== _univerjs_core.TextX.id || !Array.isArray(edit.e) || !edit.e.every(isTextXAction)) return;
|
|
2274
|
+
const textActions = edit.e;
|
|
2275
|
+
let offset = 0;
|
|
2276
|
+
const addRange = (startOffset, endOffset) => {
|
|
2277
|
+
getDocumentEditTargetObjectIds(documentDataModel, scopedSegment, {
|
|
2278
|
+
startOffset,
|
|
2279
|
+
endOffset
|
|
2280
|
+
}).forEach((objectId) => result.add(objectId));
|
|
2281
|
+
};
|
|
2282
|
+
textActions.forEach((action) => {
|
|
2283
|
+
if (action.t === _univerjs_core.TextXActionType.INSERT) {
|
|
2284
|
+
addRange(offset, offset);
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
if (action.t === _univerjs_core.TextXActionType.DELETE) {
|
|
2288
|
+
addRange(offset, offset + action.len);
|
|
2289
|
+
offset += action.len;
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
if (action.body !== void 0 || action.oldBody !== void 0 || action.coverType !== void 0) addRange(offset, offset + action.len);
|
|
2293
|
+
offset += action.len;
|
|
2294
|
+
});
|
|
2257
2295
|
});
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
body:
|
|
2296
|
+
getDrawingIdsFromActions(actions).forEach((drawingId) => {
|
|
2297
|
+
var _documentDataModel$ge3, _body$customBlocks;
|
|
2298
|
+
result.add(getDocumentEntityPermissionObjectId(segmentId, "drawing", drawingId));
|
|
2299
|
+
const body = (_documentDataModel$ge3 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.getBody();
|
|
2300
|
+
const block = body === null || body === void 0 || (_body$customBlocks = body.customBlocks) === null || _body$customBlocks === void 0 ? void 0 : _body$customBlocks.find((item) => item.blockId === drawingId);
|
|
2301
|
+
if (block) getSectionPermissionObjectIds(documentDataModel, segmentId, {
|
|
2302
|
+
startOffset: block.startIndex,
|
|
2303
|
+
endOffset: block.startIndex + 1
|
|
2304
|
+
}).forEach((objectId) => result.add(objectId));
|
|
2263
2305
|
});
|
|
2264
|
-
return
|
|
2265
|
-
textX,
|
|
2266
|
-
initializesTextRuns
|
|
2267
|
-
};
|
|
2306
|
+
return [...result];
|
|
2268
2307
|
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
const segmentId = params.segmentId ?? "";
|
|
2279
|
-
const body = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
2280
|
-
if (!documentDataModel || !body) return false;
|
|
2281
|
-
const paragraph = getCurrentParagraph(body, params);
|
|
2282
|
-
if (!paragraph) return false;
|
|
2283
|
-
const { textX, initializesTextRuns } = createParagraphStyleTextX(body, paragraph, params);
|
|
2284
|
-
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
2285
|
-
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
2286
|
-
let actions = jsonX.editOp(textX.serialize(), path);
|
|
2287
|
-
if (initializesTextRuns) {
|
|
2288
|
-
const initializeTextRunsActions = jsonX.replaceOp([...path, "textRuns"], void 0, [{
|
|
2289
|
-
st: params.startOffset,
|
|
2290
|
-
ed: params.endOffset,
|
|
2291
|
-
ts: _univerjs_core.Tools.deepClone(params.style.textStyle)
|
|
2292
|
-
}]);
|
|
2293
|
-
actions = _univerjs_core.JSONX.compose(initializeTextRunsActions, actions);
|
|
2308
|
+
function getDrawingIdsFromActions(actions) {
|
|
2309
|
+
const result = /* @__PURE__ */ new Set();
|
|
2310
|
+
const visit = (value) => {
|
|
2311
|
+
if (Array.isArray(value)) {
|
|
2312
|
+
value.forEach((item, index) => {
|
|
2313
|
+
if (item === "drawings" && typeof value[index + 1] === "string") result.add(value[index + 1]);
|
|
2314
|
+
visit(item);
|
|
2315
|
+
});
|
|
2316
|
+
return;
|
|
2294
2317
|
}
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
segmentId,
|
|
2298
|
-
actions,
|
|
2299
|
-
textRanges: null,
|
|
2300
|
-
noNeedSetTextRange: true,
|
|
2301
|
-
isEditing: false,
|
|
2302
|
-
trigger: UpdateDocumentParagraphStyleCommand.id
|
|
2303
|
-
}));
|
|
2304
|
-
}
|
|
2305
|
-
};
|
|
2306
|
-
|
|
2307
|
-
//#endregion
|
|
2308
|
-
//#region src/utils/section-columns.ts
|
|
2309
|
-
function resolveSectionValue(sectionValue, documentValue, fallback) {
|
|
2310
|
-
return sectionValue ?? documentValue ?? fallback;
|
|
2311
|
-
}
|
|
2312
|
-
function getEffectivePageSize(documentStyle, section) {
|
|
2313
|
-
var _section$pageSize, _documentStyle$pageSi, _section$pageSize2, _documentStyle$pageSi2;
|
|
2314
|
-
const fallback = _univerjs_core.PAGE_SIZE[_univerjs_core.PaperType.A4];
|
|
2315
|
-
return {
|
|
2316
|
-
width: resolveSectionValue(section === null || section === void 0 || (_section$pageSize = section.pageSize) === null || _section$pageSize === void 0 ? void 0 : _section$pageSize.width, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width, fallback.width),
|
|
2317
|
-
height: resolveSectionValue(section === null || section === void 0 || (_section$pageSize2 = section.pageSize) === null || _section$pageSize2 === void 0 ? void 0 : _section$pageSize2.height, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.height, fallback.height)
|
|
2318
|
+
if (!isRecord$2(value)) return;
|
|
2319
|
+
Object.values(value).forEach(visit);
|
|
2318
2320
|
};
|
|
2321
|
+
visit(actions);
|
|
2322
|
+
return [...result];
|
|
2319
2323
|
}
|
|
2320
|
-
function
|
|
2321
|
-
return
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
left: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
|
|
2325
|
-
right: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN)
|
|
2326
|
-
};
|
|
2324
|
+
function isTextXAction(value) {
|
|
2325
|
+
if (!isRecord$2(value) || typeof value.len !== "number") return false;
|
|
2326
|
+
if (value.t === _univerjs_core.TextXActionType.INSERT) return isRecord$2(value.body);
|
|
2327
|
+
return value.t === _univerjs_core.TextXActionType.RETAIN || value.t === _univerjs_core.TextXActionType.DELETE;
|
|
2327
2328
|
}
|
|
2328
|
-
function
|
|
2329
|
-
|
|
2330
|
-
pageSize.width,
|
|
2331
|
-
pageSize.height,
|
|
2332
|
-
contentSize.width,
|
|
2333
|
-
contentSize.height
|
|
2334
|
-
].every((value) => Number.isFinite(value) && value > 0)) throw new RangeError("Effective section page setup must leave a positive content area and use finite positive page dimensions.");
|
|
2329
|
+
function isRecord$2(value) {
|
|
2330
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2335
2331
|
}
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
const
|
|
2339
|
-
|
|
2340
|
-
const contentSize = {
|
|
2341
|
-
width: getSectionContentWidth(documentStyle, section),
|
|
2342
|
-
height: pageSize.height - margins.top - margins.bottom
|
|
2343
|
-
};
|
|
2344
|
-
assertPositivePageSetup(pageSize, contentSize);
|
|
2345
|
-
const pageNumberStart = (section === null || section === void 0 ? void 0 : section.pageNumberStart) ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageNumberStart);
|
|
2346
|
-
return {
|
|
2347
|
-
pageSize,
|
|
2348
|
-
pageOrient: resolveSectionValue(section === null || section === void 0 ? void 0 : section.pageOrient, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageOrient, _univerjs_core.PageOrientType.PORTRAIT),
|
|
2349
|
-
margins,
|
|
2350
|
-
contentSize,
|
|
2351
|
-
...pageNumberStart == null ? {} : { pageNumberStart }
|
|
2352
|
-
};
|
|
2332
|
+
function getDocumentEntityParentPermissionObjectIds(documentDataModel, segmentId, entityType, entityId) {
|
|
2333
|
+
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
2334
|
+
const range = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex).entityRanges.get(`${entityType}:${entityId}`) ?? null;
|
|
2335
|
+
return range ? getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex) : [];
|
|
2353
2336
|
}
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
const
|
|
2358
|
-
|
|
2337
|
+
function getDocumentParagraphParentPermissionObjectIds(documentDataModel, segmentId, paragraphId) {
|
|
2338
|
+
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
2339
|
+
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
2340
|
+
const { body } = segmentIndex;
|
|
2341
|
+
const paragraph = segmentIndex.paragraphsById.get(paragraphId);
|
|
2342
|
+
if (!body || !paragraph) return [];
|
|
2343
|
+
return getSectionPermissionObjectIds(documentDataModel, segmentId, {
|
|
2344
|
+
startOffset: segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph),
|
|
2345
|
+
endOffset: paragraph.startIndex + 1
|
|
2346
|
+
}, resolverIndex);
|
|
2359
2347
|
}
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2348
|
+
function getDocumentSectionPermissionObjectIdsByIds(sectionIds) {
|
|
2349
|
+
return Array.from(sectionIds, (sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
|
|
2350
|
+
}
|
|
2351
|
+
function getDocumentSectionIdsAtOffset(body, offset) {
|
|
2352
|
+
return getSectionsIntersectingRange(getTopLevelSectionBreaks(body), {
|
|
2353
|
+
startOffset: offset,
|
|
2354
|
+
endOffset: offset
|
|
2355
|
+
}).map((section) => section.sectionId);
|
|
2356
|
+
}
|
|
2357
|
+
function getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
|
|
2358
|
+
if (segmentId) {
|
|
2359
|
+
const referenceRange = resolverIndex.footnoteReferenceRanges.get(segmentId);
|
|
2360
|
+
if (referenceRange) return getDocumentEditTargetObjectIds(documentDataModel, "", referenceRange);
|
|
2361
|
+
return getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, resolverIndex.topLevelSections).map((sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
|
|
2369
2362
|
}
|
|
2370
|
-
return (
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2363
|
+
return getSectionsIntersectingRange(resolverIndex.topLevelSections, range).map((section) => getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
2364
|
+
}
|
|
2365
|
+
function getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex) {
|
|
2366
|
+
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
2367
|
+
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
2368
|
+
return (body.paragraphs ?? []).filter((paragraph) => intersectsRange(segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph), paragraph.startIndex + 1, startOffset, endOffset)).flatMap((paragraph) => paragraph.paragraphId ? [getDocumentParagraphPermissionObjectId(segmentId, paragraph.paragraphId)] : []);
|
|
2369
|
+
}
|
|
2370
|
+
function getEntityPermissionObjectIds(segmentId, range, segmentIndex) {
|
|
2371
|
+
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
2372
|
+
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
2373
|
+
return segmentIndex.entities.filter((item) => intersectsRange(item.startOffset, item.endOffset, startOffset, endOffset)).map((item) => getDocumentEntityPermissionObjectId(segmentId, item.type, item.id));
|
|
2374
|
+
}
|
|
2375
|
+
function getSectionsIntersectingRange(sections, range) {
|
|
2376
|
+
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
2377
|
+
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
2378
|
+
return sections.filter((section, index) => intersectsRange(index === 0 ? 0 : sections[index - 1].startIndex + 1, section.startIndex + 1, startOffset, endOffset));
|
|
2379
|
+
}
|
|
2380
|
+
function intersectsRange(targetStart, targetEnd, rangeStart, rangeEnd) {
|
|
2381
|
+
if (rangeStart === rangeEnd) return rangeStart >= targetStart && rangeStart < targetEnd;
|
|
2382
|
+
return rangeStart < targetEnd && rangeEnd > targetStart;
|
|
2383
|
+
}
|
|
2384
|
+
function getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, sections = getDocumentPermissionResolverIndex(documentDataModel).topLevelSections) {
|
|
2385
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
2386
|
+
const result = /* @__PURE__ */ new Set();
|
|
2387
|
+
sections.forEach((section, sectionIndex) => {
|
|
2388
|
+
if (HEADER_FOOTER_REFERENCE_KEYS.some((key) => (0, _univerjs_core.resolveSectionHeaderFooterReference)(snapshot.documentStyle, sections, sectionIndex, key).segmentId === segmentId)) result.add(section.sectionId);
|
|
2389
|
+
});
|
|
2390
|
+
return [...result];
|
|
2374
2391
|
}
|
|
2375
2392
|
|
|
2376
2393
|
//#endregion
|
|
2377
|
-
//#region src/commands/commands/
|
|
2378
|
-
const
|
|
2379
|
-
id: "doc.command.
|
|
2394
|
+
//#region src/commands/commands/set-heading-collapsed.command.ts
|
|
2395
|
+
const SetHeadingCollapsedCommand = {
|
|
2396
|
+
id: "doc.command.set-heading-collapsed",
|
|
2380
2397
|
type: _univerjs_core.CommandType.COMMAND,
|
|
2381
2398
|
handler: (accessor, params) => {
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
const
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
const body =
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
textX.push({
|
|
2399
|
+
var _body$paragraphs;
|
|
2400
|
+
if (!params || typeof params.collapsed !== "boolean") return false;
|
|
2401
|
+
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
2402
|
+
if (!doc || doc.getDisabled() || doc.getSnapshot().documentStyle.documentFlavor !== _univerjs_core.DocumentFlavor.MODERN) return false;
|
|
2403
|
+
const body = doc.getBody();
|
|
2404
|
+
const matches = (body === null || body === void 0 || (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.filter((paragraph) => paragraph.paragraphId === params.paragraphId)) ?? [];
|
|
2405
|
+
const paragraph = matches[0];
|
|
2406
|
+
if (!body || matches.length !== 1 || paragraph.headingCollapsed === true === params.collapsed) return false;
|
|
2407
|
+
const viewModel = new _univerjs_engine_render.DocumentViewModel(doc);
|
|
2408
|
+
try {
|
|
2409
|
+
var _selectionService$get;
|
|
2410
|
+
const section = viewModel.getHeadingSections().find((section) => section.paragraphId === params.paragraphId);
|
|
2411
|
+
if (!section || params.collapsed && section.startOffset >= section.endOffset || viewModel.getCollapsedHeadingAtOffset(paragraph.startIndex)) return false;
|
|
2412
|
+
const targets = getDocumentEditTargetObjectIds(doc, "", {
|
|
2413
|
+
startOffset: (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph),
|
|
2414
|
+
endOffset: paragraph.startIndex + 1
|
|
2415
|
+
});
|
|
2416
|
+
if (!canEditDocumentTargets(accessor.get(_univerjs_core.IPermissionService), params.unitId, targets)) return false;
|
|
2417
|
+
const textX = new _univerjs_core.TextX();
|
|
2418
|
+
if (paragraph.startIndex > 0) textX.push({
|
|
2403
2419
|
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2404
|
-
len:
|
|
2420
|
+
len: paragraph.startIndex
|
|
2405
2421
|
});
|
|
2406
2422
|
textX.push({
|
|
2407
2423
|
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2408
2424
|
len: 1,
|
|
2409
|
-
coverType: _univerjs_core.UpdateDocsAttributeType.
|
|
2425
|
+
coverType: _univerjs_core.UpdateDocsAttributeType.COVER,
|
|
2410
2426
|
body: {
|
|
2411
2427
|
dataStream: "",
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
startIndex: 0
|
|
2428
|
+
paragraphs: [{
|
|
2429
|
+
paragraphId: paragraph.paragraphId,
|
|
2430
|
+
startIndex: 0,
|
|
2431
|
+
headingCollapsed: params.collapsed
|
|
2417
2432
|
}]
|
|
2418
2433
|
}
|
|
2419
2434
|
});
|
|
2420
|
-
|
|
2435
|
+
const actions = _univerjs_core.JSONX.getInstance().editOp(textX.serialize(), (0, _univerjs_core.getRichTextEditPath)(doc));
|
|
2436
|
+
const selectionService = accessor.get(DocSelectionManagerService);
|
|
2437
|
+
const selectionTarget = {
|
|
2438
|
+
unitId: params.unitId,
|
|
2439
|
+
subUnitId: params.unitId
|
|
2440
|
+
};
|
|
2441
|
+
const ranges = selectionService.getDocRanges(selectionTarget) ?? [];
|
|
2442
|
+
const hidesSelection = params.collapsed && !((_selectionService$get = selectionService.getSelectionInfo(selectionTarget)) === null || _selectionService$get === void 0 ? void 0 : _selectionService$get.segmentId) && ranges.some((range) => !range.segmentId && range.startOffset != null && range.endOffset != null && range.endOffset >= section.startOffset && range.startOffset < section.endOffset);
|
|
2443
|
+
return Boolean(accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(RichTextEditingMutation.id, {
|
|
2444
|
+
unitId: params.unitId,
|
|
2445
|
+
actions,
|
|
2446
|
+
textRanges: hidesSelection ? [{
|
|
2447
|
+
startOffset: paragraph.startIndex,
|
|
2448
|
+
endOffset: paragraph.startIndex,
|
|
2449
|
+
collapsed: true
|
|
2450
|
+
}] : null,
|
|
2451
|
+
prevTextRanges: ranges,
|
|
2452
|
+
noNeedSetTextRange: !hidesSelection,
|
|
2453
|
+
isEditing: false,
|
|
2454
|
+
trigger: SetHeadingCollapsedCommand.id
|
|
2455
|
+
}));
|
|
2456
|
+
} finally {
|
|
2457
|
+
viewModel.dispose();
|
|
2421
2458
|
}
|
|
2422
|
-
|
|
2459
|
+
}
|
|
2460
|
+
};
|
|
2461
|
+
|
|
2462
|
+
//#endregion
|
|
2463
|
+
//#region src/commands/commands/set-section-header-footer-link.command.ts
|
|
2464
|
+
const SetSectionHeaderFooterLinkCommand = {
|
|
2465
|
+
id: "doc.command.set-section-header-footer-link",
|
|
2466
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2467
|
+
handler: (accessor, params) => {
|
|
2468
|
+
var _snapshot$body$sectio;
|
|
2469
|
+
if (!params) return false;
|
|
2470
|
+
const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
2471
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2472
|
+
const documentDataModel = instanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
2473
|
+
const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
|
|
2474
|
+
if (!documentDataModel || !(snapshot === null || snapshot === void 0 ? void 0 : snapshot.body) || snapshot.documentStyle.documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL) return false;
|
|
2475
|
+
const sections = getTopLevelSectionBreaks(snapshot.body);
|
|
2476
|
+
const sectionIndex = sections.findIndex((section) => section.sectionId === params.sectionId);
|
|
2477
|
+
if (sectionIndex <= 0) return false;
|
|
2478
|
+
const storageIndex = ((_snapshot$body$sectio = snapshot.body.sectionBreaks) === null || _snapshot$body$sectio === void 0 ? void 0 : _snapshot$body$sectio.findIndex((item) => item.sectionId === params.sectionId)) ?? -1;
|
|
2479
|
+
if (storageIndex < 0) return false;
|
|
2480
|
+
const context = {
|
|
2481
|
+
snapshot,
|
|
2482
|
+
sections,
|
|
2483
|
+
sectionIndex,
|
|
2484
|
+
storageIndex,
|
|
2485
|
+
key: (0, _univerjs_core.getSectionHeaderFooterReferenceKey)(params.kind, params.variant)
|
|
2486
|
+
};
|
|
2487
|
+
const rawActions = params.linkedToPrevious ? buildLinkActions(context, params.kind) : buildUnlinkActions(context, params.kind, params.segmentId);
|
|
2488
|
+
if (!rawActions) return false;
|
|
2423
2489
|
const mutation = {
|
|
2424
2490
|
id: RichTextEditingMutation.id,
|
|
2425
2491
|
params: {
|
|
2426
2492
|
unitId: params.unitId,
|
|
2427
|
-
actions:
|
|
2493
|
+
actions: rawActions.reduce((actions, action) => _univerjs_core.JSONX.compose(actions, action), null),
|
|
2428
2494
|
textRanges: null,
|
|
2429
2495
|
noNeedSetTextRange: true,
|
|
2430
2496
|
debounce: true,
|
|
2431
2497
|
isEditing: false,
|
|
2432
|
-
trigger:
|
|
2498
|
+
trigger: SetSectionHeaderFooterLinkCommand.id
|
|
2433
2499
|
}
|
|
2434
2500
|
};
|
|
2435
2501
|
return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
|
|
2436
2502
|
}
|
|
2437
2503
|
};
|
|
2438
|
-
|
|
2439
|
-
|
|
2504
|
+
function buildLinkActions(context, kind) {
|
|
2505
|
+
const { snapshot, sections, sectionIndex, storageIndex, key } = context;
|
|
2506
|
+
const section = sections[sectionIndex];
|
|
2507
|
+
const explicitSegmentId = section[key];
|
|
2508
|
+
if (typeof explicitSegmentId !== "string" || !explicitSegmentId) return null;
|
|
2509
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
2510
|
+
const actions = [jsonX.removeOp([
|
|
2511
|
+
"body",
|
|
2512
|
+
"sectionBreaks",
|
|
2513
|
+
storageIndex,
|
|
2514
|
+
key
|
|
2515
|
+
], explicitSegmentId)];
|
|
2516
|
+
const referenceKeys = kind === "header" ? [
|
|
2517
|
+
"defaultHeaderId",
|
|
2518
|
+
"firstPageHeaderId",
|
|
2519
|
+
"evenPageHeaderId"
|
|
2520
|
+
] : [
|
|
2521
|
+
"defaultFooterId",
|
|
2522
|
+
"firstPageFooterId",
|
|
2523
|
+
"evenPageFooterId"
|
|
2524
|
+
];
|
|
2525
|
+
const referencedByDocument = referenceKeys.some((referenceKey) => snapshot.documentStyle[referenceKey] === explicitSegmentId);
|
|
2526
|
+
const referencedBySection = sections.some((item) => referenceKeys.some((referenceKey) => !(item.sectionId === section.sectionId && referenceKey === key) && item[referenceKey] === explicitSegmentId));
|
|
2527
|
+
const resources = kind === "header" ? snapshot.headers : snapshot.footers;
|
|
2528
|
+
if (!referencedByDocument && !referencedBySection && (resources === null || resources === void 0 ? void 0 : resources[explicitSegmentId])) actions.push(jsonX.removeOp([kind === "header" ? "headers" : "footers", explicitSegmentId], resources[explicitSegmentId]));
|
|
2529
|
+
return actions;
|
|
2530
|
+
}
|
|
2531
|
+
function buildUnlinkActions(context, kind, requestedSegmentId) {
|
|
2532
|
+
const { snapshot, sections, sectionIndex, storageIndex, key } = context;
|
|
2533
|
+
const explicitSegmentId = sections[sectionIndex][key];
|
|
2534
|
+
if (typeof explicitSegmentId === "string" && explicitSegmentId) return null;
|
|
2535
|
+
const sourceSegmentId = (0, _univerjs_core.resolveSectionHeaderFooterReference)(snapshot.documentStyle, sections, sectionIndex - 1, key).segmentId;
|
|
2536
|
+
const segmentId = requestedSegmentId ?? (0, _univerjs_core.generateRandomId)(6);
|
|
2537
|
+
const resources = kind === "header" ? snapshot.headers : snapshot.footers;
|
|
2538
|
+
if (resources === null || resources === void 0 ? void 0 : resources[segmentId]) return null;
|
|
2539
|
+
const source = sourceSegmentId ? resources === null || resources === void 0 ? void 0 : resources[sourceSegmentId] : void 0;
|
|
2540
|
+
const idKey = kind === "header" ? "headerId" : "footerId";
|
|
2541
|
+
const resource = source ? {
|
|
2542
|
+
..._univerjs_core.Tools.deepClone(source),
|
|
2543
|
+
[idKey]: segmentId
|
|
2544
|
+
} : {
|
|
2545
|
+
[idKey]: segmentId,
|
|
2546
|
+
body: getEmptyHeaderFooterBody()
|
|
2547
|
+
};
|
|
2548
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
2549
|
+
return [jsonX.insertOp([kind === "header" ? "headers" : "footers", segmentId], resource), jsonX.insertOp([
|
|
2550
|
+
"body",
|
|
2551
|
+
"sectionBreaks",
|
|
2552
|
+
storageIndex,
|
|
2553
|
+
key
|
|
2554
|
+
], segmentId)];
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
//#endregion
|
|
2558
|
+
//#region src/commands/commands/update-document-paragraph-style.command.ts
|
|
2559
|
+
function isValidParams(params) {
|
|
2560
|
+
return Boolean((params === null || params === void 0 ? void 0 : params.unitId) && params.paragraphId && Number.isInteger(params.startOffset) && Number.isInteger(params.endOffset) && params.startOffset >= 0 && params.endOffset >= params.startOffset && params.style && Object.keys(params.style).length > 0);
|
|
2561
|
+
}
|
|
2562
|
+
function getCurrentParagraph(body, params) {
|
|
2563
|
+
const matches = (body.paragraphs ?? []).filter((paragraph) => paragraph.paragraphId === params.paragraphId);
|
|
2564
|
+
if (matches.length !== 1) return null;
|
|
2565
|
+
const paragraph = matches[0];
|
|
2566
|
+
return (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph) === params.startOffset && paragraph.startIndex === params.endOffset && body.dataStream[params.endOffset] === "\r" ? paragraph : null;
|
|
2567
|
+
}
|
|
2568
|
+
function createParagraphStyleTextX(body, paragraph, params) {
|
|
2569
|
+
const textX = new _univerjs_core.TextX();
|
|
2570
|
+
const initializesTextRuns = Boolean(params.style.textStyle && params.startOffset < params.endOffset && body.textRuns == null);
|
|
2571
|
+
if (params.startOffset > 0) textX.push({
|
|
2572
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2573
|
+
len: params.startOffset
|
|
2574
|
+
});
|
|
2575
|
+
if (params.style.textStyle && params.startOffset < params.endOffset && !initializesTextRuns) textX.push({
|
|
2576
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2577
|
+
len: params.endOffset - params.startOffset,
|
|
2578
|
+
coverType: _univerjs_core.UpdateDocsAttributeType.COVER,
|
|
2579
|
+
body: {
|
|
2580
|
+
dataStream: "",
|
|
2581
|
+
textRuns: [{
|
|
2582
|
+
st: 0,
|
|
2583
|
+
ed: params.endOffset - params.startOffset,
|
|
2584
|
+
ts: _univerjs_core.Tools.deepClone(params.style.textStyle)
|
|
2585
|
+
}]
|
|
2586
|
+
}
|
|
2587
|
+
});
|
|
2588
|
+
else if (params.startOffset < params.endOffset) textX.push({
|
|
2589
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2590
|
+
len: params.endOffset - params.startOffset
|
|
2591
|
+
});
|
|
2592
|
+
const paragraphBody = {
|
|
2593
|
+
dataStream: "",
|
|
2594
|
+
paragraphs: [{
|
|
2595
|
+
..._univerjs_core.Tools.deepClone(paragraph),
|
|
2596
|
+
startIndex: 0,
|
|
2597
|
+
paragraphStyle: {
|
|
2598
|
+
..._univerjs_core.Tools.deepClone(paragraph.paragraphStyle ?? {}),
|
|
2599
|
+
..._univerjs_core.Tools.deepClone(params.style)
|
|
2600
|
+
}
|
|
2601
|
+
}]
|
|
2602
|
+
};
|
|
2603
|
+
Object.defineProperty(paragraphBody, _univerjs_core.RESTORE_INSERTED_PARAGRAPH_IDS, {
|
|
2604
|
+
value: true,
|
|
2605
|
+
enumerable: true
|
|
2606
|
+
});
|
|
2607
|
+
textX.push({
|
|
2608
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2609
|
+
len: 1,
|
|
2610
|
+
coverType: _univerjs_core.UpdateDocsAttributeType.REPLACE,
|
|
2611
|
+
body: paragraphBody
|
|
2612
|
+
});
|
|
2613
|
+
return {
|
|
2614
|
+
textX,
|
|
2615
|
+
initializesTextRuns
|
|
2616
|
+
};
|
|
2617
|
+
}
|
|
2618
|
+
const UpdateDocumentParagraphStyleCommand = {
|
|
2619
|
+
id: "doc.command.update-paragraph-style",
|
|
2440
2620
|
type: _univerjs_core.CommandType.COMMAND,
|
|
2441
2621
|
handler: (accessor, params) => {
|
|
2442
|
-
var
|
|
2443
|
-
if (!params) return false;
|
|
2444
|
-
const
|
|
2445
|
-
|
|
2446
|
-
const
|
|
2447
|
-
const
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
const
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
});
|
|
2464
|
-
if (nextSection && params.nextSectionType != null) {
|
|
2465
|
-
textX.retain(nextSection.startIndex - params.offset);
|
|
2466
|
-
textX.push({
|
|
2467
|
-
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2468
|
-
len: 1,
|
|
2469
|
-
coverType: _univerjs_core.UpdateDocsAttributeType.REPLACE,
|
|
2470
|
-
body: {
|
|
2471
|
-
dataStream: "",
|
|
2472
|
-
sectionBreaks: [{
|
|
2473
|
-
..._univerjs_core.Tools.deepClone(nextSection),
|
|
2474
|
-
sectionType: params.nextSectionType,
|
|
2475
|
-
startIndex: 0
|
|
2476
|
-
}]
|
|
2477
|
-
}
|
|
2478
|
-
});
|
|
2622
|
+
var _documentDataModel$ge;
|
|
2623
|
+
if (!isValidParams(params)) return false;
|
|
2624
|
+
const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
2625
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2626
|
+
const documentDataModel = instanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
2627
|
+
const segmentId = params.segmentId ?? "";
|
|
2628
|
+
const body = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
2629
|
+
if (!documentDataModel || !body) return false;
|
|
2630
|
+
const paragraph = getCurrentParagraph(body, params);
|
|
2631
|
+
if (!paragraph) return false;
|
|
2632
|
+
const { textX, initializesTextRuns } = createParagraphStyleTextX(body, paragraph, params);
|
|
2633
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
2634
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
2635
|
+
let actions = jsonX.editOp(textX.serialize(), path);
|
|
2636
|
+
if (initializesTextRuns) {
|
|
2637
|
+
const initializeTextRunsActions = jsonX.replaceOp([...path, "textRuns"], void 0, [{
|
|
2638
|
+
st: params.startOffset,
|
|
2639
|
+
ed: params.endOffset,
|
|
2640
|
+
ts: _univerjs_core.Tools.deepClone(params.style.textStyle)
|
|
2641
|
+
}]);
|
|
2642
|
+
actions = _univerjs_core.JSONX.compose(initializeTextRunsActions, actions);
|
|
2479
2643
|
}
|
|
2480
|
-
return
|
|
2644
|
+
return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
|
|
2645
|
+
unitId: params.unitId,
|
|
2646
|
+
segmentId,
|
|
2647
|
+
actions,
|
|
2648
|
+
textRanges: null,
|
|
2649
|
+
noNeedSetTextRange: true,
|
|
2650
|
+
isEditing: false,
|
|
2651
|
+
trigger: UpdateDocumentParagraphStyleCommand.id
|
|
2652
|
+
}));
|
|
2481
2653
|
}
|
|
2482
2654
|
};
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2655
|
+
|
|
2656
|
+
//#endregion
|
|
2657
|
+
//#region src/utils/section-columns.ts
|
|
2658
|
+
function resolveSectionValue(sectionValue, documentValue, fallback) {
|
|
2659
|
+
return sectionValue ?? documentValue ?? fallback;
|
|
2660
|
+
}
|
|
2661
|
+
function getEffectivePageSize(documentStyle, section) {
|
|
2662
|
+
var _section$pageSize, _documentStyle$pageSi, _section$pageSize2, _documentStyle$pageSi2;
|
|
2663
|
+
const fallback = _univerjs_core.PAGE_SIZE[_univerjs_core.PaperType.A4];
|
|
2664
|
+
return {
|
|
2665
|
+
width: resolveSectionValue(section === null || section === void 0 || (_section$pageSize = section.pageSize) === null || _section$pageSize === void 0 ? void 0 : _section$pageSize.width, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width, fallback.width),
|
|
2666
|
+
height: resolveSectionValue(section === null || section === void 0 || (_section$pageSize2 = section.pageSize) === null || _section$pageSize2 === void 0 ? void 0 : _section$pageSize2.height, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.height, fallback.height)
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
function getEffectiveMargins(documentStyle, section) {
|
|
2670
|
+
return {
|
|
2671
|
+
top: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginTop, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginTop, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
|
|
2672
|
+
bottom: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginBottom, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginBottom, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
|
|
2673
|
+
left: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
|
|
2674
|
+
right: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN)
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
function assertPositivePageSetup(pageSize, contentSize) {
|
|
2678
|
+
if (![
|
|
2679
|
+
pageSize.width,
|
|
2680
|
+
pageSize.height,
|
|
2681
|
+
contentSize.width,
|
|
2682
|
+
contentSize.height
|
|
2683
|
+
].every((value) => Number.isFinite(value) && value > 0)) throw new RangeError("Effective section page setup must leave a positive content area and use finite positive page dimensions.");
|
|
2684
|
+
}
|
|
2685
|
+
/** Resolves nominal traditional page geometry without requiring a renderer. */
|
|
2686
|
+
function getEffectiveSectionPageSetup(documentStyle, section) {
|
|
2687
|
+
const pageSize = getEffectivePageSize(documentStyle, section);
|
|
2688
|
+
const margins = getEffectiveMargins(documentStyle, section);
|
|
2689
|
+
const contentSize = {
|
|
2690
|
+
width: getSectionContentWidth(documentStyle, section),
|
|
2691
|
+
height: pageSize.height - margins.top - margins.bottom
|
|
2692
|
+
};
|
|
2693
|
+
assertPositivePageSetup(pageSize, contentSize);
|
|
2694
|
+
const pageNumberStart = (section === null || section === void 0 ? void 0 : section.pageNumberStart) ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageNumberStart);
|
|
2695
|
+
return {
|
|
2696
|
+
pageSize,
|
|
2697
|
+
pageOrient: resolveSectionValue(section === null || section === void 0 ? void 0 : section.pageOrient, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageOrient, _univerjs_core.PageOrientType.PORTRAIT),
|
|
2698
|
+
margins,
|
|
2699
|
+
contentSize,
|
|
2700
|
+
...pageNumberStart == null ? {} : { pageNumberStart }
|
|
2701
|
+
};
|
|
2702
|
+
}
|
|
2703
|
+
/** Returns the usable horizontal layout width for a traditional section. */
|
|
2704
|
+
function getSectionContentWidth(documentStyle, section) {
|
|
2705
|
+
var _section$pageSize3, _documentStyle$pageSi3;
|
|
2706
|
+
const pageWidth = resolveSectionValue(section === null || section === void 0 || (_section$pageSize3 = section.pageSize) === null || _section$pageSize3 === void 0 ? void 0 : _section$pageSize3.width, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi3 = documentStyle.pageSize) === null || _documentStyle$pageSi3 === void 0 ? void 0 : _documentStyle$pageSi3.width, _univerjs_core.PAGE_SIZE[_univerjs_core.PaperType.A4].width);
|
|
2707
|
+
return Math.max(0, pageWidth - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN) - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN));
|
|
2708
|
+
}
|
|
2709
|
+
/** Creates explicit OOXML section columns from a count, gap, and optional widths. */
|
|
2710
|
+
function createSectionColumnProperties(documentStyle, section, columnCount, gap, widths) {
|
|
2711
|
+
if (columnCount <= 1) return [];
|
|
2712
|
+
const safeGap = Math.max(0, gap);
|
|
2713
|
+
const contentWidth = getSectionContentWidth(documentStyle, section);
|
|
2714
|
+
const availableWidth = Math.max(0, contentWidth - safeGap * (columnCount - 1));
|
|
2715
|
+
if (widths) {
|
|
2716
|
+
if (widths.some((width) => !Number.isFinite(width) || width < 0)) throw new RangeError("Section column widths must be finite and non-negative.");
|
|
2717
|
+
if (widths.reduce((sum, width) => sum + width, 0) > availableWidth) throw new RangeError("Section columns exceed the available page content width.");
|
|
2718
|
+
}
|
|
2719
|
+
return (widths ?? Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
|
|
2720
|
+
width: Math.max(0, width),
|
|
2721
|
+
paddingEnd: index === columnCount - 1 ? 0 : safeGap
|
|
2722
|
+
}));
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
//#endregion
|
|
2726
|
+
//#region src/commands/commands/update-document-section.command.ts
|
|
2727
|
+
const UpdateDocumentSectionCommand = {
|
|
2728
|
+
id: "doc.command.update-section",
|
|
2729
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2730
|
+
handler: (accessor, params) => {
|
|
2731
|
+
if (!(params === null || params === void 0 ? void 0 : params.updates.length) || params.updates.some(({ sectionId, config }) => !sectionId || Object.keys(config).length === 0)) return false;
|
|
2732
|
+
const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
2733
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
2734
|
+
const documentDataModel = instanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
2735
|
+
if (!documentDataModel || documentDataModel.getDocumentStyle().documentFlavor !== _univerjs_core.DocumentFlavor.TRADITIONAL) return false;
|
|
2736
|
+
const body = documentDataModel.getBody();
|
|
2737
|
+
if (!body) return false;
|
|
2738
|
+
const updates = new Map(params.updates.map(({ sectionId, config }) => [sectionId, config]));
|
|
2739
|
+
if (updates.size !== params.updates.length) return false;
|
|
2740
|
+
const selectedIds = new Set(updates.keys());
|
|
2741
|
+
const sections = getTopLevelSectionBreaks(body).filter((section) => selectedIds.has(section.sectionId)).sort((left, right) => left.startIndex - right.startIndex);
|
|
2742
|
+
if (sections.length !== selectedIds.size) return false;
|
|
2743
|
+
const documentStyle = documentDataModel.getDocumentStyle();
|
|
2744
|
+
if (sections.some((section) => !isValidSectionConfig({
|
|
2745
|
+
...section,
|
|
2746
|
+
...updates.get(section.sectionId)
|
|
2747
|
+
}, documentStyle))) return false;
|
|
2748
|
+
const cursor = new _univerjs_core.MemoryCursor();
|
|
2749
|
+
const textX = new _univerjs_core.TextX();
|
|
2750
|
+
for (const section of sections) {
|
|
2751
|
+
textX.push({
|
|
2752
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2753
|
+
len: section.startIndex - cursor.cursor
|
|
2754
|
+
});
|
|
2755
|
+
textX.push({
|
|
2756
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2757
|
+
len: 1,
|
|
2758
|
+
coverType: _univerjs_core.UpdateDocsAttributeType.REPLACE,
|
|
2759
|
+
body: {
|
|
2760
|
+
dataStream: "",
|
|
2761
|
+
sectionBreaks: [{
|
|
2762
|
+
..._univerjs_core.Tools.deepClone(section),
|
|
2763
|
+
..._univerjs_core.Tools.deepClone(updates.get(section.sectionId)),
|
|
2764
|
+
sectionId: section.sectionId,
|
|
2765
|
+
startIndex: 0
|
|
2766
|
+
}]
|
|
2767
|
+
}
|
|
2768
|
+
});
|
|
2769
|
+
cursor.moveCursorTo(section.startIndex + 1);
|
|
2770
|
+
}
|
|
2771
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
2772
|
+
const mutation = {
|
|
2773
|
+
id: RichTextEditingMutation.id,
|
|
2774
|
+
params: {
|
|
2775
|
+
unitId: params.unitId,
|
|
2776
|
+
actions: jsonX.editOp(textX.serialize(), (0, _univerjs_core.getRichTextEditPath)(documentDataModel)),
|
|
2777
|
+
textRanges: null,
|
|
2778
|
+
noNeedSetTextRange: true,
|
|
2779
|
+
debounce: true,
|
|
2780
|
+
isEditing: false,
|
|
2781
|
+
trigger: UpdateDocumentSectionCommand.id
|
|
2782
|
+
}
|
|
2783
|
+
};
|
|
2784
|
+
return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
|
|
2785
|
+
}
|
|
2786
|
+
};
|
|
2787
|
+
const InsertDocumentSectionBreakCommand = {
|
|
2788
|
+
id: "doc.command.insert-section-break",
|
|
2789
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2790
|
+
handler: (accessor, params) => {
|
|
2791
|
+
var _body$sectionBreaks;
|
|
2792
|
+
if (!params) return false;
|
|
2793
|
+
const context = getTraditionalDocumentContext(accessor, params.unitId);
|
|
2794
|
+
if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(_univerjs_core.SectionType, params.nextSectionType)) return false;
|
|
2795
|
+
const { body, documentDataModel, commandService } = context;
|
|
2796
|
+
const insertedSection = {
|
|
2797
|
+
..._univerjs_core.Tools.deepClone(params.config ?? {}),
|
|
2798
|
+
sectionId: params.sectionId,
|
|
2799
|
+
startIndex: params.offset
|
|
2800
|
+
};
|
|
2801
|
+
if (!isValidTopLevelInsertionOffset(body, params.offset) || ((_body$sectionBreaks = body.sectionBreaks) === null || _body$sectionBreaks === void 0 ? void 0 : _body$sectionBreaks.some((section) => section.sectionId === params.sectionId)) || !isValidSectionConfig(insertedSection, documentDataModel.getDocumentStyle())) return false;
|
|
2802
|
+
const nextSection = params.nextSectionType == null ? void 0 : getTopLevelSectionBreaks(body).find((section) => section.startIndex >= params.offset);
|
|
2803
|
+
if (params.nextSectionType != null && !nextSection) return false;
|
|
2804
|
+
const textX = new _univerjs_core.TextX();
|
|
2805
|
+
textX.retain(params.offset);
|
|
2806
|
+
textX.insert(1, {
|
|
2807
|
+
dataStream: _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK,
|
|
2808
|
+
sectionBreaks: [{
|
|
2809
|
+
...insertedSection,
|
|
2810
|
+
startIndex: 0
|
|
2811
|
+
}]
|
|
2812
|
+
});
|
|
2813
|
+
if (nextSection && params.nextSectionType != null) {
|
|
2814
|
+
textX.retain(nextSection.startIndex - params.offset);
|
|
2815
|
+
textX.push({
|
|
2816
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
2817
|
+
len: 1,
|
|
2818
|
+
coverType: _univerjs_core.UpdateDocsAttributeType.REPLACE,
|
|
2819
|
+
body: {
|
|
2820
|
+
dataStream: "",
|
|
2821
|
+
sectionBreaks: [{
|
|
2822
|
+
..._univerjs_core.Tools.deepClone(nextSection),
|
|
2823
|
+
sectionType: params.nextSectionType,
|
|
2824
|
+
startIndex: 0
|
|
2825
|
+
}]
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2828
|
+
}
|
|
2829
|
+
return executeSectionTextX(commandService, documentDataModel, textX, InsertDocumentSectionBreakCommand.id);
|
|
2830
|
+
}
|
|
2831
|
+
};
|
|
2832
|
+
const InsertDocumentColumnBreakCommand = {
|
|
2833
|
+
id: "doc.command.insert-column-break",
|
|
2834
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
2835
|
+
handler: (accessor, params) => {
|
|
2836
|
+
if (!params) return false;
|
|
2837
|
+
const context = getTraditionalDocumentContext(accessor, params.unitId);
|
|
2838
|
+
if (!context || !isValidTopLevelInsertionOffset(context.body, params.offset)) return false;
|
|
2839
|
+
const textX = new _univerjs_core.TextX();
|
|
2840
|
+
textX.retain(params.offset);
|
|
2492
2841
|
textX.insert(1, {
|
|
2493
2842
|
dataStream: _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK,
|
|
2494
2843
|
customRanges: [{
|
|
@@ -2787,7 +3136,7 @@ function composeActions(actions) {
|
|
|
2787
3136
|
//#endregion
|
|
2788
3137
|
//#region package.json
|
|
2789
3138
|
var name = "@univerjs/docs";
|
|
2790
|
-
var version = "1.0
|
|
3139
|
+
var version = "1.2.0";
|
|
2791
3140
|
|
|
2792
3141
|
//#endregion
|
|
2793
3142
|
//#region src/config/config.ts
|
|
@@ -2865,270 +3214,6 @@ DocCustomRangeController = __decorate([
|
|
|
2865
3214
|
__decorateParam(2, _univerjs_core.IUniverInstanceService)
|
|
2866
3215
|
], DocCustomRangeController);
|
|
2867
3216
|
|
|
2868
|
-
//#endregion
|
|
2869
|
-
//#region src/services/permission/document-permission-resolver.ts
|
|
2870
|
-
const HEADER_FOOTER_REFERENCE_KEYS = [
|
|
2871
|
-
"defaultHeaderId",
|
|
2872
|
-
"defaultFooterId",
|
|
2873
|
-
"firstPageHeaderId",
|
|
2874
|
-
"firstPageFooterId",
|
|
2875
|
-
"evenPageHeaderId",
|
|
2876
|
-
"evenPageFooterId"
|
|
2877
|
-
];
|
|
2878
|
-
const documentPermissionResolverIndexCache = /* @__PURE__ */ new WeakMap();
|
|
2879
|
-
function getDocumentPermissionResolverIndex(documentDataModel) {
|
|
2880
|
-
var _getMutationRevision, _snapshot$body;
|
|
2881
|
-
const mutationRevision = ((_getMutationRevision = documentDataModel.getMutationRevision) === null || _getMutationRevision === void 0 ? void 0 : _getMutationRevision.call(documentDataModel)) ?? NaN;
|
|
2882
|
-
const cached = documentPermissionResolverIndexCache.get(documentDataModel);
|
|
2883
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.mutationRevision) === mutationRevision) return cached;
|
|
2884
|
-
const snapshot = documentDataModel.getSnapshot();
|
|
2885
|
-
const topLevelSections = snapshot.body ? getTopLevelSectionBreaks(snapshot.body) : [];
|
|
2886
|
-
const drawingSegmentIds = /* @__PURE__ */ new Map();
|
|
2887
|
-
const addDrawingSegments = (body, segmentId) => {
|
|
2888
|
-
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) if (!drawingSegmentIds.has(block.blockId)) drawingSegmentIds.set(block.blockId, segmentId);
|
|
2889
|
-
};
|
|
2890
|
-
addDrawingSegments(snapshot.body, "");
|
|
2891
|
-
Object.entries(snapshot.headers ?? {}).forEach(([segmentId, header]) => addDrawingSegments(header.body, segmentId));
|
|
2892
|
-
Object.entries(snapshot.footers ?? {}).forEach(([segmentId, footer]) => addDrawingSegments(footer.body, segmentId));
|
|
2893
|
-
Object.entries(snapshot.notes ?? {}).forEach(([segmentId, footnote]) => addDrawingSegments(footnote.body, segmentId));
|
|
2894
|
-
const footnoteReferenceRanges = /* @__PURE__ */ new Map();
|
|
2895
|
-
for (const reference of ((_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.customRanges) ?? []) {
|
|
2896
|
-
var _reference$properties;
|
|
2897
|
-
if ((reference.rangeType === _univerjs_core.CustomRangeType.FOOTNOTE || reference.rangeType === _univerjs_core.CustomRangeType.ENDNOTE) && typeof ((_reference$properties = reference.properties) === null || _reference$properties === void 0 ? void 0 : _reference$properties.noteId) === "string") footnoteReferenceRanges.set(reference.properties.noteId, {
|
|
2898
|
-
startOffset: reference.startIndex,
|
|
2899
|
-
endOffset: reference.endIndex + 1
|
|
2900
|
-
});
|
|
2901
|
-
}
|
|
2902
|
-
const index = {
|
|
2903
|
-
drawingSegmentIds,
|
|
2904
|
-
footnoteReferenceRanges,
|
|
2905
|
-
mutationRevision,
|
|
2906
|
-
segments: /* @__PURE__ */ new Map(),
|
|
2907
|
-
topLevelSections
|
|
2908
|
-
};
|
|
2909
|
-
documentPermissionResolverIndexCache.set(documentDataModel, index);
|
|
2910
|
-
return index;
|
|
2911
|
-
}
|
|
2912
|
-
function getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
|
|
2913
|
-
var _documentDataModel$ge, _snapshot$notes;
|
|
2914
|
-
const cached = resolverIndex.segments.get(segmentId);
|
|
2915
|
-
if (cached) return cached;
|
|
2916
|
-
const body = ((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody()) ?? null;
|
|
2917
|
-
const snapshot = documentDataModel.getSnapshot();
|
|
2918
|
-
const note = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
|
|
2919
|
-
const drawings = (note ? note.drawings : snapshot.drawings) ?? {};
|
|
2920
|
-
const entities = body == null ? [] : [
|
|
2921
|
-
...(body.tables ?? []).map((item) => ({
|
|
2922
|
-
type: "table",
|
|
2923
|
-
id: item.tableId,
|
|
2924
|
-
startOffset: item.startIndex,
|
|
2925
|
-
endOffset: item.endIndex
|
|
2926
|
-
})),
|
|
2927
|
-
...(body.customBlocks ?? []).map((item) => ({
|
|
2928
|
-
type: drawings[item.blockId] ? "drawing" : "custom-block",
|
|
2929
|
-
id: item.blockId,
|
|
2930
|
-
startOffset: item.startIndex,
|
|
2931
|
-
endOffset: item.startIndex + 1
|
|
2932
|
-
})),
|
|
2933
|
-
...(body.blockRanges ?? []).map((item) => ({
|
|
2934
|
-
type: "block-range",
|
|
2935
|
-
id: item.blockId,
|
|
2936
|
-
startOffset: item.startIndex,
|
|
2937
|
-
endOffset: item.endIndex + 1
|
|
2938
|
-
})),
|
|
2939
|
-
...(body.customRanges ?? []).map((item) => ({
|
|
2940
|
-
type: "custom-range",
|
|
2941
|
-
id: item.rangeId,
|
|
2942
|
-
startOffset: item.startIndex,
|
|
2943
|
-
endOffset: item.endIndex + 1
|
|
2944
|
-
})),
|
|
2945
|
-
...(body.columnGroups ?? []).map((item) => ({
|
|
2946
|
-
type: "column-group",
|
|
2947
|
-
id: item.columnGroupId,
|
|
2948
|
-
startOffset: item.startIndex,
|
|
2949
|
-
endOffset: item.endIndex + 1
|
|
2950
|
-
}))
|
|
2951
|
-
];
|
|
2952
|
-
const entityRanges = new Map(entities.map((entity) => [`${entity.type}:${entity.id}`, {
|
|
2953
|
-
startOffset: entity.startOffset,
|
|
2954
|
-
endOffset: entity.endOffset
|
|
2955
|
-
}]));
|
|
2956
|
-
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) {
|
|
2957
|
-
const range = {
|
|
2958
|
-
startOffset: block.startIndex,
|
|
2959
|
-
endOffset: block.startIndex + 1
|
|
2960
|
-
};
|
|
2961
|
-
entityRanges.set(`custom-block:${block.blockId}`, range);
|
|
2962
|
-
entityRanges.set(`drawing:${block.blockId}`, range);
|
|
2963
|
-
}
|
|
2964
|
-
const segmentIndex = {
|
|
2965
|
-
body,
|
|
2966
|
-
entities,
|
|
2967
|
-
entityRanges,
|
|
2968
|
-
paragraphContentStartOffsets: body == null ? /* @__PURE__ */ new Map() : (0, _univerjs_core.getParagraphContentStartOffsets)(body),
|
|
2969
|
-
paragraphsById: new Map(((body === null || body === void 0 ? void 0 : body.paragraphs) ?? []).filter((paragraph) => paragraph.paragraphId != null).map((paragraph) => [paragraph.paragraphId, paragraph]))
|
|
2970
|
-
};
|
|
2971
|
-
resolverIndex.segments.set(segmentId, segmentIndex);
|
|
2972
|
-
return segmentIndex;
|
|
2973
|
-
}
|
|
2974
|
-
function getDocumentDrawingSegmentId(documentDataModel, drawingId) {
|
|
2975
|
-
return getDocumentPermissionResolverIndex(documentDataModel).drawingSegmentIds.get(drawingId) ?? "";
|
|
2976
|
-
}
|
|
2977
|
-
function getDocumentEditTargetObjectIds(documentDataModel, segmentId, range) {
|
|
2978
|
-
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
2979
|
-
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
2980
|
-
const { body } = segmentIndex;
|
|
2981
|
-
if (!body) return [];
|
|
2982
|
-
return [
|
|
2983
|
-
...getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex),
|
|
2984
|
-
...getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex),
|
|
2985
|
-
...getEntityPermissionObjectIds(segmentId, range, segmentIndex)
|
|
2986
|
-
];
|
|
2987
|
-
}
|
|
2988
|
-
function getDocumentEditTargetObjectIdsFromActions(documentDataModel, segmentId, actions) {
|
|
2989
|
-
const result = /* @__PURE__ */ new Set();
|
|
2990
|
-
if (actions == null) return [];
|
|
2991
|
-
const cursor = _univerjs_core.JSON1.type.readCursor(actions);
|
|
2992
|
-
cursor.traverse(null, () => {
|
|
2993
|
-
const path = cursor.getPath();
|
|
2994
|
-
const edit = cursor.getComponent();
|
|
2995
|
-
const scopedSegment = [
|
|
2996
|
-
"headers",
|
|
2997
|
-
"footers",
|
|
2998
|
-
"notes"
|
|
2999
|
-
].includes(String(path[0])) && typeof path[1] === "string" ? path[1] : segmentId;
|
|
3000
|
-
if (path[0] === "notes" && typeof path[1] === "string") getSectionPermissionObjectIds(documentDataModel, path[1], {
|
|
3001
|
-
startOffset: 0,
|
|
3002
|
-
endOffset: 0
|
|
3003
|
-
}).forEach((objectId) => result.add(objectId));
|
|
3004
|
-
if (path[0] === "noteSettings") getDocumentPermissionResolverIndex(documentDataModel).topLevelSections.forEach((section) => {
|
|
3005
|
-
result.add(getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
3006
|
-
});
|
|
3007
|
-
if (path[0] === "body" && path[1] === "sectionBreaks" && typeof path[2] === "number" && (path[3] === "noteProperties" || path[3] === "suppressEndnotes")) {
|
|
3008
|
-
var _documentDataModel$ge2;
|
|
3009
|
-
const sectionId = (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2.sectionBreaks) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2[path[2]]) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.sectionId;
|
|
3010
|
-
if (sectionId) result.add(getDocumentSectionPermissionObjectId("", sectionId));
|
|
3011
|
-
}
|
|
3012
|
-
if (path[path.length - 1] !== "body" || (edit === null || edit === void 0 ? void 0 : edit.et) !== _univerjs_core.TextX.id || !Array.isArray(edit.e) || !edit.e.every(isTextXAction)) return;
|
|
3013
|
-
const textActions = edit.e;
|
|
3014
|
-
let offset = 0;
|
|
3015
|
-
const addRange = (startOffset, endOffset) => {
|
|
3016
|
-
getDocumentEditTargetObjectIds(documentDataModel, scopedSegment, {
|
|
3017
|
-
startOffset,
|
|
3018
|
-
endOffset
|
|
3019
|
-
}).forEach((objectId) => result.add(objectId));
|
|
3020
|
-
};
|
|
3021
|
-
textActions.forEach((action) => {
|
|
3022
|
-
if (action.t === _univerjs_core.TextXActionType.INSERT) {
|
|
3023
|
-
addRange(offset, offset);
|
|
3024
|
-
return;
|
|
3025
|
-
}
|
|
3026
|
-
if (action.t === _univerjs_core.TextXActionType.DELETE) {
|
|
3027
|
-
addRange(offset, offset + action.len);
|
|
3028
|
-
offset += action.len;
|
|
3029
|
-
return;
|
|
3030
|
-
}
|
|
3031
|
-
if (action.body !== void 0 || action.oldBody !== void 0 || action.coverType !== void 0) addRange(offset, offset + action.len);
|
|
3032
|
-
offset += action.len;
|
|
3033
|
-
});
|
|
3034
|
-
});
|
|
3035
|
-
getDrawingIdsFromActions(actions).forEach((drawingId) => {
|
|
3036
|
-
var _documentDataModel$ge3, _body$customBlocks;
|
|
3037
|
-
result.add(getDocumentEntityPermissionObjectId(segmentId, "drawing", drawingId));
|
|
3038
|
-
const body = (_documentDataModel$ge3 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.getBody();
|
|
3039
|
-
const block = body === null || body === void 0 || (_body$customBlocks = body.customBlocks) === null || _body$customBlocks === void 0 ? void 0 : _body$customBlocks.find((item) => item.blockId === drawingId);
|
|
3040
|
-
if (block) getSectionPermissionObjectIds(documentDataModel, segmentId, {
|
|
3041
|
-
startOffset: block.startIndex,
|
|
3042
|
-
endOffset: block.startIndex + 1
|
|
3043
|
-
}).forEach((objectId) => result.add(objectId));
|
|
3044
|
-
});
|
|
3045
|
-
return [...result];
|
|
3046
|
-
}
|
|
3047
|
-
function getDrawingIdsFromActions(actions) {
|
|
3048
|
-
const result = /* @__PURE__ */ new Set();
|
|
3049
|
-
const visit = (value) => {
|
|
3050
|
-
if (Array.isArray(value)) {
|
|
3051
|
-
value.forEach((item, index) => {
|
|
3052
|
-
if (item === "drawings" && typeof value[index + 1] === "string") result.add(value[index + 1]);
|
|
3053
|
-
visit(item);
|
|
3054
|
-
});
|
|
3055
|
-
return;
|
|
3056
|
-
}
|
|
3057
|
-
if (!isRecord$2(value)) return;
|
|
3058
|
-
Object.values(value).forEach(visit);
|
|
3059
|
-
};
|
|
3060
|
-
visit(actions);
|
|
3061
|
-
return [...result];
|
|
3062
|
-
}
|
|
3063
|
-
function isTextXAction(value) {
|
|
3064
|
-
if (!isRecord$2(value) || typeof value.len !== "number") return false;
|
|
3065
|
-
if (value.t === _univerjs_core.TextXActionType.INSERT) return isRecord$2(value.body);
|
|
3066
|
-
return value.t === _univerjs_core.TextXActionType.RETAIN || value.t === _univerjs_core.TextXActionType.DELETE;
|
|
3067
|
-
}
|
|
3068
|
-
function isRecord$2(value) {
|
|
3069
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3070
|
-
}
|
|
3071
|
-
function getDocumentEntityParentPermissionObjectIds(documentDataModel, segmentId, entityType, entityId) {
|
|
3072
|
-
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
3073
|
-
const range = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex).entityRanges.get(`${entityType}:${entityId}`) ?? null;
|
|
3074
|
-
return range ? getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex) : [];
|
|
3075
|
-
}
|
|
3076
|
-
function getDocumentParagraphParentPermissionObjectIds(documentDataModel, segmentId, paragraphId) {
|
|
3077
|
-
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
3078
|
-
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
3079
|
-
const { body } = segmentIndex;
|
|
3080
|
-
const paragraph = segmentIndex.paragraphsById.get(paragraphId);
|
|
3081
|
-
if (!body || !paragraph) return [];
|
|
3082
|
-
return getSectionPermissionObjectIds(documentDataModel, segmentId, {
|
|
3083
|
-
startOffset: segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph),
|
|
3084
|
-
endOffset: paragraph.startIndex + 1
|
|
3085
|
-
}, resolverIndex);
|
|
3086
|
-
}
|
|
3087
|
-
function getDocumentSectionPermissionObjectIdsByIds(sectionIds) {
|
|
3088
|
-
return Array.from(sectionIds, (sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
|
|
3089
|
-
}
|
|
3090
|
-
function getDocumentSectionIdsAtOffset(body, offset) {
|
|
3091
|
-
return getSectionsIntersectingRange(getTopLevelSectionBreaks(body), {
|
|
3092
|
-
startOffset: offset,
|
|
3093
|
-
endOffset: offset
|
|
3094
|
-
}).map((section) => section.sectionId);
|
|
3095
|
-
}
|
|
3096
|
-
function getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
|
|
3097
|
-
if (segmentId) {
|
|
3098
|
-
const referenceRange = resolverIndex.footnoteReferenceRanges.get(segmentId);
|
|
3099
|
-
if (referenceRange) return getDocumentEditTargetObjectIds(documentDataModel, "", referenceRange);
|
|
3100
|
-
return getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, resolverIndex.topLevelSections).map((sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
|
|
3101
|
-
}
|
|
3102
|
-
return getSectionsIntersectingRange(resolverIndex.topLevelSections, range).map((section) => getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
3103
|
-
}
|
|
3104
|
-
function getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex) {
|
|
3105
|
-
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
3106
|
-
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
3107
|
-
return (body.paragraphs ?? []).filter((paragraph) => intersectsRange(segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph), paragraph.startIndex + 1, startOffset, endOffset)).flatMap((paragraph) => paragraph.paragraphId ? [getDocumentParagraphPermissionObjectId(segmentId, paragraph.paragraphId)] : []);
|
|
3108
|
-
}
|
|
3109
|
-
function getEntityPermissionObjectIds(segmentId, range, segmentIndex) {
|
|
3110
|
-
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
3111
|
-
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
3112
|
-
return segmentIndex.entities.filter((item) => intersectsRange(item.startOffset, item.endOffset, startOffset, endOffset)).map((item) => getDocumentEntityPermissionObjectId(segmentId, item.type, item.id));
|
|
3113
|
-
}
|
|
3114
|
-
function getSectionsIntersectingRange(sections, range) {
|
|
3115
|
-
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
3116
|
-
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
3117
|
-
return sections.filter((section, index) => intersectsRange(index === 0 ? 0 : sections[index - 1].startIndex + 1, section.startIndex + 1, startOffset, endOffset));
|
|
3118
|
-
}
|
|
3119
|
-
function intersectsRange(targetStart, targetEnd, rangeStart, rangeEnd) {
|
|
3120
|
-
if (rangeStart === rangeEnd) return rangeStart >= targetStart && rangeStart < targetEnd;
|
|
3121
|
-
return rangeStart < targetEnd && rangeEnd > targetStart;
|
|
3122
|
-
}
|
|
3123
|
-
function getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, sections = getDocumentPermissionResolverIndex(documentDataModel).topLevelSections) {
|
|
3124
|
-
const snapshot = documentDataModel.getSnapshot();
|
|
3125
|
-
const result = /* @__PURE__ */ new Set();
|
|
3126
|
-
sections.forEach((section, sectionIndex) => {
|
|
3127
|
-
if (HEADER_FOOTER_REFERENCE_KEYS.some((key) => (0, _univerjs_core.resolveSectionHeaderFooterReference)(snapshot.documentStyle, sections, sectionIndex, key).segmentId === segmentId)) result.add(section.sectionId);
|
|
3128
|
-
});
|
|
3129
|
-
return [...result];
|
|
3130
|
-
}
|
|
3131
|
-
|
|
3132
3217
|
//#endregion
|
|
3133
3218
|
//#region src/controllers/doc-permission.controller.ts
|
|
3134
3219
|
const NON_EDIT_DOCUMENT_COMMAND_IDS = /* @__PURE__ */ new Set([
|
|
@@ -3705,6 +3790,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
|
3705
3790
|
SetDocumentPermissionsCommand,
|
|
3706
3791
|
SetDocumentDefaultParagraphStyleCommand,
|
|
3707
3792
|
SetDocumentNameCommand,
|
|
3793
|
+
SetHeadingCollapsedCommand,
|
|
3708
3794
|
SetSectionHeaderFooterLinkCommand,
|
|
3709
3795
|
UpdateDocumentParagraphStyleCommand,
|
|
3710
3796
|
UpdateDocumentSectionCommand,
|
|
@@ -4803,13 +4889,13 @@ exports.DeleteTextCommand = DeleteTextCommand;
|
|
|
4803
4889
|
exports.DocBlockMoveValidatorService = DocBlockMoveValidatorService;
|
|
4804
4890
|
exports.DocContentInsertService = DocContentInsertService;
|
|
4805
4891
|
exports.DocHistoryAction = DocHistoryAction;
|
|
4806
|
-
Object.defineProperty(exports,
|
|
4892
|
+
Object.defineProperty(exports, "DocInterceptorService", {
|
|
4807
4893
|
enumerable: true,
|
|
4808
4894
|
get: function () {
|
|
4809
4895
|
return DocInterceptorService;
|
|
4810
4896
|
}
|
|
4811
4897
|
});
|
|
4812
|
-
Object.defineProperty(exports,
|
|
4898
|
+
Object.defineProperty(exports, "DocLayoutExecutorService", {
|
|
4813
4899
|
enumerable: true,
|
|
4814
4900
|
get: function () {
|
|
4815
4901
|
return DocLayoutExecutorService;
|
|
@@ -4818,19 +4904,19 @@ Object.defineProperty(exports, 'DocLayoutExecutorService', {
|
|
|
4818
4904
|
exports.DocLayoutExecutorState = DocLayoutExecutorState;
|
|
4819
4905
|
exports.DocLayoutExecutorType = DocLayoutExecutorType;
|
|
4820
4906
|
exports.DocLayoutSessionStatus = DocLayoutSessionStatus;
|
|
4821
|
-
Object.defineProperty(exports,
|
|
4907
|
+
Object.defineProperty(exports, "DocSelectionManagerService", {
|
|
4822
4908
|
enumerable: true,
|
|
4823
4909
|
get: function () {
|
|
4824
4910
|
return DocSelectionManagerService;
|
|
4825
4911
|
}
|
|
4826
4912
|
});
|
|
4827
|
-
Object.defineProperty(exports,
|
|
4913
|
+
Object.defineProperty(exports, "DocSkeletonManagerService", {
|
|
4828
4914
|
enumerable: true,
|
|
4829
4915
|
get: function () {
|
|
4830
4916
|
return DocSkeletonManagerService;
|
|
4831
4917
|
}
|
|
4832
4918
|
});
|
|
4833
|
-
Object.defineProperty(exports,
|
|
4919
|
+
Object.defineProperty(exports, "DocStateChangeManagerService", {
|
|
4834
4920
|
enumerable: true,
|
|
4835
4921
|
get: function () {
|
|
4836
4922
|
return DocStateChangeManagerService;
|
|
@@ -4853,15 +4939,16 @@ exports.SetDocumentPermissionCommand = SetDocumentPermissionCommand;
|
|
|
4853
4939
|
exports.SetDocumentPermissionRuleMutation = SetDocumentPermissionRuleMutation;
|
|
4854
4940
|
exports.SetDocumentPermissionRulesMutation = SetDocumentPermissionRulesMutation;
|
|
4855
4941
|
exports.SetDocumentPermissionsCommand = SetDocumentPermissionsCommand;
|
|
4942
|
+
exports.SetHeadingCollapsedCommand = SetHeadingCollapsedCommand;
|
|
4856
4943
|
exports.SetSectionHeaderFooterLinkCommand = SetSectionHeaderFooterLinkCommand;
|
|
4857
4944
|
exports.SetTextSelectionsOperation = SetTextSelectionsOperation;
|
|
4858
|
-
Object.defineProperty(exports,
|
|
4945
|
+
Object.defineProperty(exports, "UniverDocsLayoutWorkerPlugin", {
|
|
4859
4946
|
enumerable: true,
|
|
4860
4947
|
get: function () {
|
|
4861
4948
|
return UniverDocsLayoutWorkerPlugin;
|
|
4862
4949
|
}
|
|
4863
4950
|
});
|
|
4864
|
-
Object.defineProperty(exports,
|
|
4951
|
+
Object.defineProperty(exports, "UniverDocsPlugin", {
|
|
4865
4952
|
enumerable: true,
|
|
4866
4953
|
get: function () {
|
|
4867
4954
|
return UniverDocsPlugin;
|