@univerjs/docs 1.3.1 → 1.5.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 +12 -46
- package/lib/cjs/facade.js +19 -33
- package/lib/cjs/index.js +192 -1433
- package/lib/cjs/protocol-CvmouuxB.js +955 -0
- package/lib/cjs/worker.js +377 -0
- package/lib/es/facade.js +19 -33
- package/lib/es/index.js +73 -1313
- package/lib/es/protocol-D1XjAOOp.js +854 -0
- package/lib/es/worker.js +371 -0
- package/lib/facade.js +19 -33
- package/lib/index.js +73 -1313
- package/lib/protocol-D1XjAOOp.js +854 -0
- package/lib/types/config/config.d.ts +4 -0
- package/lib/types/index.d.ts +3 -2
- package/lib/types/layout-worker/index.d.ts +1 -5
- package/lib/types/layout-worker/worker.d.ts +1 -1
- package/lib/types/services/doc-interceptor/doc-interceptor.service.d.ts +1 -1
- package/lib/types/services/doc-state-change-manager.service.d.ts +1 -1
- package/lib/types/services/permission/document-permission.d.ts +1 -1
- package/lib/types/worker.d.ts +27 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/lib/worker.js +371 -0
- package/package.json +15 -10
package/lib/es/worker.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { _ as _defineProperty, a as DOCS_WORKER_PLUGIN_CONFIG_KEY, c as name, f as DocLayoutExecutorType, g as __decorateParam, h as __decorate, l as version, n as DocsLayoutWorkerPerformanceTracker, p as DocLayoutSessionStatus, r as DocsLayoutFontLoader, s as defaultPluginWorkerConfig, t as DOCS_LAYOUT_WORKER_CHANNEL } from "./protocol-D1XjAOOp.js";
|
|
2
|
+
import { DocumentDataModel, IConfigService, Inject, Injector, LocaleService, Plugin, Tools, merge, requestImmediateMacroTask } from "@univerjs/core";
|
|
3
|
+
import { Observable, shareReplay } from "rxjs";
|
|
4
|
+
import { ChannelService, fromModule } from "@univerjs/rpc";
|
|
5
|
+
import { DocumentLayoutSession, FontCache, setDocsCustomBlockRenderViewportProvider } from "@univerjs/engine-render/worker";
|
|
6
|
+
|
|
7
|
+
// src/layout-worker/worker.ts
|
|
8
|
+
const FONT_PROBE_CONTENT = "Univer 文档 Worker 0123456789";
|
|
9
|
+
const FONT_PROBE_STYLE = "16px Arial";
|
|
10
|
+
const WORKER_LAYOUT_INTERRUPT_INTERVAL = 8;
|
|
11
|
+
function yieldForWorkerMessage() {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
requestImmediateMacroTask(() => resolve());
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function createDocsLayoutWorkerMessageProtocol(performanceTracker) {
|
|
17
|
+
return {
|
|
18
|
+
send(message) {
|
|
19
|
+
const startedAt = Tools.now();
|
|
20
|
+
postMessage(message);
|
|
21
|
+
performanceTracker.recordResponse(message, Tools.now() - startedAt);
|
|
22
|
+
},
|
|
23
|
+
onMessage: new Observable((subscriber) => {
|
|
24
|
+
const handler = (event) => subscriber.next(event.data);
|
|
25
|
+
addEventListener("message", handler);
|
|
26
|
+
return () => removeEventListener("message", handler);
|
|
27
|
+
}).pipe(shareReplay({
|
|
28
|
+
bufferSize: 1,
|
|
29
|
+
refCount: true
|
|
30
|
+
}))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function getCustomRangePresentationKey(entry) {
|
|
34
|
+
return JSON.stringify([entry.segmentId, entry.rangeId]);
|
|
35
|
+
}
|
|
36
|
+
function applyRecordPatch(target, patch) {
|
|
37
|
+
if (patch == null) return;
|
|
38
|
+
for (const key of patch.removals) delete target[key];
|
|
39
|
+
Object.assign(target, patch.upserts);
|
|
40
|
+
}
|
|
41
|
+
var DocsLayoutWorkerRuntime = class {
|
|
42
|
+
constructor(_performanceTracker = new DocsLayoutWorkerPerformanceTracker()) {
|
|
43
|
+
this._performanceTracker = _performanceTracker;
|
|
44
|
+
_defineProperty(this, "_sessions", /* @__PURE__ */ new Map());
|
|
45
|
+
_defineProperty(this, "_fontLoader", new DocsLayoutFontLoader());
|
|
46
|
+
_defineProperty(this, "type", "worker");
|
|
47
|
+
}
|
|
48
|
+
initialize(fontFaces = []) {
|
|
49
|
+
return this._fontLoader.load(fontFaces);
|
|
50
|
+
}
|
|
51
|
+
async getCapabilities() {
|
|
52
|
+
const metrics = FontCache.getMeasureText(FONT_PROBE_CONTENT, FONT_PROBE_STYLE);
|
|
53
|
+
return {
|
|
54
|
+
protocolVersion: 5,
|
|
55
|
+
executor: "worker",
|
|
56
|
+
offscreenCanvas: typeof OffscreenCanvas !== "undefined",
|
|
57
|
+
structuredClone: typeof structuredClone === "function",
|
|
58
|
+
fontProbe: {
|
|
59
|
+
content: FONT_PROBE_CONTENT,
|
|
60
|
+
font: FONT_PROBE_STYLE,
|
|
61
|
+
width: metrics.width,
|
|
62
|
+
actualBoundingBoxAscent: metrics.actualBoundingBoxAscent,
|
|
63
|
+
actualBoundingBoxDescent: metrics.actualBoundingBoxDescent
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async recover() {
|
|
68
|
+
for (const session of this._sessions.values()) for (const mount of session.layoutSessions.values()) mount.layoutSession.dispose();
|
|
69
|
+
this._sessions.clear();
|
|
70
|
+
}
|
|
71
|
+
async createSession(request) {
|
|
72
|
+
if (typeof OffscreenCanvas === "undefined") throw new Error("Document layout Worker requires OffscreenCanvas text measurement support.");
|
|
73
|
+
const currentSession = this._sessions.get(request.unitId);
|
|
74
|
+
if (currentSession != null && request.sessionEpoch < currentSession.sessionEpoch) return;
|
|
75
|
+
this._disposeSession(request.unitId);
|
|
76
|
+
FontCache.setNormalLineHeightCache(request.normalFontLineHeights ?? {});
|
|
77
|
+
const dataModel = new DocumentDataModel(request.snapshot);
|
|
78
|
+
const localeService = new LocaleService();
|
|
79
|
+
if (request.localeData != null) localeService.load({ [request.locale]: request.localeData });
|
|
80
|
+
localeService.setLocale(request.locale);
|
|
81
|
+
localeService.setDirection(request.direction);
|
|
82
|
+
this._sessions.set(request.unitId, {
|
|
83
|
+
sessionEpoch: request.sessionEpoch,
|
|
84
|
+
dataModel,
|
|
85
|
+
layoutSessions: /* @__PURE__ */ new Map(),
|
|
86
|
+
localeService,
|
|
87
|
+
modelRevision: request.modelRevision,
|
|
88
|
+
customRangePresentations: /* @__PURE__ */ new Map()
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async startLayout(request) {
|
|
92
|
+
const session = this._sessions.get(request.unitId);
|
|
93
|
+
if (session == null) return { status: "not-found" };
|
|
94
|
+
if (session.modelRevision !== request.baseRevision) return {
|
|
95
|
+
status: "resnapshot-required",
|
|
96
|
+
modelRevision: session.modelRevision
|
|
97
|
+
};
|
|
98
|
+
if (!this._applyMutations(session, request)) return {
|
|
99
|
+
status: "resnapshot-required",
|
|
100
|
+
modelRevision: session.modelRevision
|
|
101
|
+
};
|
|
102
|
+
FontCache.setNormalLineHeightCache(request.normalFontLineHeights ?? {});
|
|
103
|
+
this._updateCustomRangePresentations(session, request);
|
|
104
|
+
this._applyCustomRangePresentations(session.dataModel, Array.from(session.customRangePresentations.values()));
|
|
105
|
+
let mount = session.layoutSessions.get(request.mountId);
|
|
106
|
+
if (mount != null && (request.mountEpoch < mount.mountEpoch || request.mountEpoch === mount.mountEpoch && request.viewportEpoch < mount.viewportEpoch)) return { status: "superseded" };
|
|
107
|
+
if (mount != null && request.mountEpoch > mount.mountEpoch) {
|
|
108
|
+
mount.layoutSession.dispose();
|
|
109
|
+
session.layoutSessions.delete(request.mountId);
|
|
110
|
+
mount = void 0;
|
|
111
|
+
}
|
|
112
|
+
if (mount == null) {
|
|
113
|
+
const customBlockViewports = { ...request.customBlockViewports };
|
|
114
|
+
applyRecordPatch(customBlockViewports, request.customBlockViewportPatch);
|
|
115
|
+
mount = {
|
|
116
|
+
mountId: request.mountId,
|
|
117
|
+
layoutSession: new DocumentLayoutSession(session.dataModel, session.localeService),
|
|
118
|
+
customBlockViewports,
|
|
119
|
+
metricsRevision: request.metricsRevision,
|
|
120
|
+
mountEpoch: request.mountEpoch,
|
|
121
|
+
viewportEpoch: request.viewportEpoch,
|
|
122
|
+
activeGeneration: null,
|
|
123
|
+
cancelledGeneration: null
|
|
124
|
+
};
|
|
125
|
+
session.layoutSessions.set(request.mountId, mount);
|
|
126
|
+
} else {
|
|
127
|
+
if (request.customBlockViewports != null) mount.customBlockViewports = { ...request.customBlockViewports };
|
|
128
|
+
applyRecordPatch(mount.customBlockViewports, request.customBlockViewportPatch);
|
|
129
|
+
mount.metricsRevision = request.metricsRevision;
|
|
130
|
+
mount.viewportEpoch = request.viewportEpoch;
|
|
131
|
+
}
|
|
132
|
+
const generation = mount.layoutSession.start({
|
|
133
|
+
waitForHyphenationPatterns: true,
|
|
134
|
+
reason: request.reason,
|
|
135
|
+
anchor: request.anchor,
|
|
136
|
+
priorityAnchor: request.priorityAnchor,
|
|
137
|
+
invalidation: request.invalidation,
|
|
138
|
+
modernPageWidth: request.modernPageWidth,
|
|
139
|
+
modernHorizontalMargin: request.modernHorizontalMargin
|
|
140
|
+
});
|
|
141
|
+
mount.activeGeneration = generation;
|
|
142
|
+
mount.cancelledGeneration = null;
|
|
143
|
+
return {
|
|
144
|
+
status: "accepted",
|
|
145
|
+
step: await this._runLayoutStep(session, mount, generation, request.budgetMs)
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
_applyMutations(session, request) {
|
|
149
|
+
for (const mutation of request.mutations) {
|
|
150
|
+
if (mutation.baseRevision !== session.modelRevision || mutation.modelRevision !== mutation.baseRevision + 1) return false;
|
|
151
|
+
session.dataModel.apply(mutation.actions);
|
|
152
|
+
session.modelRevision = mutation.modelRevision;
|
|
153
|
+
}
|
|
154
|
+
if (session.modelRevision !== request.modelRevision) return false;
|
|
155
|
+
if (request.mutations.length > 0) for (const mount of session.layoutSessions.values()) {
|
|
156
|
+
mount.activeGeneration = null;
|
|
157
|
+
mount.cancelledGeneration = null;
|
|
158
|
+
mount.layoutSession.resetDataModel(session.dataModel);
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
_applyCustomRangePresentations(dataModel, presentations) {
|
|
163
|
+
const rangeMaps = /* @__PURE__ */ new Map();
|
|
164
|
+
const segmentModels = [
|
|
165
|
+
["", dataModel],
|
|
166
|
+
...dataModel.headerModelMap,
|
|
167
|
+
...dataModel.footerModelMap
|
|
168
|
+
];
|
|
169
|
+
for (const [segmentId, segmentModel] of segmentModels) {
|
|
170
|
+
var _segmentModel$getBody;
|
|
171
|
+
const rangeMap = /* @__PURE__ */ new Map();
|
|
172
|
+
for (const range of ((_segmentModel$getBody = segmentModel.getBody()) === null || _segmentModel$getBody === void 0 ? void 0 : _segmentModel$getBody.customRanges) ?? []) {
|
|
173
|
+
const workerRange = range;
|
|
174
|
+
delete workerRange.active;
|
|
175
|
+
delete workerRange.glyphAscentEm;
|
|
176
|
+
delete workerRange.glyphDescentEm;
|
|
177
|
+
delete workerRange.glyphWidthEm;
|
|
178
|
+
delete workerRange.show;
|
|
179
|
+
if (!rangeMap.has(range.rangeId)) rangeMap.set(range.rangeId, workerRange);
|
|
180
|
+
}
|
|
181
|
+
rangeMaps.set(segmentId, rangeMap);
|
|
182
|
+
}
|
|
183
|
+
for (const { segmentId, rangeId, presentation } of presentations ?? []) {
|
|
184
|
+
const rangeMap = rangeMaps.get(segmentId);
|
|
185
|
+
const range = rangeMap === null || rangeMap === void 0 ? void 0 : rangeMap.get(rangeId);
|
|
186
|
+
if (range != null) {
|
|
187
|
+
Object.assign(range, presentation);
|
|
188
|
+
rangeMap === null || rangeMap === void 0 || rangeMap.delete(rangeId);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
_updateCustomRangePresentations(session, request) {
|
|
193
|
+
var _request$customRangeP, _request$customRangeP2;
|
|
194
|
+
if (request.customRangePresentations != null) {
|
|
195
|
+
session.customRangePresentations.clear();
|
|
196
|
+
for (const entry of request.customRangePresentations) {
|
|
197
|
+
const key = getCustomRangePresentationKey(entry);
|
|
198
|
+
if (!session.customRangePresentations.has(key)) session.customRangePresentations.set(key, entry);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const removal of ((_request$customRangeP = request.customRangePresentationPatch) === null || _request$customRangeP === void 0 ? void 0 : _request$customRangeP.removals) ?? []) session.customRangePresentations.delete(getCustomRangePresentationKey(removal));
|
|
202
|
+
for (const entry of ((_request$customRangeP2 = request.customRangePresentationPatch) === null || _request$customRangeP2 === void 0 ? void 0 : _request$customRangeP2.upserts) ?? []) session.customRangePresentations.set(getCustomRangePresentationKey(entry), entry);
|
|
203
|
+
}
|
|
204
|
+
async stepLayout(request) {
|
|
205
|
+
const session = this._getSession(request.unitId);
|
|
206
|
+
const mount = this._getLayoutMount(session, request);
|
|
207
|
+
return await this._runLayoutStep(session, mount, request.generation, request.budgetMs);
|
|
208
|
+
}
|
|
209
|
+
async publishBacklog(request) {
|
|
210
|
+
const session = this._getSession(request.unitId);
|
|
211
|
+
const mount = this._getLayoutMount(session, request);
|
|
212
|
+
return this._runWithCustomBlockViewports(session, mount, () => ({
|
|
213
|
+
...mount.layoutSession.publishBacklog(request.generation),
|
|
214
|
+
unitId: request.unitId,
|
|
215
|
+
mountId: request.mountId,
|
|
216
|
+
mountEpoch: mount.mountEpoch,
|
|
217
|
+
viewportEpoch: mount.viewportEpoch,
|
|
218
|
+
modelRevision: session.modelRevision,
|
|
219
|
+
metricsRevision: mount.metricsRevision
|
|
220
|
+
}));
|
|
221
|
+
}
|
|
222
|
+
async getLayoutPage(request) {
|
|
223
|
+
const session = this._getSession(request.unitId);
|
|
224
|
+
const mount = this._getLayoutMount(session, request);
|
|
225
|
+
return {
|
|
226
|
+
...request,
|
|
227
|
+
modelRevision: session.modelRevision,
|
|
228
|
+
metricsRevision: mount.metricsRevision,
|
|
229
|
+
page: mount.layoutSession.getPage(request.pageIndex)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async cancelLayout(request) {
|
|
233
|
+
var _this$_sessions$get;
|
|
234
|
+
const mount = (_this$_sessions$get = this._sessions.get(request.unitId)) === null || _this$_sessions$get === void 0 ? void 0 : _this$_sessions$get.layoutSessions.get(request.mountId);
|
|
235
|
+
if ((mount === null || mount === void 0 ? void 0 : mount.mountEpoch) === request.mountEpoch && mount.viewportEpoch === request.viewportEpoch) {
|
|
236
|
+
if (request.generation == null || request.generation === mount.activeGeneration) mount.cancelledGeneration = request.generation ?? mount.activeGeneration;
|
|
237
|
+
mount.layoutSession.cancel(request.generation);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async getPerformanceMetrics(unitId) {
|
|
241
|
+
return this._performanceTracker.getMetrics(unitId);
|
|
242
|
+
}
|
|
243
|
+
async resetPerformanceMetrics(unitId) {
|
|
244
|
+
this._performanceTracker.reset(unitId);
|
|
245
|
+
}
|
|
246
|
+
async disposeLayoutMount(request) {
|
|
247
|
+
const session = this._sessions.get(request.unitId);
|
|
248
|
+
const mount = session === null || session === void 0 ? void 0 : session.layoutSessions.get(request.mountId);
|
|
249
|
+
if (session == null || mount == null || mount.mountEpoch !== request.mountEpoch || mount.viewportEpoch !== request.viewportEpoch) return;
|
|
250
|
+
session.layoutSessions.delete(request.mountId);
|
|
251
|
+
mount.activeGeneration = null;
|
|
252
|
+
mount.layoutSession.dispose();
|
|
253
|
+
}
|
|
254
|
+
async disposeSession(request) {
|
|
255
|
+
const session = this._sessions.get(request.unitId);
|
|
256
|
+
if ((session === null || session === void 0 ? void 0 : session.sessionEpoch) !== request.sessionEpoch) return;
|
|
257
|
+
this._disposeSession(request.unitId);
|
|
258
|
+
this._performanceTracker.reset(request.unitId);
|
|
259
|
+
}
|
|
260
|
+
dispose() {
|
|
261
|
+
this._fontLoader.dispose();
|
|
262
|
+
for (const unitId of this._sessions.keys()) this._disposeSession(unitId);
|
|
263
|
+
this._performanceTracker.resetAll();
|
|
264
|
+
}
|
|
265
|
+
_getSession(unitId) {
|
|
266
|
+
const session = this._sessions.get(unitId);
|
|
267
|
+
if (session == null) throw new Error(`Document layout Worker session not found for unit "${unitId}".`);
|
|
268
|
+
return session;
|
|
269
|
+
}
|
|
270
|
+
_getLayoutMount(session, request) {
|
|
271
|
+
const mount = session.layoutSessions.get(request.mountId);
|
|
272
|
+
if (mount == null) throw new Error(`Document layout Worker mount not found: "${request.mountId}".`);
|
|
273
|
+
if (mount.mountEpoch !== request.mountEpoch || mount.viewportEpoch !== request.viewportEpoch) throw new Error(`Document layout Worker rejected a stale mount publication: "${request.mountId}".`);
|
|
274
|
+
return mount;
|
|
275
|
+
}
|
|
276
|
+
async _runLayoutStep(session, mount, generation, budgetMs) {
|
|
277
|
+
const result = this._runWithCustomBlockViewports(session, mount, () => ({
|
|
278
|
+
...mount.layoutSession.step(generation, budgetMs, WORKER_LAYOUT_INTERRUPT_INTERVAL),
|
|
279
|
+
unitId: session.dataModel.getUnitId(),
|
|
280
|
+
mountId: mount.mountId,
|
|
281
|
+
mountEpoch: mount.mountEpoch,
|
|
282
|
+
viewportEpoch: mount.viewportEpoch,
|
|
283
|
+
modelRevision: session.modelRevision,
|
|
284
|
+
metricsRevision: mount.metricsRevision
|
|
285
|
+
}));
|
|
286
|
+
await yieldForWorkerMessage();
|
|
287
|
+
if (mount.activeGeneration === generation && mount.cancelledGeneration !== generation) return result;
|
|
288
|
+
return this._runWithCustomBlockViewports(session, mount, () => ({
|
|
289
|
+
...mount.layoutSession.step(generation, 0, 1),
|
|
290
|
+
unitId: session.dataModel.getUnitId(),
|
|
291
|
+
mountId: mount.mountId,
|
|
292
|
+
mountEpoch: mount.mountEpoch,
|
|
293
|
+
viewportEpoch: mount.viewportEpoch,
|
|
294
|
+
modelRevision: session.modelRevision,
|
|
295
|
+
metricsRevision: mount.metricsRevision
|
|
296
|
+
}));
|
|
297
|
+
}
|
|
298
|
+
_runWithCustomBlockViewports(session, mount, run) {
|
|
299
|
+
const unregister = setDocsCustomBlockRenderViewportProvider((unitId, blockId) => unitId === session.dataModel.getUnitId() ? mount.customBlockViewports[blockId] : null);
|
|
300
|
+
try {
|
|
301
|
+
return run();
|
|
302
|
+
} finally {
|
|
303
|
+
unregister();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
_disposeSession(unitId) {
|
|
307
|
+
const session = this._sessions.get(unitId);
|
|
308
|
+
if (session == null) return;
|
|
309
|
+
this._sessions.delete(unitId);
|
|
310
|
+
for (const mount of session.layoutSessions.values()) {
|
|
311
|
+
mount.activeGeneration = null;
|
|
312
|
+
mount.layoutSession.dispose();
|
|
313
|
+
}
|
|
314
|
+
session.layoutSessions.clear();
|
|
315
|
+
session.dataModel.dispose();
|
|
316
|
+
session.localeService.dispose();
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
var DocsLayoutWorkerChannelService = class extends ChannelService {
|
|
320
|
+
constructor(protocol, _runtime) {
|
|
321
|
+
super(protocol);
|
|
322
|
+
this._runtime = _runtime;
|
|
323
|
+
}
|
|
324
|
+
dispose() {
|
|
325
|
+
this._runtime.dispose();
|
|
326
|
+
super.dispose();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
function startDocsLayoutWorker() {
|
|
330
|
+
const performanceTracker = new DocsLayoutWorkerPerformanceTracker();
|
|
331
|
+
const runtime = new DocsLayoutWorkerRuntime(performanceTracker);
|
|
332
|
+
const channelService = new DocsLayoutWorkerChannelService(createDocsLayoutWorkerMessageProtocol(performanceTracker), runtime);
|
|
333
|
+
channelService.registerChannel(DOCS_LAYOUT_WORKER_CHANNEL, fromModule(runtime));
|
|
334
|
+
return channelService;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/worker.ts
|
|
338
|
+
/**
|
|
339
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
340
|
+
*
|
|
341
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
342
|
+
* you may not use this file except in compliance with the License.
|
|
343
|
+
* You may obtain a copy of the License at
|
|
344
|
+
*
|
|
345
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
346
|
+
*
|
|
347
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
348
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
349
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
350
|
+
* See the License for the specific language governing permissions and
|
|
351
|
+
* limitations under the License.
|
|
352
|
+
*/
|
|
353
|
+
let UniverDocsWorkerPlugin = class UniverDocsWorkerPlugin extends Plugin {
|
|
354
|
+
constructor(_config = defaultPluginWorkerConfig, _injector, _configService) {
|
|
355
|
+
super();
|
|
356
|
+
this._config = _config;
|
|
357
|
+
this._injector = _injector;
|
|
358
|
+
this._configService = _configService;
|
|
359
|
+
const { ...rest } = merge({}, defaultPluginWorkerConfig, this._config);
|
|
360
|
+
this._configService.setConfig(DOCS_WORKER_PLUGIN_CONFIG_KEY, rest);
|
|
361
|
+
}
|
|
362
|
+
onStarting() {
|
|
363
|
+
this.disposeWithMe(startDocsLayoutWorker());
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
_defineProperty(UniverDocsWorkerPlugin, "pluginName", "UNIVER_DOCS_WORKER_PLUGIN");
|
|
367
|
+
_defineProperty(UniverDocsWorkerPlugin, "packageName", name);
|
|
368
|
+
_defineProperty(UniverDocsWorkerPlugin, "version", version);
|
|
369
|
+
UniverDocsWorkerPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverDocsWorkerPlugin);
|
|
370
|
+
|
|
371
|
+
export { UniverDocsWorkerPlugin };
|
package/lib/facade.js
CHANGED
|
@@ -3,7 +3,7 @@ import { FBaseInitialable, FEnum, FUniver } from "@univerjs/core/facade";
|
|
|
3
3
|
import { CreateHeaderFooterCommand, DeleteDocumentSectionBreakCommand, HeaderFooterType, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentNameCommand, SetDocumentPermissionCommand, SetDocumentPermissionsCommand, SetSectionHeaderFooterLinkCommand, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, canEditDocumentTargets, createSectionColumnProperties, generateParagraphs, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentParagraphParentPermissionObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks } from "@univerjs/docs";
|
|
4
4
|
import { UnitAction } from "@univerjs/protocol";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// src/facade/f-document-permission.ts
|
|
7
7
|
/**
|
|
8
8
|
* Command-backed permissions for one Document unit.
|
|
9
9
|
* @hideconstructor
|
|
@@ -213,8 +213,7 @@ var FDocumentObjectPermission = class {
|
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
//#region src/facade/utils.ts
|
|
216
|
+
// src/facade/utils.ts
|
|
218
217
|
function cloneParagraphStyle(paragraphStyle) {
|
|
219
218
|
return paragraphStyle == null ? paragraphStyle : JSON.parse(JSON.stringify(paragraphStyle));
|
|
220
219
|
}
|
|
@@ -302,16 +301,14 @@ function stripBlockTokens(text) {
|
|
|
302
301
|
return Array.from(text).map((char) => char === DataStreamTreeTokenType.PARAGRAPH ? "\n" : char).filter((char) => char !== DataStreamTreeTokenType.BLOCK_START && char !== DataStreamTreeTokenType.BLOCK_END && char !== DataStreamTreeTokenType.SECTION_BREAK).join("").replace(/\n$/, "");
|
|
303
302
|
}
|
|
304
303
|
|
|
305
|
-
|
|
306
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
304
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
307
305
|
function __decorateParam(paramIndex, decorator) {
|
|
308
306
|
return function(target, key) {
|
|
309
307
|
decorator(target, key, paramIndex);
|
|
310
308
|
};
|
|
311
309
|
}
|
|
312
310
|
|
|
313
|
-
|
|
314
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
311
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
315
312
|
function __decorate(decorators, target, key, desc) {
|
|
316
313
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
317
314
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -319,8 +316,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
319
316
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
320
317
|
}
|
|
321
318
|
|
|
322
|
-
|
|
323
|
-
//#region src/facade/f-document-text-range.ts
|
|
319
|
+
// src/facade/f-document-text-range.ts
|
|
324
320
|
let FDocumentTextRange = class FDocumentTextRange extends FBaseInitialable {
|
|
325
321
|
constructor(_document, _startOffset, _endOffset, _segmentId, _injector, _commandService) {
|
|
326
322
|
super(_injector);
|
|
@@ -484,8 +480,7 @@ function isDeepEqual(left, right) {
|
|
|
484
480
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
485
481
|
}
|
|
486
482
|
|
|
487
|
-
|
|
488
|
-
//#region src/facade/f-document-paragraph.ts
|
|
483
|
+
// src/facade/f-document-paragraph.ts
|
|
489
484
|
let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
|
|
490
485
|
constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService, _permissionService) {
|
|
491
486
|
super(_injector);
|
|
@@ -870,8 +865,7 @@ function isParagraphFacade(value) {
|
|
|
870
865
|
return typeof value.getId === "function" && typeof value.getSegmentId === "function" && typeof value.getInfo === "function" && typeof value.getRange === "function";
|
|
871
866
|
}
|
|
872
867
|
|
|
873
|
-
|
|
874
|
-
//#region src/facade/f-document-section.ts
|
|
868
|
+
// src/facade/f-document-section.ts
|
|
875
869
|
function validatePageSetup(pageSetup) {
|
|
876
870
|
const { pageNumberStart, pageSize, pageOrient, marginTop, marginBottom, marginLeft, marginRight } = pageSetup;
|
|
877
871
|
if (pageNumberStart != null && (!Number.isInteger(pageNumberStart) || pageNumberStart < 1)) throw new RangeError("Section page number start must be a positive integer.");
|
|
@@ -1452,8 +1446,7 @@ let FDocumentSection = class FDocumentSection {
|
|
|
1452
1446
|
};
|
|
1453
1447
|
FDocumentSection = __decorate([__decorateParam(2, ICommandService), __decorateParam(3, IPermissionService)], FDocumentSection);
|
|
1454
1448
|
|
|
1455
|
-
|
|
1456
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
1449
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
1457
1450
|
function _typeof(o) {
|
|
1458
1451
|
"@babel/helpers - typeof";
|
|
1459
1452
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -1463,28 +1456,25 @@ function _typeof(o) {
|
|
|
1463
1456
|
}, _typeof(o);
|
|
1464
1457
|
}
|
|
1465
1458
|
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
function toPrimitive(t, r) {
|
|
1459
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
1460
|
+
function toPrimitive(t, e) {
|
|
1469
1461
|
if ("object" != _typeof(t) || !t) return t;
|
|
1470
|
-
var
|
|
1471
|
-
if (void 0 !==
|
|
1472
|
-
var i =
|
|
1462
|
+
var r;
|
|
1463
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
1464
|
+
var i = r.call(t, e || "default");
|
|
1473
1465
|
if ("object" != _typeof(i)) return i;
|
|
1474
1466
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1475
1467
|
}
|
|
1476
|
-
return ("string" ===
|
|
1468
|
+
return ("string" === e ? String : Number)(t);
|
|
1477
1469
|
}
|
|
1478
1470
|
|
|
1479
|
-
|
|
1480
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
1471
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
1481
1472
|
function toPropertyKey(t) {
|
|
1482
1473
|
var i = toPrimitive(t, "string");
|
|
1483
1474
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
1484
1475
|
}
|
|
1485
1476
|
|
|
1486
|
-
|
|
1487
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
1477
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
1488
1478
|
function _defineProperty(e, r, t) {
|
|
1489
1479
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1490
1480
|
value: t,
|
|
@@ -1494,8 +1484,7 @@ function _defineProperty(e, r, t) {
|
|
|
1494
1484
|
}) : e[r] = t, e;
|
|
1495
1485
|
}
|
|
1496
1486
|
|
|
1497
|
-
|
|
1498
|
-
//#region src/facade/f-document.ts
|
|
1487
|
+
// src/facade/f-document.ts
|
|
1499
1488
|
let FDocument = class FDocument extends FBaseInitialable {
|
|
1500
1489
|
constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService, _permissionService) {
|
|
1501
1490
|
super(_injector);
|
|
@@ -2264,8 +2253,7 @@ FDocument = __decorate([
|
|
|
2264
2253
|
__decorateParam(5, IPermissionService)
|
|
2265
2254
|
], FDocument);
|
|
2266
2255
|
|
|
2267
|
-
|
|
2268
|
-
//#region src/facade/f-univer.ts
|
|
2256
|
+
// src/facade/f-univer.ts
|
|
2269
2257
|
var FUniverDocsMixin = class extends FUniver {
|
|
2270
2258
|
createDocument(data, options) {
|
|
2271
2259
|
const document = this._injector.get(IUniverInstanceService).createUnit(UniverInstanceType.UNIVER_DOC, data, options);
|
|
@@ -2284,8 +2272,7 @@ var FUniverDocsMixin = class extends FUniver {
|
|
|
2284
2272
|
};
|
|
2285
2273
|
FUniver.extend(FUniverDocsMixin);
|
|
2286
2274
|
|
|
2287
|
-
|
|
2288
|
-
//#region src/facade/f-enum.ts
|
|
2275
|
+
// src/facade/f-enum.ts
|
|
2289
2276
|
/**
|
|
2290
2277
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2291
2278
|
*
|
|
@@ -2314,5 +2301,4 @@ var FDocsEnumMixin = class extends FEnum {
|
|
|
2314
2301
|
};
|
|
2315
2302
|
FEnum.extend(FDocsEnumMixin);
|
|
2316
2303
|
|
|
2317
|
-
//#endregion
|
|
2318
2304
|
export { DocsSectionUnsupportedDocumentFlavorError, FDocsEnumMixin, FDocument, FDocumentObjectPermission, FDocumentParagraph, FDocumentPermission, FDocumentSection, FDocumentTextRange, isParagraphFacade, stripBlockTokens };
|