@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/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
## Package Overview
|
|
10
10
|
|
|
11
|
-
| Package | UMD global | CSS | Locales | Facade entry |
|
|
12
|
-
| --- | --- | :---: | :---: | :---: |
|
|
13
|
-
| `@univerjs/docs` | `UniverDocs` | No | No | Yes |
|
|
11
|
+
| Package | UMD global | CSS | Locales | Facade entry | Worker entry |
|
|
12
|
+
| --- | --- | :---: | :---: | :---: | :---: |
|
|
13
|
+
| `@univerjs/docs` | `UniverDocs` | No | No | Yes | Yes |
|
|
14
14
|
|
|
15
15
|
## Installation
|
|
16
16
|
|
|
@@ -20,65 +20,31 @@ pnpm add @univerjs/docs
|
|
|
20
20
|
npm install @univerjs/docs
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Keep all `@univerjs/*` packages on the same version.
|
|
24
|
-
|
|
25
23
|
## Usage
|
|
26
24
|
|
|
25
|
+
Start with the [integration setup](https://docs.univer.ai/) for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.
|
|
26
|
+
|
|
27
27
|
```ts
|
|
28
28
|
import { UniverDocsPlugin } from '@univerjs/docs';
|
|
29
29
|
|
|
30
30
|
univer.registerPlugin(UniverDocsPlugin);
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Modern documents (`DocumentFlavor.MODERN`) support collapsing Heading 1 through Heading 5.
|
|
36
|
-
The heading stays visible; its section extends to the next heading of the same or a higher
|
|
37
|
-
level, or the end of its content flow. Each table cell and Modern column has its own heading
|
|
38
|
-
hierarchy. Expanding a parent preserves the collapse flags of its nested headings.
|
|
39
|
-
Traditional documents ignore these flags.
|
|
33
|
+
### Worker usage
|
|
40
34
|
|
|
41
|
-
`
|
|
42
|
-
collapses a heading; `false` or an omitted flag leaves it expanded. Collapsing changes layout
|
|
43
|
-
visibility without deleting the section's text, tables, images, or other snapshot content.
|
|
44
|
-
Saving and reopening a Univer snapshot retains the flag. This contract does not establish
|
|
45
|
-
preservation through Office import or export.
|
|
35
|
+
On the main thread, import `UniverDocsLayoutWorkerPlugin` from `@univerjs/docs`. Register it alongside `UniverDocsPlugin` and set `workerFactory` to a function that creates the layout worker.
|
|
46
36
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
`UniverDocsPlugin` registers `SetHeadingCollapsedCommand` (`doc.command.set-heading-collapsed`).
|
|
50
|
-
After registering the plugin and creating the document, execute the registered command through
|
|
51
|
-
the Facade API or `ICommandService`; do not call its handler or mutate the model directly.
|
|
52
|
-
For an existing `univerAPI` instance:
|
|
37
|
+
In the worker entry, import `UniverDocsWorkerPlugin` from `@univerjs/docs/worker`:
|
|
53
38
|
|
|
54
39
|
```ts
|
|
55
|
-
import {
|
|
40
|
+
import { UniverDocsWorkerPlugin } from '@univerjs/docs/worker';
|
|
56
41
|
|
|
57
|
-
|
|
58
|
-
unitId: documentId,
|
|
59
|
-
paragraphId: headingParagraphId,
|
|
60
|
-
collapsed: true,
|
|
61
|
-
});
|
|
42
|
+
univer.registerPlugin(UniverDocsWorkerPlugin);
|
|
62
43
|
```
|
|
63
44
|
|
|
64
|
-
|
|
65
|
-
Use `collapsed: false` to expand. The command returns `false` for a no-op or an invalid target,
|
|
66
|
-
including Traditional or disabled documents, headings hidden by an ancestor, empty sections
|
|
67
|
-
when collapsing, and targets without edit permission.
|
|
68
|
-
|
|
69
|
-
Concurrent paragraph formatting preserves inherited style references and imported numbering metadata;
|
|
70
|
-
a full replacement can still explicitly clear those fields.
|
|
71
|
-
|
|
72
|
-
Collapse state is shared document state, not a personal view preference. The command uses the
|
|
73
|
-
rich-text mutation path for undo/redo and collaboration. Undoing a fold preserves later peer
|
|
74
|
-
character formatting and enclosing field or content-control properties that the fold did not edit.
|
|
75
|
-
A selection hidden by a collapse moves to the visible heading. Worker layout uses the same flags
|
|
76
|
-
after edits, undo/redo, and snapshot recovery; visibility changes rebuild the affected layout and retain the published viewport until
|
|
77
|
-
replacement content is ready. Hidden tables and images are omitted from layout publications,
|
|
78
|
-
while their source data remains in the snapshot. Rejected edits with empty operations do not
|
|
79
|
-
advance the Worker mutation queue or force the next real edit to resnapshot the document.
|
|
45
|
+
## Integration Notes
|
|
80
46
|
|
|
81
|
-
|
|
47
|
+
- Import `@univerjs/docs/facade` when using this package through Univer Facade APIs.
|
|
82
48
|
|
|
83
49
|
## Resources
|
|
84
50
|
|
package/lib/cjs/facade.js
CHANGED
|
@@ -4,7 +4,7 @@ let _univerjs_core_facade = require("@univerjs/core/facade");
|
|
|
4
4
|
let _univerjs_docs = require("@univerjs/docs");
|
|
5
5
|
let _univerjs_protocol = require("@univerjs/protocol");
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/facade/f-document-permission.ts
|
|
8
8
|
/**
|
|
9
9
|
* Command-backed permissions for one Document unit.
|
|
10
10
|
* @hideconstructor
|
|
@@ -214,8 +214,7 @@ var FDocumentObjectPermission = class {
|
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
//#region src/facade/utils.ts
|
|
217
|
+
// src/facade/utils.ts
|
|
219
218
|
function cloneParagraphStyle(paragraphStyle) {
|
|
220
219
|
return paragraphStyle == null ? paragraphStyle : JSON.parse(JSON.stringify(paragraphStyle));
|
|
221
220
|
}
|
|
@@ -303,16 +302,14 @@ function stripBlockTokens(text) {
|
|
|
303
302
|
return Array.from(text).map((char) => char === _univerjs_core.DataStreamTreeTokenType.PARAGRAPH ? "\n" : char).filter((char) => char !== _univerjs_core.DataStreamTreeTokenType.BLOCK_START && char !== _univerjs_core.DataStreamTreeTokenType.BLOCK_END && char !== _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK).join("").replace(/\n$/, "");
|
|
304
303
|
}
|
|
305
304
|
|
|
306
|
-
|
|
307
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
305
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorateParam.js
|
|
308
306
|
function __decorateParam(paramIndex, decorator) {
|
|
309
307
|
return function(target, key) {
|
|
310
308
|
decorator(target, key, paramIndex);
|
|
311
309
|
};
|
|
312
310
|
}
|
|
313
311
|
|
|
314
|
-
|
|
315
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
312
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/decorate.js
|
|
316
313
|
function __decorate(decorators, target, key, desc) {
|
|
317
314
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
318
315
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -320,8 +317,7 @@ function __decorate(decorators, target, key, desc) {
|
|
|
320
317
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
321
318
|
}
|
|
322
319
|
|
|
323
|
-
|
|
324
|
-
//#region src/facade/f-document-text-range.ts
|
|
320
|
+
// src/facade/f-document-text-range.ts
|
|
325
321
|
let FDocumentTextRange = class FDocumentTextRange extends _univerjs_core_facade.FBaseInitialable {
|
|
326
322
|
constructor(_document, _startOffset, _endOffset, _segmentId, _injector, _commandService) {
|
|
327
323
|
super(_injector);
|
|
@@ -485,8 +481,7 @@ function isDeepEqual(left, right) {
|
|
|
485
481
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
486
482
|
}
|
|
487
483
|
|
|
488
|
-
|
|
489
|
-
//#region src/facade/f-document-paragraph.ts
|
|
484
|
+
// src/facade/f-document-paragraph.ts
|
|
490
485
|
let FDocumentParagraph = class FDocumentParagraph extends _univerjs_core_facade.FBaseInitialable {
|
|
491
486
|
constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService, _permissionService) {
|
|
492
487
|
super(_injector);
|
|
@@ -871,8 +866,7 @@ function isParagraphFacade(value) {
|
|
|
871
866
|
return typeof value.getId === "function" && typeof value.getSegmentId === "function" && typeof value.getInfo === "function" && typeof value.getRange === "function";
|
|
872
867
|
}
|
|
873
868
|
|
|
874
|
-
|
|
875
|
-
//#region src/facade/f-document-section.ts
|
|
869
|
+
// src/facade/f-document-section.ts
|
|
876
870
|
function validatePageSetup(pageSetup) {
|
|
877
871
|
const { pageNumberStart, pageSize, pageOrient, marginTop, marginBottom, marginLeft, marginRight } = pageSetup;
|
|
878
872
|
if (pageNumberStart != null && (!Number.isInteger(pageNumberStart) || pageNumberStart < 1)) throw new RangeError("Section page number start must be a positive integer.");
|
|
@@ -1453,8 +1447,7 @@ let FDocumentSection = class FDocumentSection {
|
|
|
1453
1447
|
};
|
|
1454
1448
|
FDocumentSection = __decorate([__decorateParam(2, _univerjs_core.ICommandService), __decorateParam(3, _univerjs_core.IPermissionService)], FDocumentSection);
|
|
1455
1449
|
|
|
1456
|
-
|
|
1457
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
1450
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/typeof.js
|
|
1458
1451
|
function _typeof(o) {
|
|
1459
1452
|
"@babel/helpers - typeof";
|
|
1460
1453
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -1464,28 +1457,25 @@ function _typeof(o) {
|
|
|
1464
1457
|
}, _typeof(o);
|
|
1465
1458
|
}
|
|
1466
1459
|
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
function toPrimitive(t, r) {
|
|
1460
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPrimitive.js
|
|
1461
|
+
function toPrimitive(t, e) {
|
|
1470
1462
|
if ("object" != _typeof(t) || !t) return t;
|
|
1471
|
-
var
|
|
1472
|
-
if (void 0 !==
|
|
1473
|
-
var i =
|
|
1463
|
+
var r;
|
|
1464
|
+
if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
|
|
1465
|
+
var i = r.call(t, e || "default");
|
|
1474
1466
|
if ("object" != _typeof(i)) return i;
|
|
1475
1467
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1476
1468
|
}
|
|
1477
|
-
return ("string" ===
|
|
1469
|
+
return ("string" === e ? String : Number)(t);
|
|
1478
1470
|
}
|
|
1479
1471
|
|
|
1480
|
-
|
|
1481
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
1472
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/toPropertyKey.js
|
|
1482
1473
|
function toPropertyKey(t) {
|
|
1483
1474
|
var i = toPrimitive(t, "string");
|
|
1484
1475
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
1485
1476
|
}
|
|
1486
1477
|
|
|
1487
|
-
|
|
1488
|
-
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
1478
|
+
// \0@oxc-project+runtime@0.157.0/helpers/esm/defineProperty.js
|
|
1489
1479
|
function _defineProperty(e, r, t) {
|
|
1490
1480
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1491
1481
|
value: t,
|
|
@@ -1495,8 +1485,7 @@ function _defineProperty(e, r, t) {
|
|
|
1495
1485
|
}) : e[r] = t, e;
|
|
1496
1486
|
}
|
|
1497
1487
|
|
|
1498
|
-
|
|
1499
|
-
//#region src/facade/f-document.ts
|
|
1488
|
+
// src/facade/f-document.ts
|
|
1500
1489
|
let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
1501
1490
|
constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService, _permissionService) {
|
|
1502
1491
|
super(_injector);
|
|
@@ -2265,8 +2254,7 @@ FDocument = __decorate([
|
|
|
2265
2254
|
__decorateParam(5, _univerjs_core.IPermissionService)
|
|
2266
2255
|
], FDocument);
|
|
2267
2256
|
|
|
2268
|
-
|
|
2269
|
-
//#region src/facade/f-univer.ts
|
|
2257
|
+
// src/facade/f-univer.ts
|
|
2270
2258
|
var FUniverDocsMixin = class extends _univerjs_core_facade.FUniver {
|
|
2271
2259
|
createDocument(data, options) {
|
|
2272
2260
|
const document = this._injector.get(_univerjs_core.IUniverInstanceService).createUnit(_univerjs_core.UniverInstanceType.UNIVER_DOC, data, options);
|
|
@@ -2285,8 +2273,7 @@ var FUniverDocsMixin = class extends _univerjs_core_facade.FUniver {
|
|
|
2285
2273
|
};
|
|
2286
2274
|
_univerjs_core_facade.FUniver.extend(FUniverDocsMixin);
|
|
2287
2275
|
|
|
2288
|
-
|
|
2289
|
-
//#region src/facade/f-enum.ts
|
|
2276
|
+
// src/facade/f-enum.ts
|
|
2290
2277
|
/**
|
|
2291
2278
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2292
2279
|
*
|
|
@@ -2315,7 +2302,6 @@ var FDocsEnumMixin = class extends _univerjs_core_facade.FEnum {
|
|
|
2315
2302
|
};
|
|
2316
2303
|
_univerjs_core_facade.FEnum.extend(FDocsEnumMixin);
|
|
2317
2304
|
|
|
2318
|
-
//#endregion
|
|
2319
2305
|
exports.DocsSectionUnsupportedDocumentFlavorError = DocsSectionUnsupportedDocumentFlavorError;
|
|
2320
2306
|
exports.FDocsEnumMixin = FDocsEnumMixin;
|
|
2321
2307
|
Object.defineProperty(exports, "FDocument", {
|