@univerjs/docs 1.1.0 → 1.3.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/index.js +748 -676
- package/lib/es/index.js +748 -677
- package/lib/index.js +748 -677
- 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/utils/section-columns.d.ts +2 -1
- package/lib/umd/index.js +2 -2
- package/package.json +7 -7
package/lib/es/index.js
CHANGED
|
@@ -645,9 +645,11 @@ let DocLayoutExecutorService = _DocLayoutExecutorService = class DocLayoutExecut
|
|
|
645
645
|
});
|
|
646
646
|
}
|
|
647
647
|
_enqueueCommittedMutation(params) {
|
|
648
|
+
var _params$actions;
|
|
648
649
|
const executor = this._executor;
|
|
649
650
|
const dataModel = this._getEligibleModel(params.unitId);
|
|
650
651
|
if (executor == null || dataModel == null) return;
|
|
652
|
+
if (JSONX.isNoop(params.actions) || ((_params$actions = params.actions) === null || _params$actions === void 0 ? void 0 : _params$actions.length) === 0) return;
|
|
651
653
|
const session = this._sessions.get(params.unitId);
|
|
652
654
|
if (session == null) {
|
|
653
655
|
this._replaceSession(dataModel).catch((error) => {
|
|
@@ -655,7 +657,6 @@ let DocLayoutExecutorService = _DocLayoutExecutorService = class DocLayoutExecut
|
|
|
655
657
|
});
|
|
656
658
|
return;
|
|
657
659
|
}
|
|
658
|
-
if (JSONX.isNoop(params.actions)) return;
|
|
659
660
|
const sourceMutationRevision = dataModel.getMutationRevision();
|
|
660
661
|
if (sourceMutationRevision !== session.sourceMutationRevision + 1) {
|
|
661
662
|
session.needsResnapshot = true;
|
|
@@ -2124,6 +2125,339 @@ function getTopLevelSectionBreaks(body) {
|
|
|
2124
2125
|
return result;
|
|
2125
2126
|
}
|
|
2126
2127
|
|
|
2128
|
+
//#endregion
|
|
2129
|
+
//#region src/services/permission/document-permission-resolver.ts
|
|
2130
|
+
const HEADER_FOOTER_REFERENCE_KEYS = [
|
|
2131
|
+
"defaultHeaderId",
|
|
2132
|
+
"defaultFooterId",
|
|
2133
|
+
"firstPageHeaderId",
|
|
2134
|
+
"firstPageFooterId",
|
|
2135
|
+
"evenPageHeaderId",
|
|
2136
|
+
"evenPageFooterId"
|
|
2137
|
+
];
|
|
2138
|
+
const documentPermissionResolverIndexCache = /* @__PURE__ */ new WeakMap();
|
|
2139
|
+
function getDocumentPermissionResolverIndex(documentDataModel) {
|
|
2140
|
+
var _getMutationRevision, _snapshot$body;
|
|
2141
|
+
const mutationRevision = ((_getMutationRevision = documentDataModel.getMutationRevision) === null || _getMutationRevision === void 0 ? void 0 : _getMutationRevision.call(documentDataModel)) ?? NaN;
|
|
2142
|
+
const cached = documentPermissionResolverIndexCache.get(documentDataModel);
|
|
2143
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.mutationRevision) === mutationRevision) return cached;
|
|
2144
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
2145
|
+
const topLevelSections = snapshot.body ? getTopLevelSectionBreaks(snapshot.body) : [];
|
|
2146
|
+
const drawingSegmentIds = /* @__PURE__ */ new Map();
|
|
2147
|
+
const addDrawingSegments = (body, segmentId) => {
|
|
2148
|
+
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) if (!drawingSegmentIds.has(block.blockId)) drawingSegmentIds.set(block.blockId, segmentId);
|
|
2149
|
+
};
|
|
2150
|
+
addDrawingSegments(snapshot.body, "");
|
|
2151
|
+
Object.entries(snapshot.headers ?? {}).forEach(([segmentId, header]) => addDrawingSegments(header.body, segmentId));
|
|
2152
|
+
Object.entries(snapshot.footers ?? {}).forEach(([segmentId, footer]) => addDrawingSegments(footer.body, segmentId));
|
|
2153
|
+
Object.entries(snapshot.notes ?? {}).forEach(([segmentId, footnote]) => addDrawingSegments(footnote.body, segmentId));
|
|
2154
|
+
const footnoteReferenceRanges = /* @__PURE__ */ new Map();
|
|
2155
|
+
for (const reference of ((_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.customRanges) ?? []) {
|
|
2156
|
+
var _reference$properties;
|
|
2157
|
+
if ((reference.rangeType === CustomRangeType.FOOTNOTE || reference.rangeType === CustomRangeType.ENDNOTE) && typeof ((_reference$properties = reference.properties) === null || _reference$properties === void 0 ? void 0 : _reference$properties.noteId) === "string") footnoteReferenceRanges.set(reference.properties.noteId, {
|
|
2158
|
+
startOffset: reference.startIndex,
|
|
2159
|
+
endOffset: reference.endIndex + 1
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
const index = {
|
|
2163
|
+
drawingSegmentIds,
|
|
2164
|
+
footnoteReferenceRanges,
|
|
2165
|
+
mutationRevision,
|
|
2166
|
+
segments: /* @__PURE__ */ new Map(),
|
|
2167
|
+
topLevelSections
|
|
2168
|
+
};
|
|
2169
|
+
documentPermissionResolverIndexCache.set(documentDataModel, index);
|
|
2170
|
+
return index;
|
|
2171
|
+
}
|
|
2172
|
+
function getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
|
|
2173
|
+
var _documentDataModel$ge, _snapshot$notes;
|
|
2174
|
+
const cached = resolverIndex.segments.get(segmentId);
|
|
2175
|
+
if (cached) return cached;
|
|
2176
|
+
const body = ((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody()) ?? null;
|
|
2177
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
2178
|
+
const note = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
|
|
2179
|
+
const drawings = (note ? note.drawings : snapshot.drawings) ?? {};
|
|
2180
|
+
const entities = body == null ? [] : [
|
|
2181
|
+
...(body.tables ?? []).map((item) => ({
|
|
2182
|
+
type: "table",
|
|
2183
|
+
id: item.tableId,
|
|
2184
|
+
startOffset: item.startIndex,
|
|
2185
|
+
endOffset: item.endIndex
|
|
2186
|
+
})),
|
|
2187
|
+
...(body.customBlocks ?? []).map((item) => ({
|
|
2188
|
+
type: drawings[item.blockId] ? "drawing" : "custom-block",
|
|
2189
|
+
id: item.blockId,
|
|
2190
|
+
startOffset: item.startIndex,
|
|
2191
|
+
endOffset: item.startIndex + 1
|
|
2192
|
+
})),
|
|
2193
|
+
...(body.blockRanges ?? []).map((item) => ({
|
|
2194
|
+
type: "block-range",
|
|
2195
|
+
id: item.blockId,
|
|
2196
|
+
startOffset: item.startIndex,
|
|
2197
|
+
endOffset: item.endIndex + 1
|
|
2198
|
+
})),
|
|
2199
|
+
...(body.customRanges ?? []).map((item) => ({
|
|
2200
|
+
type: "custom-range",
|
|
2201
|
+
id: item.rangeId,
|
|
2202
|
+
startOffset: item.startIndex,
|
|
2203
|
+
endOffset: item.endIndex + 1
|
|
2204
|
+
})),
|
|
2205
|
+
...(body.columnGroups ?? []).map((item) => ({
|
|
2206
|
+
type: "column-group",
|
|
2207
|
+
id: item.columnGroupId,
|
|
2208
|
+
startOffset: item.startIndex,
|
|
2209
|
+
endOffset: item.endIndex + 1
|
|
2210
|
+
}))
|
|
2211
|
+
];
|
|
2212
|
+
const entityRanges = new Map(entities.map((entity) => [`${entity.type}:${entity.id}`, {
|
|
2213
|
+
startOffset: entity.startOffset,
|
|
2214
|
+
endOffset: entity.endOffset
|
|
2215
|
+
}]));
|
|
2216
|
+
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) {
|
|
2217
|
+
const range = {
|
|
2218
|
+
startOffset: block.startIndex,
|
|
2219
|
+
endOffset: block.startIndex + 1
|
|
2220
|
+
};
|
|
2221
|
+
entityRanges.set(`custom-block:${block.blockId}`, range);
|
|
2222
|
+
entityRanges.set(`drawing:${block.blockId}`, range);
|
|
2223
|
+
}
|
|
2224
|
+
const segmentIndex = {
|
|
2225
|
+
body,
|
|
2226
|
+
entities,
|
|
2227
|
+
entityRanges,
|
|
2228
|
+
paragraphContentStartOffsets: body == null ? /* @__PURE__ */ new Map() : getParagraphContentStartOffsets(body),
|
|
2229
|
+
paragraphsById: new Map(((body === null || body === void 0 ? void 0 : body.paragraphs) ?? []).filter((paragraph) => paragraph.paragraphId != null).map((paragraph) => [paragraph.paragraphId, paragraph]))
|
|
2230
|
+
};
|
|
2231
|
+
resolverIndex.segments.set(segmentId, segmentIndex);
|
|
2232
|
+
return segmentIndex;
|
|
2233
|
+
}
|
|
2234
|
+
function getDocumentDrawingSegmentId(documentDataModel, drawingId) {
|
|
2235
|
+
return getDocumentPermissionResolverIndex(documentDataModel).drawingSegmentIds.get(drawingId) ?? "";
|
|
2236
|
+
}
|
|
2237
|
+
function getDocumentEditTargetObjectIds(documentDataModel, segmentId, range) {
|
|
2238
|
+
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
2239
|
+
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
2240
|
+
const { body } = segmentIndex;
|
|
2241
|
+
if (!body) return [];
|
|
2242
|
+
return [
|
|
2243
|
+
...getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex),
|
|
2244
|
+
...getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex),
|
|
2245
|
+
...getEntityPermissionObjectIds(segmentId, range, segmentIndex)
|
|
2246
|
+
];
|
|
2247
|
+
}
|
|
2248
|
+
function getDocumentEditTargetObjectIdsFromActions(documentDataModel, segmentId, actions) {
|
|
2249
|
+
const result = /* @__PURE__ */ new Set();
|
|
2250
|
+
if (actions == null) return [];
|
|
2251
|
+
const cursor = JSON1.type.readCursor(actions);
|
|
2252
|
+
cursor.traverse(null, () => {
|
|
2253
|
+
const path = cursor.getPath();
|
|
2254
|
+
const edit = cursor.getComponent();
|
|
2255
|
+
const scopedSegment = [
|
|
2256
|
+
"headers",
|
|
2257
|
+
"footers",
|
|
2258
|
+
"notes"
|
|
2259
|
+
].includes(String(path[0])) && typeof path[1] === "string" ? path[1] : segmentId;
|
|
2260
|
+
if (path[0] === "notes" && typeof path[1] === "string") getSectionPermissionObjectIds(documentDataModel, path[1], {
|
|
2261
|
+
startOffset: 0,
|
|
2262
|
+
endOffset: 0
|
|
2263
|
+
}).forEach((objectId) => result.add(objectId));
|
|
2264
|
+
if (path[0] === "noteSettings") getDocumentPermissionResolverIndex(documentDataModel).topLevelSections.forEach((section) => {
|
|
2265
|
+
result.add(getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
2266
|
+
});
|
|
2267
|
+
if (path[0] === "body" && path[1] === "sectionBreaks" && typeof path[2] === "number" && (path[3] === "noteProperties" || path[3] === "suppressEndnotes")) {
|
|
2268
|
+
var _documentDataModel$ge2;
|
|
2269
|
+
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;
|
|
2270
|
+
if (sectionId) result.add(getDocumentSectionPermissionObjectId("", sectionId));
|
|
2271
|
+
}
|
|
2272
|
+
if (path[path.length - 1] !== "body" || (edit === null || edit === void 0 ? void 0 : edit.et) !== TextX.id || !Array.isArray(edit.e) || !edit.e.every(isTextXAction)) return;
|
|
2273
|
+
const textActions = edit.e;
|
|
2274
|
+
let offset = 0;
|
|
2275
|
+
const addRange = (startOffset, endOffset) => {
|
|
2276
|
+
getDocumentEditTargetObjectIds(documentDataModel, scopedSegment, {
|
|
2277
|
+
startOffset,
|
|
2278
|
+
endOffset
|
|
2279
|
+
}).forEach((objectId) => result.add(objectId));
|
|
2280
|
+
};
|
|
2281
|
+
textActions.forEach((action) => {
|
|
2282
|
+
if (action.t === TextXActionType.INSERT) {
|
|
2283
|
+
addRange(offset, offset);
|
|
2284
|
+
return;
|
|
2285
|
+
}
|
|
2286
|
+
if (action.t === TextXActionType.DELETE) {
|
|
2287
|
+
addRange(offset, offset + action.len);
|
|
2288
|
+
offset += action.len;
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2291
|
+
if (action.body !== void 0 || action.oldBody !== void 0 || action.coverType !== void 0) addRange(offset, offset + action.len);
|
|
2292
|
+
offset += action.len;
|
|
2293
|
+
});
|
|
2294
|
+
});
|
|
2295
|
+
getDrawingIdsFromActions(actions).forEach((drawingId) => {
|
|
2296
|
+
var _documentDataModel$ge3, _body$customBlocks;
|
|
2297
|
+
result.add(getDocumentEntityPermissionObjectId(segmentId, "drawing", drawingId));
|
|
2298
|
+
const body = (_documentDataModel$ge3 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.getBody();
|
|
2299
|
+
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);
|
|
2300
|
+
if (block) getSectionPermissionObjectIds(documentDataModel, segmentId, {
|
|
2301
|
+
startOffset: block.startIndex,
|
|
2302
|
+
endOffset: block.startIndex + 1
|
|
2303
|
+
}).forEach((objectId) => result.add(objectId));
|
|
2304
|
+
});
|
|
2305
|
+
return [...result];
|
|
2306
|
+
}
|
|
2307
|
+
function getDrawingIdsFromActions(actions) {
|
|
2308
|
+
const result = /* @__PURE__ */ new Set();
|
|
2309
|
+
const visit = (value) => {
|
|
2310
|
+
if (Array.isArray(value)) {
|
|
2311
|
+
value.forEach((item, index) => {
|
|
2312
|
+
if (item === "drawings" && typeof value[index + 1] === "string") result.add(value[index + 1]);
|
|
2313
|
+
visit(item);
|
|
2314
|
+
});
|
|
2315
|
+
return;
|
|
2316
|
+
}
|
|
2317
|
+
if (!isRecord$2(value)) return;
|
|
2318
|
+
Object.values(value).forEach(visit);
|
|
2319
|
+
};
|
|
2320
|
+
visit(actions);
|
|
2321
|
+
return [...result];
|
|
2322
|
+
}
|
|
2323
|
+
function isTextXAction(value) {
|
|
2324
|
+
if (!isRecord$2(value) || typeof value.len !== "number") return false;
|
|
2325
|
+
if (value.t === TextXActionType.INSERT) return isRecord$2(value.body);
|
|
2326
|
+
return value.t === TextXActionType.RETAIN || value.t === TextXActionType.DELETE;
|
|
2327
|
+
}
|
|
2328
|
+
function isRecord$2(value) {
|
|
2329
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2330
|
+
}
|
|
2331
|
+
function getDocumentEntityParentPermissionObjectIds(documentDataModel, segmentId, entityType, entityId) {
|
|
2332
|
+
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
2333
|
+
const range = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex).entityRanges.get(`${entityType}:${entityId}`) ?? null;
|
|
2334
|
+
return range ? getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex) : [];
|
|
2335
|
+
}
|
|
2336
|
+
function getDocumentParagraphParentPermissionObjectIds(documentDataModel, segmentId, paragraphId) {
|
|
2337
|
+
const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
|
|
2338
|
+
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
2339
|
+
const { body } = segmentIndex;
|
|
2340
|
+
const paragraph = segmentIndex.paragraphsById.get(paragraphId);
|
|
2341
|
+
if (!body || !paragraph) return [];
|
|
2342
|
+
return getSectionPermissionObjectIds(documentDataModel, segmentId, {
|
|
2343
|
+
startOffset: segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? getParagraphContentStartOffset(body, paragraph),
|
|
2344
|
+
endOffset: paragraph.startIndex + 1
|
|
2345
|
+
}, resolverIndex);
|
|
2346
|
+
}
|
|
2347
|
+
function getDocumentSectionPermissionObjectIdsByIds(sectionIds) {
|
|
2348
|
+
return Array.from(sectionIds, (sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
|
|
2349
|
+
}
|
|
2350
|
+
function getDocumentSectionIdsAtOffset(body, offset) {
|
|
2351
|
+
return getSectionsIntersectingRange(getTopLevelSectionBreaks(body), {
|
|
2352
|
+
startOffset: offset,
|
|
2353
|
+
endOffset: offset
|
|
2354
|
+
}).map((section) => section.sectionId);
|
|
2355
|
+
}
|
|
2356
|
+
function getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
|
|
2357
|
+
if (segmentId) {
|
|
2358
|
+
const referenceRange = resolverIndex.footnoteReferenceRanges.get(segmentId);
|
|
2359
|
+
if (referenceRange) return getDocumentEditTargetObjectIds(documentDataModel, "", referenceRange);
|
|
2360
|
+
return getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, resolverIndex.topLevelSections).map((sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
|
|
2361
|
+
}
|
|
2362
|
+
return getSectionsIntersectingRange(resolverIndex.topLevelSections, range).map((section) => getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
2363
|
+
}
|
|
2364
|
+
function getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex) {
|
|
2365
|
+
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
2366
|
+
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
2367
|
+
return (body.paragraphs ?? []).filter((paragraph) => intersectsRange(segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? getParagraphContentStartOffset(body, paragraph), paragraph.startIndex + 1, startOffset, endOffset)).flatMap((paragraph) => paragraph.paragraphId ? [getDocumentParagraphPermissionObjectId(segmentId, paragraph.paragraphId)] : []);
|
|
2368
|
+
}
|
|
2369
|
+
function getEntityPermissionObjectIds(segmentId, range, segmentIndex) {
|
|
2370
|
+
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
2371
|
+
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
2372
|
+
return segmentIndex.entities.filter((item) => intersectsRange(item.startOffset, item.endOffset, startOffset, endOffset)).map((item) => getDocumentEntityPermissionObjectId(segmentId, item.type, item.id));
|
|
2373
|
+
}
|
|
2374
|
+
function getSectionsIntersectingRange(sections, range) {
|
|
2375
|
+
const startOffset = Math.min(range.startOffset, range.endOffset);
|
|
2376
|
+
const endOffset = Math.max(range.startOffset, range.endOffset);
|
|
2377
|
+
return sections.filter((section, index) => intersectsRange(index === 0 ? 0 : sections[index - 1].startIndex + 1, section.startIndex + 1, startOffset, endOffset));
|
|
2378
|
+
}
|
|
2379
|
+
function intersectsRange(targetStart, targetEnd, rangeStart, rangeEnd) {
|
|
2380
|
+
if (rangeStart === rangeEnd) return rangeStart >= targetStart && rangeStart < targetEnd;
|
|
2381
|
+
return rangeStart < targetEnd && rangeEnd > targetStart;
|
|
2382
|
+
}
|
|
2383
|
+
function getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, sections = getDocumentPermissionResolverIndex(documentDataModel).topLevelSections) {
|
|
2384
|
+
const snapshot = documentDataModel.getSnapshot();
|
|
2385
|
+
const result = /* @__PURE__ */ new Set();
|
|
2386
|
+
sections.forEach((section, sectionIndex) => {
|
|
2387
|
+
if (HEADER_FOOTER_REFERENCE_KEYS.some((key) => resolveSectionHeaderFooterReference(snapshot.documentStyle, sections, sectionIndex, key).segmentId === segmentId)) result.add(section.sectionId);
|
|
2388
|
+
});
|
|
2389
|
+
return [...result];
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
//#endregion
|
|
2393
|
+
//#region src/commands/commands/set-heading-collapsed.command.ts
|
|
2394
|
+
const SetHeadingCollapsedCommand = {
|
|
2395
|
+
id: "doc.command.set-heading-collapsed",
|
|
2396
|
+
type: CommandType.COMMAND,
|
|
2397
|
+
handler: (accessor, params) => {
|
|
2398
|
+
var _body$paragraphs;
|
|
2399
|
+
if (!params || typeof params.collapsed !== "boolean") return false;
|
|
2400
|
+
const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
2401
|
+
if (!doc || doc.getDisabled() || doc.getSnapshot().documentStyle.documentFlavor !== DocumentFlavor.MODERN) return false;
|
|
2402
|
+
const body = doc.getBody();
|
|
2403
|
+
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)) ?? [];
|
|
2404
|
+
const paragraph = matches[0];
|
|
2405
|
+
if (!body || matches.length !== 1 || paragraph.headingCollapsed === true === params.collapsed) return false;
|
|
2406
|
+
const viewModel = new DocumentViewModel(doc);
|
|
2407
|
+
try {
|
|
2408
|
+
var _selectionService$get;
|
|
2409
|
+
const section = viewModel.getHeadingSections().find((section) => section.paragraphId === params.paragraphId);
|
|
2410
|
+
if (!section || params.collapsed && section.startOffset >= section.endOffset || viewModel.getCollapsedHeadingAtOffset(paragraph.startIndex)) return false;
|
|
2411
|
+
const targets = getDocumentEditTargetObjectIds(doc, "", {
|
|
2412
|
+
startOffset: getParagraphContentStartOffset(body, paragraph),
|
|
2413
|
+
endOffset: paragraph.startIndex + 1
|
|
2414
|
+
});
|
|
2415
|
+
if (!canEditDocumentTargets(accessor.get(IPermissionService), params.unitId, targets)) return false;
|
|
2416
|
+
const textX = new TextX();
|
|
2417
|
+
if (paragraph.startIndex > 0) textX.push({
|
|
2418
|
+
t: TextXActionType.RETAIN,
|
|
2419
|
+
len: paragraph.startIndex
|
|
2420
|
+
});
|
|
2421
|
+
textX.push({
|
|
2422
|
+
t: TextXActionType.RETAIN,
|
|
2423
|
+
len: 1,
|
|
2424
|
+
coverType: UpdateDocsAttributeType.COVER,
|
|
2425
|
+
body: {
|
|
2426
|
+
dataStream: "",
|
|
2427
|
+
paragraphs: [{
|
|
2428
|
+
paragraphId: paragraph.paragraphId,
|
|
2429
|
+
startIndex: 0,
|
|
2430
|
+
headingCollapsed: params.collapsed
|
|
2431
|
+
}]
|
|
2432
|
+
}
|
|
2433
|
+
});
|
|
2434
|
+
const actions = JSONX.getInstance().editOp(textX.serialize(), getRichTextEditPath(doc));
|
|
2435
|
+
const selectionService = accessor.get(DocSelectionManagerService);
|
|
2436
|
+
const selectionTarget = {
|
|
2437
|
+
unitId: params.unitId,
|
|
2438
|
+
subUnitId: params.unitId
|
|
2439
|
+
};
|
|
2440
|
+
const ranges = selectionService.getDocRanges(selectionTarget) ?? [];
|
|
2441
|
+
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);
|
|
2442
|
+
return Boolean(accessor.get(ICommandService).syncExecuteCommand(RichTextEditingMutation.id, {
|
|
2443
|
+
unitId: params.unitId,
|
|
2444
|
+
actions,
|
|
2445
|
+
textRanges: hidesSelection ? [{
|
|
2446
|
+
startOffset: paragraph.startIndex,
|
|
2447
|
+
endOffset: paragraph.startIndex,
|
|
2448
|
+
collapsed: true
|
|
2449
|
+
}] : null,
|
|
2450
|
+
prevTextRanges: ranges,
|
|
2451
|
+
noNeedSetTextRange: !hidesSelection,
|
|
2452
|
+
isEditing: false,
|
|
2453
|
+
trigger: SetHeadingCollapsedCommand.id
|
|
2454
|
+
}));
|
|
2455
|
+
} finally {
|
|
2456
|
+
viewModel.dispose();
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
};
|
|
2460
|
+
|
|
2127
2461
|
//#endregion
|
|
2128
2462
|
//#region src/commands/commands/set-section-header-footer-link.command.ts
|
|
2129
2463
|
const SetSectionHeaderFooterLinkCommand = {
|
|
@@ -2424,725 +2758,461 @@ const UpdateDocumentSectionCommand = {
|
|
|
2424
2758
|
body: {
|
|
2425
2759
|
dataStream: "",
|
|
2426
2760
|
sectionBreaks: [{
|
|
2427
|
-
...Tools.deepClone(section),
|
|
2428
|
-
...Tools.deepClone(updates.get(section.sectionId)),
|
|
2429
|
-
sectionId: section.sectionId,
|
|
2430
|
-
startIndex: 0
|
|
2431
|
-
}]
|
|
2432
|
-
}
|
|
2433
|
-
});
|
|
2434
|
-
cursor.moveCursorTo(section.startIndex + 1);
|
|
2435
|
-
}
|
|
2436
|
-
const jsonX = JSONX.getInstance();
|
|
2437
|
-
const mutation = {
|
|
2438
|
-
id: RichTextEditingMutation.id,
|
|
2439
|
-
params: {
|
|
2440
|
-
unitId: params.unitId,
|
|
2441
|
-
actions: jsonX.editOp(textX.serialize(), getRichTextEditPath(documentDataModel)),
|
|
2442
|
-
textRanges: null,
|
|
2443
|
-
noNeedSetTextRange: true,
|
|
2444
|
-
debounce: true,
|
|
2445
|
-
isEditing: false,
|
|
2446
|
-
trigger: UpdateDocumentSectionCommand.id
|
|
2447
|
-
}
|
|
2448
|
-
};
|
|
2449
|
-
return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
|
|
2450
|
-
}
|
|
2451
|
-
};
|
|
2452
|
-
const InsertDocumentSectionBreakCommand = {
|
|
2453
|
-
id: "doc.command.insert-section-break",
|
|
2454
|
-
type: CommandType.COMMAND,
|
|
2455
|
-
handler: (accessor, params) => {
|
|
2456
|
-
var _body$sectionBreaks;
|
|
2457
|
-
if (!params) return false;
|
|
2458
|
-
const context = getTraditionalDocumentContext(accessor, params.unitId);
|
|
2459
|
-
if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(SectionType, params.nextSectionType)) return false;
|
|
2460
|
-
const { body, documentDataModel, commandService } = context;
|
|
2461
|
-
const insertedSection = {
|
|
2462
|
-
...Tools.deepClone(params.config ?? {}),
|
|
2463
|
-
sectionId: params.sectionId,
|
|
2464
|
-
startIndex: params.offset
|
|
2465
|
-
};
|
|
2466
|
-
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;
|
|
2467
|
-
const nextSection = params.nextSectionType == null ? void 0 : getTopLevelSectionBreaks(body).find((section) => section.startIndex >= params.offset);
|
|
2468
|
-
if (params.nextSectionType != null && !nextSection) return false;
|
|
2469
|
-
const textX = new TextX();
|
|
2470
|
-
textX.retain(params.offset);
|
|
2471
|
-
textX.insert(1, {
|
|
2472
|
-
dataStream: DataStreamTreeTokenType.SECTION_BREAK,
|
|
2473
|
-
sectionBreaks: [{
|
|
2474
|
-
...insertedSection,
|
|
2475
|
-
startIndex: 0
|
|
2476
|
-
}]
|
|
2477
|
-
});
|
|
2478
|
-
if (nextSection && params.nextSectionType != null) {
|
|
2479
|
-
textX.retain(nextSection.startIndex - params.offset);
|
|
2480
|
-
textX.push({
|
|
2481
|
-
t: TextXActionType.RETAIN,
|
|
2482
|
-
len: 1,
|
|
2483
|
-
coverType: UpdateDocsAttributeType.REPLACE,
|
|
2484
|
-
body: {
|
|
2485
|
-
dataStream: "",
|
|
2486
|
-
sectionBreaks: [{
|
|
2487
|
-
...Tools.deepClone(nextSection),
|
|
2488
|
-
sectionType: params.nextSectionType,
|
|
2761
|
+
...Tools.deepClone(section),
|
|
2762
|
+
...Tools.deepClone(updates.get(section.sectionId)),
|
|
2763
|
+
sectionId: section.sectionId,
|
|
2489
2764
|
startIndex: 0
|
|
2490
2765
|
}]
|
|
2491
2766
|
}
|
|
2492
2767
|
});
|
|
2768
|
+
cursor.moveCursorTo(section.startIndex + 1);
|
|
2493
2769
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
customRanges: [{
|
|
2509
|
-
startIndex: 0,
|
|
2510
|
-
endIndex: 0,
|
|
2511
|
-
rangeId: `docx-break-${generateRandomId()}`,
|
|
2512
|
-
rangeType: CustomRangeType.CUSTOM,
|
|
2513
|
-
wholeEntity: true,
|
|
2514
|
-
properties: { breakType: DocxBreakType.COLUMN }
|
|
2515
|
-
}]
|
|
2516
|
-
});
|
|
2517
|
-
return executeSectionTextX(context.commandService, context.documentDataModel, textX, InsertDocumentColumnBreakCommand.id);
|
|
2770
|
+
const jsonX = JSONX.getInstance();
|
|
2771
|
+
const mutation = {
|
|
2772
|
+
id: RichTextEditingMutation.id,
|
|
2773
|
+
params: {
|
|
2774
|
+
unitId: params.unitId,
|
|
2775
|
+
actions: jsonX.editOp(textX.serialize(), getRichTextEditPath(documentDataModel)),
|
|
2776
|
+
textRanges: null,
|
|
2777
|
+
noNeedSetTextRange: true,
|
|
2778
|
+
debounce: true,
|
|
2779
|
+
isEditing: false,
|
|
2780
|
+
trigger: UpdateDocumentSectionCommand.id
|
|
2781
|
+
}
|
|
2782
|
+
};
|
|
2783
|
+
return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
|
|
2518
2784
|
}
|
|
2519
2785
|
};
|
|
2520
|
-
const
|
|
2521
|
-
id: "doc.command.
|
|
2786
|
+
const InsertDocumentSectionBreakCommand = {
|
|
2787
|
+
id: "doc.command.insert-section-break",
|
|
2522
2788
|
type: CommandType.COMMAND,
|
|
2523
2789
|
handler: (accessor, params) => {
|
|
2790
|
+
var _body$sectionBreaks;
|
|
2524
2791
|
if (!params) return false;
|
|
2525
2792
|
const context = getTraditionalDocumentContext(accessor, params.unitId);
|
|
2526
|
-
if (!context || !params.sectionId) return false;
|
|
2527
|
-
const
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
section.marginBottom,
|
|
2561
|
-
section.marginLeft,
|
|
2562
|
-
section.marginRight
|
|
2563
|
-
].some((margin) => margin != null && (!Number.isFinite(margin) || margin < 0))) return false;
|
|
2564
|
-
const pageSize = section.pageSize ?? documentStyle.pageSize;
|
|
2565
|
-
const marginTop = section.marginTop ?? documentStyle.marginTop ?? 0;
|
|
2566
|
-
const marginBottom = section.marginBottom ?? documentStyle.marginBottom ?? 0;
|
|
2567
|
-
const marginLeft = section.marginLeft ?? documentStyle.marginLeft ?? 0;
|
|
2568
|
-
const marginRight = section.marginRight ?? documentStyle.marginRight ?? 0;
|
|
2569
|
-
if ((pageSize === null || pageSize === void 0 ? void 0 : pageSize.width) != null && marginLeft + marginRight >= pageSize.width || (pageSize === null || pageSize === void 0 ? void 0 : pageSize.height) != null && marginTop + marginBottom >= pageSize.height) return false;
|
|
2570
|
-
const columns = section.columnProperties ?? [];
|
|
2571
|
-
if (columns.some(({ width, paddingEnd }) => !Number.isFinite(width) || !Number.isFinite(paddingEnd) || width < 0 || paddingEnd < 0)) return false;
|
|
2572
|
-
return columns.reduce((sum, { width, paddingEnd }) => sum + width + paddingEnd, 0) <= getSectionContentWidth(documentStyle, section);
|
|
2573
|
-
}
|
|
2574
|
-
function isPositiveFinite(value) {
|
|
2575
|
-
return value != null && Number.isFinite(value) && value > 0;
|
|
2576
|
-
}
|
|
2577
|
-
function isValidEnumValue(enumObject, value) {
|
|
2578
|
-
return Object.values(enumObject).includes(value);
|
|
2579
|
-
}
|
|
2580
|
-
function executeSectionTextX(commandService, documentDataModel, textX, trigger) {
|
|
2581
|
-
const actions = JSONX.getInstance().editOp(textX.serialize(), getRichTextEditPath(documentDataModel));
|
|
2582
|
-
return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
|
|
2583
|
-
unitId: documentDataModel.getUnitId(),
|
|
2584
|
-
actions,
|
|
2585
|
-
textRanges: null,
|
|
2586
|
-
noNeedSetTextRange: true,
|
|
2587
|
-
debounce: true,
|
|
2588
|
-
isEditing: false,
|
|
2589
|
-
trigger
|
|
2590
|
-
}));
|
|
2591
|
-
}
|
|
2592
|
-
|
|
2593
|
-
//#endregion
|
|
2594
|
-
//#region src/services/permission/document-permission-rule.model.ts
|
|
2595
|
-
/**
|
|
2596
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2597
|
-
*
|
|
2598
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2599
|
-
* you may not use this file except in compliance with the License.
|
|
2600
|
-
* You may obtain a copy of the License at
|
|
2601
|
-
*
|
|
2602
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2603
|
-
*
|
|
2604
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
2605
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2606
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2607
|
-
* See the License for the specific language governing permissions and
|
|
2608
|
-
* limitations under the License.
|
|
2609
|
-
*/
|
|
2610
|
-
let DocumentPermissionRuleModel = class DocumentPermissionRuleModel extends ObjectPermissionRuleModel {
|
|
2611
|
-
constructor(resources) {
|
|
2612
|
-
super(resources, "DOC_OBJECT_PERMISSION_PLUGIN", UniverInstanceType.UNIVER_DOC, [
|
|
2613
|
-
UnitObject.DocumentSection,
|
|
2614
|
-
UnitObject.DocumentParagraph,
|
|
2615
|
-
UnitObject.DocumentEntity
|
|
2616
|
-
]);
|
|
2617
|
-
}
|
|
2618
|
-
};
|
|
2619
|
-
DocumentPermissionRuleModel = __decorate([__decorateParam(0, IResourceManagerService)], DocumentPermissionRuleModel);
|
|
2620
|
-
|
|
2621
|
-
//#endregion
|
|
2622
|
-
//#region src/commands/mutations/set-document-permission-rule.mutation.ts
|
|
2623
|
-
const SetDocumentPermissionRuleMutation = {
|
|
2624
|
-
id: "doc.mutation.set-permission-rule",
|
|
2625
|
-
type: CommandType.MUTATION,
|
|
2626
|
-
handler: (accessor, params) => {
|
|
2627
|
-
if (!params || !accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC)) return false;
|
|
2628
|
-
return accessor.get(DocumentPermissionRuleModel).setRule(params.unitId, params.objectType, params.objectId, params.rule);
|
|
2629
|
-
}
|
|
2630
|
-
};
|
|
2631
|
-
|
|
2632
|
-
//#endregion
|
|
2633
|
-
//#region src/commands/mutations/set-document-permission-rules.mutation.ts
|
|
2634
|
-
const SetDocumentPermissionRulesMutation = {
|
|
2635
|
-
id: "doc.mutation.set-permission-rules",
|
|
2636
|
-
type: CommandType.MUTATION,
|
|
2637
|
-
handler: (accessor, params) => {
|
|
2638
|
-
if (!params || !accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC)) return false;
|
|
2639
|
-
return accessor.get(DocumentPermissionRuleModel).setRules(params.unitId, params.rules);
|
|
2640
|
-
}
|
|
2641
|
-
};
|
|
2642
|
-
|
|
2643
|
-
//#endregion
|
|
2644
|
-
//#region src/embed-host-anchor.ts
|
|
2645
|
-
const EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY = "UniverEmbedDocsCustomBlock";
|
|
2646
|
-
const DEFAULT_CUSTOM_BLOCK_SIZE = {
|
|
2647
|
-
width: 720,
|
|
2648
|
-
height: 360
|
|
2649
|
-
};
|
|
2650
|
-
const SHEET_LIKE_CUSTOM_BLOCK_SIZE = {
|
|
2651
|
-
width: 960,
|
|
2652
|
-
height: 480
|
|
2653
|
-
};
|
|
2654
|
-
const SLIDE_CUSTOM_BLOCK_SIZE = {
|
|
2655
|
-
width: 720,
|
|
2656
|
-
height: 405
|
|
2657
|
-
};
|
|
2658
|
-
function createDocsCustomBlockInsertMutation(params) {
|
|
2659
|
-
return createRichTextMutation(params.unitId, params.segmentId, createInsertCustomBlockActions(params));
|
|
2660
|
-
}
|
|
2661
|
-
function createDocsCustomBlockRemoveMutation(params) {
|
|
2662
|
-
return createRichTextMutation(params.unitId, params.segmentId, createRemoveCustomBlockActions(params));
|
|
2663
|
-
}
|
|
2664
|
-
function createInsertCustomBlockActions(params) {
|
|
2665
|
-
const textX = new TextX();
|
|
2666
|
-
if (params.startIndex > 0) textX.push({
|
|
2667
|
-
t: TextXActionType.RETAIN,
|
|
2668
|
-
len: params.startIndex
|
|
2669
|
-
});
|
|
2670
|
-
textX.push({
|
|
2671
|
-
t: TextXActionType.INSERT,
|
|
2672
|
-
body: {
|
|
2673
|
-
dataStream: "\b",
|
|
2674
|
-
customBlocks: [{
|
|
2675
|
-
startIndex: 0,
|
|
2676
|
-
blockId: params.blockId
|
|
2677
|
-
}]
|
|
2678
|
-
},
|
|
2679
|
-
len: 1
|
|
2680
|
-
});
|
|
2681
|
-
return composeActions([toBodyEditActions(textX, params.segmentId), createDrawingInsertActions(params)]);
|
|
2682
|
-
}
|
|
2683
|
-
function createRemoveCustomBlockActions(params) {
|
|
2684
|
-
const textX = new TextX();
|
|
2685
|
-
if (params.startIndex > 0) textX.push({
|
|
2686
|
-
t: TextXActionType.RETAIN,
|
|
2687
|
-
len: params.startIndex
|
|
2688
|
-
});
|
|
2689
|
-
textX.push({
|
|
2690
|
-
t: TextXActionType.DELETE,
|
|
2691
|
-
len: 1
|
|
2692
|
-
});
|
|
2693
|
-
return composeActions([toBodyEditActions(textX, params.segmentId), createDrawingRemoveActions(params)]);
|
|
2694
|
-
}
|
|
2695
|
-
function createDocsCustomBlockDrawing(params) {
|
|
2696
|
-
const size = resolveDocsCustomBlockSize(params.childType);
|
|
2697
|
-
const isInline = params.interactionMode === "inline";
|
|
2698
|
-
return {
|
|
2699
|
-
unitId: params.unitId,
|
|
2700
|
-
subUnitId: params.unitId,
|
|
2701
|
-
drawingId: params.blockId,
|
|
2702
|
-
drawingType: DrawingTypeEnum.DRAWING_DOM,
|
|
2703
|
-
componentKey: params.componentKey ?? "UniverEmbedDocsCustomBlock",
|
|
2704
|
-
data: createEmbedDocsCustomBlockData(params),
|
|
2705
|
-
title: params.blockId,
|
|
2706
|
-
description: "Univer embedded unit custom block",
|
|
2707
|
-
layoutType: isInline ? PositionedObjectLayoutType.INLINE : PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM,
|
|
2708
|
-
allowTransform: false,
|
|
2709
|
-
docTransform: {
|
|
2710
|
-
size: {
|
|
2711
|
-
width: size.width,
|
|
2712
|
-
height: size.height
|
|
2713
|
-
},
|
|
2714
|
-
positionH: {
|
|
2715
|
-
relativeFrom: isInline ? ObjectRelativeFromH.PAGE : ObjectRelativeFromH.COLUMN,
|
|
2716
|
-
...isInline ? { posOffset: 0 } : { align: AlignTypeH.LEFT }
|
|
2717
|
-
},
|
|
2718
|
-
positionV: {
|
|
2719
|
-
relativeFrom: isInline ? ObjectRelativeFromV.PAGE : ObjectRelativeFromV.PARAGRAPH,
|
|
2720
|
-
posOffset: 0
|
|
2721
|
-
},
|
|
2722
|
-
angle: 0
|
|
2723
|
-
},
|
|
2724
|
-
transform: {
|
|
2725
|
-
left: 0,
|
|
2726
|
-
top: 0,
|
|
2727
|
-
width: size.width,
|
|
2728
|
-
height: size.height
|
|
2793
|
+
if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(SectionType, params.nextSectionType)) return false;
|
|
2794
|
+
const { body, documentDataModel, commandService } = context;
|
|
2795
|
+
const insertedSection = {
|
|
2796
|
+
...Tools.deepClone(params.config ?? {}),
|
|
2797
|
+
sectionId: params.sectionId,
|
|
2798
|
+
startIndex: params.offset
|
|
2799
|
+
};
|
|
2800
|
+
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;
|
|
2801
|
+
const nextSection = params.nextSectionType == null ? void 0 : getTopLevelSectionBreaks(body).find((section) => section.startIndex >= params.offset);
|
|
2802
|
+
if (params.nextSectionType != null && !nextSection) return false;
|
|
2803
|
+
const textX = new TextX();
|
|
2804
|
+
textX.retain(params.offset);
|
|
2805
|
+
textX.insert(1, {
|
|
2806
|
+
dataStream: DataStreamTreeTokenType.SECTION_BREAK,
|
|
2807
|
+
sectionBreaks: [{
|
|
2808
|
+
...insertedSection,
|
|
2809
|
+
startIndex: 0
|
|
2810
|
+
}]
|
|
2811
|
+
});
|
|
2812
|
+
if (nextSection && params.nextSectionType != null) {
|
|
2813
|
+
textX.retain(nextSection.startIndex - params.offset);
|
|
2814
|
+
textX.push({
|
|
2815
|
+
t: TextXActionType.RETAIN,
|
|
2816
|
+
len: 1,
|
|
2817
|
+
coverType: UpdateDocsAttributeType.REPLACE,
|
|
2818
|
+
body: {
|
|
2819
|
+
dataStream: "",
|
|
2820
|
+
sectionBreaks: [{
|
|
2821
|
+
...Tools.deepClone(nextSection),
|
|
2822
|
+
sectionType: params.nextSectionType,
|
|
2823
|
+
startIndex: 0
|
|
2824
|
+
}]
|
|
2825
|
+
}
|
|
2826
|
+
});
|
|
2729
2827
|
}
|
|
2730
|
-
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
}
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
}
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2828
|
+
return executeSectionTextX(commandService, documentDataModel, textX, InsertDocumentSectionBreakCommand.id);
|
|
2829
|
+
}
|
|
2830
|
+
};
|
|
2831
|
+
const InsertDocumentColumnBreakCommand = {
|
|
2832
|
+
id: "doc.command.insert-column-break",
|
|
2833
|
+
type: CommandType.COMMAND,
|
|
2834
|
+
handler: (accessor, params) => {
|
|
2835
|
+
if (!params) return false;
|
|
2836
|
+
const context = getTraditionalDocumentContext(accessor, params.unitId);
|
|
2837
|
+
if (!context || !isValidTopLevelInsertionOffset(context.body, params.offset)) return false;
|
|
2838
|
+
const textX = new TextX();
|
|
2839
|
+
textX.retain(params.offset);
|
|
2840
|
+
textX.insert(1, {
|
|
2841
|
+
dataStream: DataStreamTreeTokenType.COLUMN_BREAK,
|
|
2842
|
+
customRanges: [{
|
|
2843
|
+
startIndex: 0,
|
|
2844
|
+
endIndex: 0,
|
|
2845
|
+
rangeId: `docx-break-${generateRandomId()}`,
|
|
2846
|
+
rangeType: CustomRangeType.CUSTOM,
|
|
2847
|
+
wholeEntity: true,
|
|
2848
|
+
properties: { breakType: DocxBreakType.COLUMN }
|
|
2849
|
+
}]
|
|
2850
|
+
});
|
|
2851
|
+
return executeSectionTextX(context.commandService, context.documentDataModel, textX, InsertDocumentColumnBreakCommand.id);
|
|
2852
|
+
}
|
|
2853
|
+
};
|
|
2854
|
+
const DeleteDocumentSectionBreakCommand = {
|
|
2855
|
+
id: "doc.command.delete-section-break",
|
|
2856
|
+
type: CommandType.COMMAND,
|
|
2857
|
+
handler: (accessor, params) => {
|
|
2858
|
+
if (!params) return false;
|
|
2859
|
+
const context = getTraditionalDocumentContext(accessor, params.unitId);
|
|
2860
|
+
if (!context || !params.sectionId) return false;
|
|
2861
|
+
const sections = getTopLevelSectionBreaks(context.body);
|
|
2862
|
+
if (sections.length <= 1) return false;
|
|
2863
|
+
const section = sections.find((item) => item.sectionId === params.sectionId);
|
|
2864
|
+
if (!section || section === sections[sections.length - 1]) return false;
|
|
2865
|
+
const textX = new TextX();
|
|
2866
|
+
textX.retain(section.startIndex);
|
|
2867
|
+
textX.delete(1);
|
|
2868
|
+
return executeSectionTextX(context.commandService, context.documentDataModel, textX, DeleteDocumentSectionBreakCommand.id);
|
|
2869
|
+
}
|
|
2870
|
+
};
|
|
2871
|
+
function getTraditionalDocumentContext(accessor, unitId) {
|
|
2872
|
+
if (!unitId) return null;
|
|
2873
|
+
const documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
2874
|
+
const body = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getBody();
|
|
2875
|
+
if (!documentDataModel || !body || documentDataModel.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return null;
|
|
2762
2876
|
return {
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
segmentId,
|
|
2767
|
-
actions,
|
|
2768
|
-
textRanges: [],
|
|
2769
|
-
isEditing: false,
|
|
2770
|
-
noNeedSetTextRange: true
|
|
2771
|
-
}
|
|
2877
|
+
body,
|
|
2878
|
+
documentDataModel,
|
|
2879
|
+
commandService: accessor.get(ICommandService)
|
|
2772
2880
|
};
|
|
2773
2881
|
}
|
|
2774
|
-
function
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
segmentId,
|
|
2778
|
-
"body"
|
|
2779
|
-
] : ["body"]) ?? [];
|
|
2882
|
+
function isValidTopLevelInsertionOffset(body, offset) {
|
|
2883
|
+
var _body$tables, _body$columnGroups, _body$blockRanges;
|
|
2884
|
+
return Number.isInteger(offset) && offset >= 0 && offset <= body.dataStream.length && !((_body$tables = body.tables) === null || _body$tables === void 0 ? void 0 : _body$tables.some((range) => containsInteriorInsertionOffset(getTableRangeInterval(range), offset))) && !((_body$columnGroups = body.columnGroups) === null || _body$columnGroups === void 0 ? void 0 : _body$columnGroups.some((range) => containsInteriorInsertionOffset(getColumnGroupRangeInterval(range), offset))) && !((_body$blockRanges = body.blockRanges) === null || _body$blockRanges === void 0 ? void 0 : _body$blockRanges.some((range) => containsInteriorInsertionOffset(getBlockRangeInterval(range), offset)));
|
|
2780
2885
|
}
|
|
2781
|
-
function
|
|
2782
|
-
if (
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2886
|
+
function isValidSectionConfig(section, documentStyle) {
|
|
2887
|
+
if (section.sectionType != null && !isValidEnumValue(SectionType, section.sectionType)) return false;
|
|
2888
|
+
if (section.pageOrient != null && !isValidEnumValue(PageOrientType, section.pageOrient)) return false;
|
|
2889
|
+
if (section.columnSeparatorType != null && !isValidEnumValue(ColumnSeparatorType, section.columnSeparatorType)) return false;
|
|
2890
|
+
if (section.pageNumberStart != null && (!Number.isInteger(section.pageNumberStart) || section.pageNumberStart < 1)) return false;
|
|
2891
|
+
if (section.pageSize && (!isPositiveFinite(section.pageSize.width) || !isPositiveFinite(section.pageSize.height))) return false;
|
|
2892
|
+
if ([
|
|
2893
|
+
section.marginTop,
|
|
2894
|
+
section.marginBottom,
|
|
2895
|
+
section.marginLeft,
|
|
2896
|
+
section.marginRight
|
|
2897
|
+
].some((margin) => margin != null && (!Number.isFinite(margin) || margin < 0))) return false;
|
|
2898
|
+
const pageSize = section.pageSize ?? documentStyle.pageSize;
|
|
2899
|
+
const marginTop = section.marginTop ?? documentStyle.marginTop ?? 0;
|
|
2900
|
+
const marginBottom = section.marginBottom ?? documentStyle.marginBottom ?? 0;
|
|
2901
|
+
const marginLeft = section.marginLeft ?? documentStyle.marginLeft ?? 0;
|
|
2902
|
+
const marginRight = section.marginRight ?? documentStyle.marginRight ?? 0;
|
|
2903
|
+
if ((pageSize === null || pageSize === void 0 ? void 0 : pageSize.width) != null && marginLeft + marginRight >= pageSize.width || (pageSize === null || pageSize === void 0 ? void 0 : pageSize.height) != null && marginTop + marginBottom >= pageSize.height) return false;
|
|
2904
|
+
const columns = section.columnProperties ?? [];
|
|
2905
|
+
if (columns.some(({ width, paddingEnd }) => !Number.isFinite(width) || !Number.isFinite(paddingEnd) || width < 0 || paddingEnd < 0)) return false;
|
|
2906
|
+
return columns.reduce((sum, { width, paddingEnd }) => sum + width + paddingEnd, 0) <= getSectionContentWidth(documentStyle, section);
|
|
2786
2907
|
}
|
|
2787
|
-
function
|
|
2788
|
-
|
|
2789
|
-
const jsonX = JSONX.getInstance();
|
|
2790
|
-
const drawing = createDocsCustomBlockDrawing(params);
|
|
2791
|
-
return composeActions([jsonX.removeOp(["drawings", params.blockId], drawing) ?? [], jsonX.removeOp(["drawingsOrder", params.drawingOrderIndex ?? 0], params.blockId) ?? []]);
|
|
2908
|
+
function isPositiveFinite(value) {
|
|
2909
|
+
return value != null && Number.isFinite(value) && value > 0;
|
|
2792
2910
|
}
|
|
2793
|
-
function
|
|
2794
|
-
return
|
|
2795
|
-
if (!action || JSONX.isNoop(action) || action.length === 0) return composed;
|
|
2796
|
-
if (!composed || JSONX.isNoop(composed) || composed.length === 0) return action;
|
|
2797
|
-
return JSONX.compose(composed, action) ?? [];
|
|
2798
|
-
}, []);
|
|
2911
|
+
function isValidEnumValue(enumObject, value) {
|
|
2912
|
+
return Object.values(enumObject).includes(value);
|
|
2799
2913
|
}
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
*
|
|
2817
|
-
*
|
|
2818
|
-
*
|
|
2819
|
-
*
|
|
2820
|
-
*
|
|
2821
|
-
*
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
_transformCustomRange(doc, selection, segmentId) {
|
|
2838
|
-
var _doc$getSelfOrHeaderF;
|
|
2839
|
-
const { startOffset, endOffset, collapsed } = selection;
|
|
2840
|
-
const customRanges = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(selection.segmentId ?? segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.customRanges) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.filter((range) => {
|
|
2841
|
-
const selectsFieldResult = range.rangeType === CustomRangeType.FIELD && !collapsed && startOffset <= range.startIndex + 1 && endOffset >= range.endIndex;
|
|
2842
|
-
if (!range.wholeEntity && !selectsFieldResult) return false;
|
|
2843
|
-
if (startOffset <= range.startIndex && endOffset > range.endIndex) return false;
|
|
2844
|
-
if (collapsed) return range.startIndex < startOffset && range.endIndex >= endOffset;
|
|
2845
|
-
return BuildTextUtils.range.isIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex);
|
|
2846
|
-
});
|
|
2847
|
-
if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.length) {
|
|
2848
|
-
let start = startOffset;
|
|
2849
|
-
let end = endOffset;
|
|
2850
|
-
customRanges.forEach((range) => {
|
|
2851
|
-
start = Math.min(range.startIndex, start);
|
|
2852
|
-
end = Math.max(range.endIndex + 1, end);
|
|
2853
|
-
});
|
|
2854
|
-
return {
|
|
2855
|
-
...selection,
|
|
2856
|
-
startOffset: start,
|
|
2857
|
-
endOffset: end,
|
|
2858
|
-
collapsed: start === end
|
|
2859
|
-
};
|
|
2860
|
-
}
|
|
2861
|
-
return selection;
|
|
2862
|
-
}
|
|
2863
|
-
_initSelectionChange() {
|
|
2864
|
-
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
2865
|
-
if (commandInfo.id === SetTextSelectionsOperation.id) {
|
|
2866
|
-
const params = commandInfo.params;
|
|
2867
|
-
const { unitId, ranges, isEditing } = params;
|
|
2868
|
-
const doc = this._univerInstanceService.getUnit(unitId);
|
|
2869
|
-
if (!doc) return;
|
|
2870
|
-
const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range, params.segmentId));
|
|
2871
|
-
if (transformedRanges.some((range, i) => ranges[i] !== range)) this._textSelectionManagerService.replaceDocRanges(transformedRanges, void 0, isEditing);
|
|
2872
|
-
}
|
|
2873
|
-
}));
|
|
2914
|
+
function executeSectionTextX(commandService, documentDataModel, textX, trigger) {
|
|
2915
|
+
const actions = JSONX.getInstance().editOp(textX.serialize(), getRichTextEditPath(documentDataModel));
|
|
2916
|
+
return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
|
|
2917
|
+
unitId: documentDataModel.getUnitId(),
|
|
2918
|
+
actions,
|
|
2919
|
+
textRanges: null,
|
|
2920
|
+
noNeedSetTextRange: true,
|
|
2921
|
+
debounce: true,
|
|
2922
|
+
isEditing: false,
|
|
2923
|
+
trigger
|
|
2924
|
+
}));
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
//#endregion
|
|
2928
|
+
//#region src/services/permission/document-permission-rule.model.ts
|
|
2929
|
+
/**
|
|
2930
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2931
|
+
*
|
|
2932
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2933
|
+
* you may not use this file except in compliance with the License.
|
|
2934
|
+
* You may obtain a copy of the License at
|
|
2935
|
+
*
|
|
2936
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2937
|
+
*
|
|
2938
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2939
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2940
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2941
|
+
* See the License for the specific language governing permissions and
|
|
2942
|
+
* limitations under the License.
|
|
2943
|
+
*/
|
|
2944
|
+
let DocumentPermissionRuleModel = class DocumentPermissionRuleModel extends ObjectPermissionRuleModel {
|
|
2945
|
+
constructor(resources) {
|
|
2946
|
+
super(resources, "DOC_OBJECT_PERMISSION_PLUGIN", UniverInstanceType.UNIVER_DOC, [
|
|
2947
|
+
UnitObject.DocumentSection,
|
|
2948
|
+
UnitObject.DocumentParagraph,
|
|
2949
|
+
UnitObject.DocumentEntity
|
|
2950
|
+
]);
|
|
2874
2951
|
}
|
|
2875
2952
|
};
|
|
2876
|
-
|
|
2877
|
-
__decorateParam(0, ICommandService),
|
|
2878
|
-
__decorateParam(1, Inject(DocSelectionManagerService)),
|
|
2879
|
-
__decorateParam(2, IUniverInstanceService)
|
|
2880
|
-
], DocCustomRangeController);
|
|
2953
|
+
DocumentPermissionRuleModel = __decorate([__decorateParam(0, IResourceManagerService)], DocumentPermissionRuleModel);
|
|
2881
2954
|
|
|
2882
2955
|
//#endregion
|
|
2883
|
-
//#region src/
|
|
2884
|
-
const
|
|
2885
|
-
"
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
"evenPageFooterId"
|
|
2891
|
-
];
|
|
2892
|
-
const documentPermissionResolverIndexCache = /* @__PURE__ */ new WeakMap();
|
|
2893
|
-
function getDocumentPermissionResolverIndex(documentDataModel) {
|
|
2894
|
-
var _getMutationRevision, _snapshot$body;
|
|
2895
|
-
const mutationRevision = ((_getMutationRevision = documentDataModel.getMutationRevision) === null || _getMutationRevision === void 0 ? void 0 : _getMutationRevision.call(documentDataModel)) ?? NaN;
|
|
2896
|
-
const cached = documentPermissionResolverIndexCache.get(documentDataModel);
|
|
2897
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.mutationRevision) === mutationRevision) return cached;
|
|
2898
|
-
const snapshot = documentDataModel.getSnapshot();
|
|
2899
|
-
const topLevelSections = snapshot.body ? getTopLevelSectionBreaks(snapshot.body) : [];
|
|
2900
|
-
const drawingSegmentIds = /* @__PURE__ */ new Map();
|
|
2901
|
-
const addDrawingSegments = (body, segmentId) => {
|
|
2902
|
-
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) if (!drawingSegmentIds.has(block.blockId)) drawingSegmentIds.set(block.blockId, segmentId);
|
|
2903
|
-
};
|
|
2904
|
-
addDrawingSegments(snapshot.body, "");
|
|
2905
|
-
Object.entries(snapshot.headers ?? {}).forEach(([segmentId, header]) => addDrawingSegments(header.body, segmentId));
|
|
2906
|
-
Object.entries(snapshot.footers ?? {}).forEach(([segmentId, footer]) => addDrawingSegments(footer.body, segmentId));
|
|
2907
|
-
Object.entries(snapshot.notes ?? {}).forEach(([segmentId, footnote]) => addDrawingSegments(footnote.body, segmentId));
|
|
2908
|
-
const footnoteReferenceRanges = /* @__PURE__ */ new Map();
|
|
2909
|
-
for (const reference of ((_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.customRanges) ?? []) {
|
|
2910
|
-
var _reference$properties;
|
|
2911
|
-
if ((reference.rangeType === CustomRangeType.FOOTNOTE || reference.rangeType === CustomRangeType.ENDNOTE) && typeof ((_reference$properties = reference.properties) === null || _reference$properties === void 0 ? void 0 : _reference$properties.noteId) === "string") footnoteReferenceRanges.set(reference.properties.noteId, {
|
|
2912
|
-
startOffset: reference.startIndex,
|
|
2913
|
-
endOffset: reference.endIndex + 1
|
|
2914
|
-
});
|
|
2956
|
+
//#region src/commands/mutations/set-document-permission-rule.mutation.ts
|
|
2957
|
+
const SetDocumentPermissionRuleMutation = {
|
|
2958
|
+
id: "doc.mutation.set-permission-rule",
|
|
2959
|
+
type: CommandType.MUTATION,
|
|
2960
|
+
handler: (accessor, params) => {
|
|
2961
|
+
if (!params || !accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC)) return false;
|
|
2962
|
+
return accessor.get(DocumentPermissionRuleModel).setRule(params.unitId, params.objectType, params.objectId, params.rule);
|
|
2915
2963
|
}
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
function getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
|
|
2927
|
-
var _documentDataModel$ge, _snapshot$notes;
|
|
2928
|
-
const cached = resolverIndex.segments.get(segmentId);
|
|
2929
|
-
if (cached) return cached;
|
|
2930
|
-
const body = ((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody()) ?? null;
|
|
2931
|
-
const snapshot = documentDataModel.getSnapshot();
|
|
2932
|
-
const note = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
|
|
2933
|
-
const drawings = (note ? note.drawings : snapshot.drawings) ?? {};
|
|
2934
|
-
const entities = body == null ? [] : [
|
|
2935
|
-
...(body.tables ?? []).map((item) => ({
|
|
2936
|
-
type: "table",
|
|
2937
|
-
id: item.tableId,
|
|
2938
|
-
startOffset: item.startIndex,
|
|
2939
|
-
endOffset: item.endIndex
|
|
2940
|
-
})),
|
|
2941
|
-
...(body.customBlocks ?? []).map((item) => ({
|
|
2942
|
-
type: drawings[item.blockId] ? "drawing" : "custom-block",
|
|
2943
|
-
id: item.blockId,
|
|
2944
|
-
startOffset: item.startIndex,
|
|
2945
|
-
endOffset: item.startIndex + 1
|
|
2946
|
-
})),
|
|
2947
|
-
...(body.blockRanges ?? []).map((item) => ({
|
|
2948
|
-
type: "block-range",
|
|
2949
|
-
id: item.blockId,
|
|
2950
|
-
startOffset: item.startIndex,
|
|
2951
|
-
endOffset: item.endIndex + 1
|
|
2952
|
-
})),
|
|
2953
|
-
...(body.customRanges ?? []).map((item) => ({
|
|
2954
|
-
type: "custom-range",
|
|
2955
|
-
id: item.rangeId,
|
|
2956
|
-
startOffset: item.startIndex,
|
|
2957
|
-
endOffset: item.endIndex + 1
|
|
2958
|
-
})),
|
|
2959
|
-
...(body.columnGroups ?? []).map((item) => ({
|
|
2960
|
-
type: "column-group",
|
|
2961
|
-
id: item.columnGroupId,
|
|
2962
|
-
startOffset: item.startIndex,
|
|
2963
|
-
endOffset: item.endIndex + 1
|
|
2964
|
-
}))
|
|
2965
|
-
];
|
|
2966
|
-
const entityRanges = new Map(entities.map((entity) => [`${entity.type}:${entity.id}`, {
|
|
2967
|
-
startOffset: entity.startOffset,
|
|
2968
|
-
endOffset: entity.endOffset
|
|
2969
|
-
}]));
|
|
2970
|
-
for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) {
|
|
2971
|
-
const range = {
|
|
2972
|
-
startOffset: block.startIndex,
|
|
2973
|
-
endOffset: block.startIndex + 1
|
|
2974
|
-
};
|
|
2975
|
-
entityRanges.set(`custom-block:${block.blockId}`, range);
|
|
2976
|
-
entityRanges.set(`drawing:${block.blockId}`, range);
|
|
2964
|
+
};
|
|
2965
|
+
|
|
2966
|
+
//#endregion
|
|
2967
|
+
//#region src/commands/mutations/set-document-permission-rules.mutation.ts
|
|
2968
|
+
const SetDocumentPermissionRulesMutation = {
|
|
2969
|
+
id: "doc.mutation.set-permission-rules",
|
|
2970
|
+
type: CommandType.MUTATION,
|
|
2971
|
+
handler: (accessor, params) => {
|
|
2972
|
+
if (!params || !accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC)) return false;
|
|
2973
|
+
return accessor.get(DocumentPermissionRuleModel).setRules(params.unitId, params.rules);
|
|
2977
2974
|
}
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2975
|
+
};
|
|
2976
|
+
|
|
2977
|
+
//#endregion
|
|
2978
|
+
//#region src/embed-host-anchor.ts
|
|
2979
|
+
const EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY = "UniverEmbedDocsCustomBlock";
|
|
2980
|
+
const DEFAULT_CUSTOM_BLOCK_SIZE = {
|
|
2981
|
+
width: 720,
|
|
2982
|
+
height: 360
|
|
2983
|
+
};
|
|
2984
|
+
const SHEET_LIKE_CUSTOM_BLOCK_SIZE = {
|
|
2985
|
+
width: 960,
|
|
2986
|
+
height: 480
|
|
2987
|
+
};
|
|
2988
|
+
const SLIDE_CUSTOM_BLOCK_SIZE = {
|
|
2989
|
+
width: 720,
|
|
2990
|
+
height: 405
|
|
2991
|
+
};
|
|
2992
|
+
function createDocsCustomBlockInsertMutation(params) {
|
|
2993
|
+
return createRichTextMutation(params.unitId, params.segmentId, createInsertCustomBlockActions(params));
|
|
2990
2994
|
}
|
|
2991
|
-
function
|
|
2992
|
-
|
|
2993
|
-
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
2994
|
-
const { body } = segmentIndex;
|
|
2995
|
-
if (!body) return [];
|
|
2996
|
-
return [
|
|
2997
|
-
...getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex),
|
|
2998
|
-
...getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex),
|
|
2999
|
-
...getEntityPermissionObjectIds(segmentId, range, segmentIndex)
|
|
3000
|
-
];
|
|
2995
|
+
function createDocsCustomBlockRemoveMutation(params) {
|
|
2996
|
+
return createRichTextMutation(params.unitId, params.segmentId, createRemoveCustomBlockActions(params));
|
|
3001
2997
|
}
|
|
3002
|
-
function
|
|
3003
|
-
const
|
|
3004
|
-
if (
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
const path = cursor.getPath();
|
|
3008
|
-
const edit = cursor.getComponent();
|
|
3009
|
-
const scopedSegment = [
|
|
3010
|
-
"headers",
|
|
3011
|
-
"footers",
|
|
3012
|
-
"notes"
|
|
3013
|
-
].includes(String(path[0])) && typeof path[1] === "string" ? path[1] : segmentId;
|
|
3014
|
-
if (path[0] === "notes" && typeof path[1] === "string") getSectionPermissionObjectIds(documentDataModel, path[1], {
|
|
3015
|
-
startOffset: 0,
|
|
3016
|
-
endOffset: 0
|
|
3017
|
-
}).forEach((objectId) => result.add(objectId));
|
|
3018
|
-
if (path[0] === "noteSettings") getDocumentPermissionResolverIndex(documentDataModel).topLevelSections.forEach((section) => {
|
|
3019
|
-
result.add(getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
3020
|
-
});
|
|
3021
|
-
if (path[0] === "body" && path[1] === "sectionBreaks" && typeof path[2] === "number" && (path[3] === "noteProperties" || path[3] === "suppressEndnotes")) {
|
|
3022
|
-
var _documentDataModel$ge2;
|
|
3023
|
-
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;
|
|
3024
|
-
if (sectionId) result.add(getDocumentSectionPermissionObjectId("", sectionId));
|
|
3025
|
-
}
|
|
3026
|
-
if (path[path.length - 1] !== "body" || (edit === null || edit === void 0 ? void 0 : edit.et) !== TextX.id || !Array.isArray(edit.e) || !edit.e.every(isTextXAction)) return;
|
|
3027
|
-
const textActions = edit.e;
|
|
3028
|
-
let offset = 0;
|
|
3029
|
-
const addRange = (startOffset, endOffset) => {
|
|
3030
|
-
getDocumentEditTargetObjectIds(documentDataModel, scopedSegment, {
|
|
3031
|
-
startOffset,
|
|
3032
|
-
endOffset
|
|
3033
|
-
}).forEach((objectId) => result.add(objectId));
|
|
3034
|
-
};
|
|
3035
|
-
textActions.forEach((action) => {
|
|
3036
|
-
if (action.t === TextXActionType.INSERT) {
|
|
3037
|
-
addRange(offset, offset);
|
|
3038
|
-
return;
|
|
3039
|
-
}
|
|
3040
|
-
if (action.t === TextXActionType.DELETE) {
|
|
3041
|
-
addRange(offset, offset + action.len);
|
|
3042
|
-
offset += action.len;
|
|
3043
|
-
return;
|
|
3044
|
-
}
|
|
3045
|
-
if (action.body !== void 0 || action.oldBody !== void 0 || action.coverType !== void 0) addRange(offset, offset + action.len);
|
|
3046
|
-
offset += action.len;
|
|
3047
|
-
});
|
|
2998
|
+
function createInsertCustomBlockActions(params) {
|
|
2999
|
+
const textX = new TextX();
|
|
3000
|
+
if (params.startIndex > 0) textX.push({
|
|
3001
|
+
t: TextXActionType.RETAIN,
|
|
3002
|
+
len: params.startIndex
|
|
3048
3003
|
});
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
}
|
|
3004
|
+
textX.push({
|
|
3005
|
+
t: TextXActionType.INSERT,
|
|
3006
|
+
body: {
|
|
3007
|
+
dataStream: "\b",
|
|
3008
|
+
customBlocks: [{
|
|
3009
|
+
startIndex: 0,
|
|
3010
|
+
blockId: params.blockId
|
|
3011
|
+
}]
|
|
3012
|
+
},
|
|
3013
|
+
len: 1
|
|
3014
|
+
});
|
|
3015
|
+
return composeActions([toBodyEditActions(textX, params.segmentId), createDrawingInsertActions(params)]);
|
|
3016
|
+
}
|
|
3017
|
+
function createRemoveCustomBlockActions(params) {
|
|
3018
|
+
const textX = new TextX();
|
|
3019
|
+
if (params.startIndex > 0) textX.push({
|
|
3020
|
+
t: TextXActionType.RETAIN,
|
|
3021
|
+
len: params.startIndex
|
|
3058
3022
|
});
|
|
3059
|
-
|
|
3023
|
+
textX.push({
|
|
3024
|
+
t: TextXActionType.DELETE,
|
|
3025
|
+
len: 1
|
|
3026
|
+
});
|
|
3027
|
+
return composeActions([toBodyEditActions(textX, params.segmentId), createDrawingRemoveActions(params)]);
|
|
3060
3028
|
}
|
|
3061
|
-
function
|
|
3062
|
-
const
|
|
3063
|
-
const
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3029
|
+
function createDocsCustomBlockDrawing(params) {
|
|
3030
|
+
const size = resolveDocsCustomBlockSize(params.childType);
|
|
3031
|
+
const isInline = params.interactionMode === "inline";
|
|
3032
|
+
return {
|
|
3033
|
+
unitId: params.unitId,
|
|
3034
|
+
subUnitId: params.unitId,
|
|
3035
|
+
drawingId: params.blockId,
|
|
3036
|
+
drawingType: DrawingTypeEnum.DRAWING_DOM,
|
|
3037
|
+
componentKey: params.componentKey ?? "UniverEmbedDocsCustomBlock",
|
|
3038
|
+
data: createEmbedDocsCustomBlockData(params),
|
|
3039
|
+
title: params.blockId,
|
|
3040
|
+
description: "Univer embedded unit custom block",
|
|
3041
|
+
layoutType: isInline ? PositionedObjectLayoutType.INLINE : PositionedObjectLayoutType.WRAP_TOP_AND_BOTTOM,
|
|
3042
|
+
allowTransform: false,
|
|
3043
|
+
docTransform: {
|
|
3044
|
+
size: {
|
|
3045
|
+
width: size.width,
|
|
3046
|
+
height: size.height
|
|
3047
|
+
},
|
|
3048
|
+
positionH: {
|
|
3049
|
+
relativeFrom: isInline ? ObjectRelativeFromH.PAGE : ObjectRelativeFromH.COLUMN,
|
|
3050
|
+
...isInline ? { posOffset: 0 } : { align: AlignTypeH.LEFT }
|
|
3051
|
+
},
|
|
3052
|
+
positionV: {
|
|
3053
|
+
relativeFrom: isInline ? ObjectRelativeFromV.PAGE : ObjectRelativeFromV.PARAGRAPH,
|
|
3054
|
+
posOffset: 0
|
|
3055
|
+
},
|
|
3056
|
+
angle: 0
|
|
3057
|
+
},
|
|
3058
|
+
transform: {
|
|
3059
|
+
left: 0,
|
|
3060
|
+
top: 0,
|
|
3061
|
+
width: size.width,
|
|
3062
|
+
height: size.height
|
|
3070
3063
|
}
|
|
3071
|
-
if (!isRecord$2(value)) return;
|
|
3072
|
-
Object.values(value).forEach(visit);
|
|
3073
3064
|
};
|
|
3074
|
-
visit(actions);
|
|
3075
|
-
return [...result];
|
|
3076
|
-
}
|
|
3077
|
-
function isTextXAction(value) {
|
|
3078
|
-
if (!isRecord$2(value) || typeof value.len !== "number") return false;
|
|
3079
|
-
if (value.t === TextXActionType.INSERT) return isRecord$2(value.body);
|
|
3080
|
-
return value.t === TextXActionType.RETAIN || value.t === TextXActionType.DELETE;
|
|
3081
|
-
}
|
|
3082
|
-
function isRecord$2(value) {
|
|
3083
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3084
3065
|
}
|
|
3085
|
-
function
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
return
|
|
3066
|
+
function resolveDocsCustomBlockSize(childType) {
|
|
3067
|
+
if (childType === UniverInstanceType.UNIVER_SHEET || childType === UniverInstanceType.UNIVER_BASE) return SHEET_LIKE_CUSTOM_BLOCK_SIZE;
|
|
3068
|
+
if (childType === UniverInstanceType.UNIVER_SLIDE) return SLIDE_CUSTOM_BLOCK_SIZE;
|
|
3069
|
+
return DEFAULT_CUSTOM_BLOCK_SIZE;
|
|
3089
3070
|
}
|
|
3090
|
-
function
|
|
3091
|
-
|
|
3092
|
-
const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
|
|
3093
|
-
const { body } = segmentIndex;
|
|
3094
|
-
const paragraph = segmentIndex.paragraphsById.get(paragraphId);
|
|
3095
|
-
if (!body || !paragraph) return [];
|
|
3096
|
-
return getSectionPermissionObjectIds(documentDataModel, segmentId, {
|
|
3097
|
-
startOffset: segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? getParagraphContentStartOffset(body, paragraph),
|
|
3098
|
-
endOffset: paragraph.startIndex + 1
|
|
3099
|
-
}, resolverIndex);
|
|
3071
|
+
function isSheetLikeDocsCustomBlockChildType(childType) {
|
|
3072
|
+
return childType === UniverInstanceType.UNIVER_SHEET || childType === UniverInstanceType.UNIVER_BASE;
|
|
3100
3073
|
}
|
|
3101
|
-
function
|
|
3102
|
-
return
|
|
3074
|
+
function createEmbedDocsCustomBlockData(params) {
|
|
3075
|
+
return {
|
|
3076
|
+
version: 1,
|
|
3077
|
+
embedId: params.embedId ?? params.blockId,
|
|
3078
|
+
hostUnitId: params.unitId,
|
|
3079
|
+
hostAnchorId: params.blockId,
|
|
3080
|
+
childUnitId: params.childUnitId,
|
|
3081
|
+
childType: params.childType,
|
|
3082
|
+
interactionMode: params.interactionMode ?? "block"
|
|
3083
|
+
};
|
|
3103
3084
|
}
|
|
3104
|
-
function
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
}).map((section) => section.sectionId);
|
|
3085
|
+
function isEmbedDocsCustomBlockData(data) {
|
|
3086
|
+
if (!data || typeof data !== "object") return false;
|
|
3087
|
+
const candidate = data;
|
|
3088
|
+
return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string";
|
|
3109
3089
|
}
|
|
3110
|
-
function
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
return getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, resolverIndex.topLevelSections).map((sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
|
|
3115
|
-
}
|
|
3116
|
-
return getSectionsIntersectingRange(resolverIndex.topLevelSections, range).map((section) => getDocumentSectionPermissionObjectId("", section.sectionId));
|
|
3090
|
+
function shouldUseInlineTextSelectionForDocsCustomBlockDrawing(drawing) {
|
|
3091
|
+
const data = drawing && typeof drawing === "object" ? drawing.data : void 0;
|
|
3092
|
+
if (!isEmbedDocsCustomBlockData(data)) return true;
|
|
3093
|
+
return data.interactionMode === "inline";
|
|
3117
3094
|
}
|
|
3118
|
-
function
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3095
|
+
function createRichTextMutation(unitId, segmentId, actions) {
|
|
3096
|
+
return {
|
|
3097
|
+
id: RichTextEditingMutation.id,
|
|
3098
|
+
params: {
|
|
3099
|
+
unitId,
|
|
3100
|
+
segmentId,
|
|
3101
|
+
actions,
|
|
3102
|
+
textRanges: [],
|
|
3103
|
+
isEditing: false,
|
|
3104
|
+
noNeedSetTextRange: true
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3122
3107
|
}
|
|
3123
|
-
function
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3108
|
+
function toBodyEditActions(textX, segmentId) {
|
|
3109
|
+
return JSONX.getInstance().editOp(textX.serialize(), segmentId ? [
|
|
3110
|
+
"headers",
|
|
3111
|
+
segmentId,
|
|
3112
|
+
"body"
|
|
3113
|
+
] : ["body"]) ?? [];
|
|
3127
3114
|
}
|
|
3128
|
-
function
|
|
3129
|
-
|
|
3130
|
-
const
|
|
3131
|
-
|
|
3115
|
+
function createDrawingInsertActions(params) {
|
|
3116
|
+
if (params.segmentId) return [];
|
|
3117
|
+
const jsonX = JSONX.getInstance();
|
|
3118
|
+
const drawing = createDocsCustomBlockDrawing(params);
|
|
3119
|
+
return composeActions([jsonX.insertOp(["drawings", params.blockId], drawing) ?? [], jsonX.insertOp(["drawingsOrder", params.drawingOrderIndex ?? 0], params.blockId) ?? []]);
|
|
3132
3120
|
}
|
|
3133
|
-
function
|
|
3134
|
-
if (
|
|
3135
|
-
|
|
3121
|
+
function createDrawingRemoveActions(params) {
|
|
3122
|
+
if (params.segmentId) return [];
|
|
3123
|
+
const jsonX = JSONX.getInstance();
|
|
3124
|
+
const drawing = createDocsCustomBlockDrawing(params);
|
|
3125
|
+
return composeActions([jsonX.removeOp(["drawings", params.blockId], drawing) ?? [], jsonX.removeOp(["drawingsOrder", params.drawingOrderIndex ?? 0], params.blockId) ?? []]);
|
|
3136
3126
|
}
|
|
3137
|
-
function
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
});
|
|
3143
|
-
return [...result];
|
|
3127
|
+
function composeActions(actions) {
|
|
3128
|
+
return actions.reduce((composed, action) => {
|
|
3129
|
+
if (!action || JSONX.isNoop(action) || action.length === 0) return composed;
|
|
3130
|
+
if (!composed || JSONX.isNoop(composed) || composed.length === 0) return action;
|
|
3131
|
+
return JSONX.compose(composed, action) ?? [];
|
|
3132
|
+
}, []);
|
|
3144
3133
|
}
|
|
3145
3134
|
|
|
3135
|
+
//#endregion
|
|
3136
|
+
//#region package.json
|
|
3137
|
+
var name = "@univerjs/docs";
|
|
3138
|
+
var version = "1.3.0";
|
|
3139
|
+
|
|
3140
|
+
//#endregion
|
|
3141
|
+
//#region src/config/config.ts
|
|
3142
|
+
/**
|
|
3143
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3144
|
+
*
|
|
3145
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3146
|
+
* you may not use this file except in compliance with the License.
|
|
3147
|
+
* You may obtain a copy of the License at
|
|
3148
|
+
*
|
|
3149
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3150
|
+
*
|
|
3151
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3152
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3153
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3154
|
+
* See the License for the specific language governing permissions and
|
|
3155
|
+
* limitations under the License.
|
|
3156
|
+
*/
|
|
3157
|
+
const DOCS_PLUGIN_CONFIG_KEY = "docs.config";
|
|
3158
|
+
const configSymbol$1 = Symbol(DOCS_PLUGIN_CONFIG_KEY);
|
|
3159
|
+
const defaultPluginConfig = {};
|
|
3160
|
+
|
|
3161
|
+
//#endregion
|
|
3162
|
+
//#region src/controllers/custom-range.controller.ts
|
|
3163
|
+
let DocCustomRangeController = class DocCustomRangeController extends Disposable {
|
|
3164
|
+
constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
|
|
3165
|
+
super();
|
|
3166
|
+
this._commandService = _commandService;
|
|
3167
|
+
this._textSelectionManagerService = _textSelectionManagerService;
|
|
3168
|
+
this._univerInstanceService = _univerInstanceService;
|
|
3169
|
+
this._initSelectionChange();
|
|
3170
|
+
}
|
|
3171
|
+
_transformCustomRange(doc, selection, segmentId) {
|
|
3172
|
+
var _doc$getSelfOrHeaderF;
|
|
3173
|
+
const { startOffset, endOffset, collapsed } = selection;
|
|
3174
|
+
const customRanges = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(selection.segmentId ?? segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.customRanges) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.filter((range) => {
|
|
3175
|
+
const selectsFieldResult = range.rangeType === CustomRangeType.FIELD && !collapsed && startOffset <= range.startIndex + 1 && endOffset >= range.endIndex;
|
|
3176
|
+
if (!range.wholeEntity && !selectsFieldResult) return false;
|
|
3177
|
+
if (startOffset <= range.startIndex && endOffset > range.endIndex) return false;
|
|
3178
|
+
if (collapsed) return range.startIndex < startOffset && range.endIndex >= endOffset;
|
|
3179
|
+
return BuildTextUtils.range.isIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex);
|
|
3180
|
+
});
|
|
3181
|
+
if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.length) {
|
|
3182
|
+
let start = startOffset;
|
|
3183
|
+
let end = endOffset;
|
|
3184
|
+
customRanges.forEach((range) => {
|
|
3185
|
+
start = Math.min(range.startIndex, start);
|
|
3186
|
+
end = Math.max(range.endIndex + 1, end);
|
|
3187
|
+
});
|
|
3188
|
+
return {
|
|
3189
|
+
...selection,
|
|
3190
|
+
startOffset: start,
|
|
3191
|
+
endOffset: end,
|
|
3192
|
+
collapsed: start === end
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
return selection;
|
|
3196
|
+
}
|
|
3197
|
+
_initSelectionChange() {
|
|
3198
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
3199
|
+
if (commandInfo.id === SetTextSelectionsOperation.id) {
|
|
3200
|
+
const params = commandInfo.params;
|
|
3201
|
+
const { unitId, ranges, isEditing } = params;
|
|
3202
|
+
const doc = this._univerInstanceService.getUnit(unitId);
|
|
3203
|
+
if (!doc) return;
|
|
3204
|
+
const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range, params.segmentId));
|
|
3205
|
+
if (transformedRanges.some((range, i) => ranges[i] !== range)) this._textSelectionManagerService.replaceDocRanges(transformedRanges, void 0, isEditing);
|
|
3206
|
+
}
|
|
3207
|
+
}));
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
DocCustomRangeController = __decorate([
|
|
3211
|
+
__decorateParam(0, ICommandService),
|
|
3212
|
+
__decorateParam(1, Inject(DocSelectionManagerService)),
|
|
3213
|
+
__decorateParam(2, IUniverInstanceService)
|
|
3214
|
+
], DocCustomRangeController);
|
|
3215
|
+
|
|
3146
3216
|
//#endregion
|
|
3147
3217
|
//#region src/controllers/doc-permission.controller.ts
|
|
3148
3218
|
const NON_EDIT_DOCUMENT_COMMAND_IDS = /* @__PURE__ */ new Set([
|
|
@@ -3719,6 +3789,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
|
|
|
3719
3789
|
SetDocumentPermissionsCommand,
|
|
3720
3790
|
SetDocumentDefaultParagraphStyleCommand,
|
|
3721
3791
|
SetDocumentNameCommand,
|
|
3792
|
+
SetHeadingCollapsedCommand,
|
|
3722
3793
|
SetSectionHeaderFooterLinkCommand,
|
|
3723
3794
|
UpdateDocumentParagraphStyleCommand,
|
|
3724
3795
|
UpdateDocumentSectionCommand,
|
|
@@ -4808,4 +4879,4 @@ function normalizeTextRange(textRange) {
|
|
|
4808
4879
|
}
|
|
4809
4880
|
|
|
4810
4881
|
//#endregion
|
|
4811
|
-
export { CreateHeaderFooterCommand, DOCUMENT_UNIT_PERMISSION_ACTIONS, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocHistoryAction, DocInterceptorService, DocLayoutExecutorService, DocLayoutExecutorState, DocLayoutExecutorType, DocLayoutSessionStatus, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, DocsLayoutWorkerCapabilityError, DocsLayoutWorkerClientService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetDocumentNameCommand, SetDocumentPermissionCommand, SetDocumentPermissionRuleMutation, SetDocumentPermissionRulesMutation, SetDocumentPermissionsCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsLayoutWorkerPlugin, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, canEditDocumentTargets, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createDocumentPermissionPoint, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getDocumentDrawingSegmentId, getDocumentEditTargetObjectIds, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentParagraphParentPermissionObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, setDocumentPermissionValue, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, startDocsLayoutWorker, transformDocumentTextRanges, transformToDocDrawingPosition };
|
|
4882
|
+
export { CreateHeaderFooterCommand, DOCUMENT_UNIT_PERMISSION_ACTIONS, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocHistoryAction, DocInterceptorService, DocLayoutExecutorService, DocLayoutExecutorState, DocLayoutExecutorType, DocLayoutSessionStatus, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, DocsLayoutWorkerCapabilityError, DocsLayoutWorkerClientService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetDocumentNameCommand, SetDocumentPermissionCommand, SetDocumentPermissionRuleMutation, SetDocumentPermissionRulesMutation, SetDocumentPermissionsCommand, SetHeadingCollapsedCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsLayoutWorkerPlugin, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, canEditDocumentTargets, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createDocumentPermissionPoint, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getDocumentDrawingSegmentId, getDocumentEditTargetObjectIds, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentParagraphParentPermissionObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, setDocumentPermissionValue, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, startDocsLayoutWorker, transformDocumentTextRanges, transformToDocDrawingPosition };
|