@univerjs/docs 0.24.0 → 0.25.0-insiders.20260604-29ebbff
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 +1 -1
- package/lib/cjs/facade.js +305 -0
- package/lib/cjs/index.js +207 -29
- package/lib/es/facade.js +299 -0
- package/lib/es/index.js +202 -28
- package/lib/facade.js +299 -0
- package/lib/index.js +202 -28
- package/lib/types/commands/commands/core-editing.command.d.ts +57 -0
- package/lib/types/facade/f-document.d.ts +178 -0
- package/lib/types/facade/f-univer.d.ts +64 -0
- package/lib/types/facade/index.d.ts +18 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/services/doc-content-insert.service.d.ts +28 -0
- package/lib/types/utils/custom-range-factory.d.ts +1 -5
- package/lib/umd/facade.js +5 -0
- package/lib/umd/index.js +1 -1
- package/package.json +15 -5
- package/LICENSE +0 -176
package/README.md
CHANGED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_core_facade = require("@univerjs/core/facade");
|
|
4
|
+
let _univerjs_docs = require("@univerjs/docs");
|
|
5
|
+
|
|
6
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
7
|
+
function _typeof(o) {
|
|
8
|
+
"@babel/helpers - typeof";
|
|
9
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
10
|
+
return typeof o;
|
|
11
|
+
} : function(o) {
|
|
12
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
13
|
+
}, _typeof(o);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
18
|
+
function toPrimitive(t, r) {
|
|
19
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
20
|
+
var e = t[Symbol.toPrimitive];
|
|
21
|
+
if (void 0 !== e) {
|
|
22
|
+
var i = e.call(t, r || "default");
|
|
23
|
+
if ("object" != _typeof(i)) return i;
|
|
24
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
25
|
+
}
|
|
26
|
+
return ("string" === r ? String : Number)(t);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
31
|
+
function toPropertyKey(t) {
|
|
32
|
+
var i = toPrimitive(t, "string");
|
|
33
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
38
|
+
function _defineProperty(e, r, t) {
|
|
39
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
40
|
+
value: t,
|
|
41
|
+
enumerable: !0,
|
|
42
|
+
configurable: !0,
|
|
43
|
+
writable: !0
|
|
44
|
+
}) : e[r] = t, e;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
49
|
+
function __decorateParam(paramIndex, decorator) {
|
|
50
|
+
return function(target, key) {
|
|
51
|
+
decorator(target, key, paramIndex);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
|
|
57
|
+
function __decorate(decorators, target, key, desc) {
|
|
58
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
59
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
60
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
61
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/facade/f-document.ts
|
|
66
|
+
let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
67
|
+
constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService) {
|
|
68
|
+
super(_injector);
|
|
69
|
+
this._documentDataModel = _documentDataModel;
|
|
70
|
+
this._injector = _injector;
|
|
71
|
+
this._univerInstanceService = _univerInstanceService;
|
|
72
|
+
this._resourceLoaderService = _resourceLoaderService;
|
|
73
|
+
this._commandService = _commandService;
|
|
74
|
+
_defineProperty(this, "id", void 0);
|
|
75
|
+
this.id = this._documentDataModel.getUnitId();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get the document data model of the document.
|
|
79
|
+
* @returns {DocumentDataModel} The document data model.
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
83
|
+
* const documentDataModel = fDocument.getDocumentDataModel();
|
|
84
|
+
* console.log(documentDataModel);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
getDocumentDataModel() {
|
|
88
|
+
return this._documentDataModel;
|
|
89
|
+
}
|
|
90
|
+
dispose() {
|
|
91
|
+
super.dispose();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the document id.
|
|
95
|
+
* @returns {string} The document id.
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
99
|
+
* const unitId = fDocument.getId();
|
|
100
|
+
* console.log(unitId);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
getId() {
|
|
104
|
+
return this.id;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the document name.
|
|
108
|
+
* @returns {string} The document name.
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
112
|
+
* const name = fDocument.getName();
|
|
113
|
+
* console.log(name);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
getName() {
|
|
117
|
+
return this._documentDataModel.getTitle() || "";
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Save the document snapshot data, including the document content and resource data, etc.
|
|
121
|
+
* @returns {IDocumentData} The document snapshot data.
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
125
|
+
* const snapshot = fDocument.save();
|
|
126
|
+
* console.log(snapshot);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
save() {
|
|
130
|
+
return this._resourceLoaderService.saveUnit(this._documentDataModel.getUnitId());
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Undo the last operation in the document.
|
|
134
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the undo operation was successful, or false if it failed.
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
138
|
+
* await fDocument.undo();
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
undo() {
|
|
142
|
+
this._univerInstanceService.focusUnit(this.id);
|
|
143
|
+
return this._commandService.executeCommand(_univerjs_core.UndoCommand.id);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Redo the last undone operation in the document.
|
|
147
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the redo operation was successful, or false if it failed.
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
151
|
+
* await fDocument.redo();
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
redo() {
|
|
155
|
+
this._univerInstanceService.focusUnit(this.id);
|
|
156
|
+
return this._commandService.executeCommand(_univerjs_core.RedoCommand.id);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Adds the specified text to the end of this text region.
|
|
160
|
+
* @param {string} text - The text to be added to the end of this text region.
|
|
161
|
+
* @return {Promise<boolean>} A promise that resolves to true if the text was successfully appended, or false if it failed.
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
165
|
+
* await fDocument.appendText('Hello, world!');
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
appendText(text) {
|
|
169
|
+
const { body } = this.save();
|
|
170
|
+
if (!body) throw new Error("The document body is empty");
|
|
171
|
+
const lastPosition = body.dataStream.length - 2;
|
|
172
|
+
return this.insertText(text, {
|
|
173
|
+
startOffset: lastPosition,
|
|
174
|
+
endOffset: lastPosition,
|
|
175
|
+
segmentId: ""
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Inserts text at the provided document range. Defaults to appending before the final section break.
|
|
180
|
+
* @param {string} text - The text to insert.
|
|
181
|
+
* @param {IDocumentInsertTextFacadeOptions} options - Optional target range, segment id, and cursor offset.
|
|
182
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the text was successfully inserted, or false if it failed.
|
|
183
|
+
* @example
|
|
184
|
+
*
|
|
185
|
+
* // Insert text at a specific range in the document body
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
188
|
+
* await fDocument.insertText('Hello, world!', {
|
|
189
|
+
* startOffset: 5,
|
|
190
|
+
* endOffset: 5,
|
|
191
|
+
* segmentId: '',
|
|
192
|
+
* cursorOffset: 13,
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* // Insert text at the beginning of a header or footer segment
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
199
|
+
* const snapshot = fDocument.save();
|
|
200
|
+
* const { headers, footers } = snapshot;
|
|
201
|
+
*
|
|
202
|
+
* if (headers) {
|
|
203
|
+
* for (const headerId in headers) {
|
|
204
|
+
* if (headerId === 'target-header-id') {
|
|
205
|
+
* await fDocument.insertText('Hello, header!', {
|
|
206
|
+
* startOffset: 0,
|
|
207
|
+
* endOffset: 0,
|
|
208
|
+
* segmentId: headerId,
|
|
209
|
+
* });
|
|
210
|
+
* }
|
|
211
|
+
* }
|
|
212
|
+
* }
|
|
213
|
+
*
|
|
214
|
+
* if (footers) {
|
|
215
|
+
* for (const footerId in footers) {
|
|
216
|
+
* if (footerId === 'target-footer-id') {
|
|
217
|
+
* await fDocument.insertText('Hello, footer!', {
|
|
218
|
+
* startOffset: 0,
|
|
219
|
+
* endOffset: 0,
|
|
220
|
+
* segmentId: footerId,
|
|
221
|
+
* });
|
|
222
|
+
* }
|
|
223
|
+
* }
|
|
224
|
+
* }
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
insertText(text, options = {}) {
|
|
228
|
+
var _options$startOffset, _options$endOffset, _options$segmentId;
|
|
229
|
+
const unitId = this.id;
|
|
230
|
+
const { body } = this.save();
|
|
231
|
+
if (!body) throw new Error("The document body is empty");
|
|
232
|
+
const startOffset = (_options$startOffset = options.startOffset) !== null && _options$startOffset !== void 0 ? _options$startOffset : Math.max(0, body.dataStream.length - 2);
|
|
233
|
+
const endOffset = (_options$endOffset = options.endOffset) !== null && _options$endOffset !== void 0 ? _options$endOffset : startOffset;
|
|
234
|
+
const segmentId = (_options$segmentId = options.segmentId) !== null && _options$segmentId !== void 0 ? _options$segmentId : "";
|
|
235
|
+
const activeRange = {
|
|
236
|
+
startOffset,
|
|
237
|
+
endOffset,
|
|
238
|
+
collapsed: startOffset === endOffset,
|
|
239
|
+
segmentId
|
|
240
|
+
};
|
|
241
|
+
return this._commandService.executeCommand(_univerjs_docs.InsertTextCommand.id, {
|
|
242
|
+
unitId,
|
|
243
|
+
body: { dataStream: text },
|
|
244
|
+
range: activeRange,
|
|
245
|
+
segmentId,
|
|
246
|
+
...options.cursorOffset == null ? {} : { cursorOffset: options.cursorOffset }
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Inserts one or more plain-text paragraphs at the provided document range.
|
|
251
|
+
* @param {string} text - The paragraph text to insert. Newlines are normalized to document paragraph separators.
|
|
252
|
+
* @param {IDocumentInsertTextFacadeOptions} options - Optional target range, segment id, and cursor offset.
|
|
253
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the paragraphs were successfully inserted, or false if it failed.
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const fDocument = univerAPI.getActiveDocument();
|
|
257
|
+
* await fDocument.insertParagraph('Hello, world! This is a new paragraph.', {
|
|
258
|
+
* startOffset: 5,
|
|
259
|
+
* endOffset: 5,
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
insertParagraph(text = "", options = {}) {
|
|
264
|
+
var _options$cursorOffset;
|
|
265
|
+
const dataStream = `${text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").join("\r\n")}\r\n`;
|
|
266
|
+
return this.insertText(dataStream, {
|
|
267
|
+
...options,
|
|
268
|
+
cursorOffset: (_options$cursorOffset = options.cursorOffset) !== null && _options$cursorOffset !== void 0 ? _options$cursorOffset : dataStream.length
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
FDocument = __decorate([
|
|
273
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
274
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
275
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.IResourceLoaderService)),
|
|
276
|
+
__decorateParam(4, _univerjs_core.ICommandService)
|
|
277
|
+
], FDocument);
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/facade/f-univer.ts
|
|
281
|
+
var FUniverDocsUIMixin = class extends _univerjs_core_facade.FUniver {
|
|
282
|
+
createDocument(data) {
|
|
283
|
+
const document = this._injector.get(_univerjs_core.IUniverInstanceService).createUnit(_univerjs_core.UniverInstanceType.UNIVER_DOC, data);
|
|
284
|
+
return this._injector.createInstance(FDocument, document);
|
|
285
|
+
}
|
|
286
|
+
getActiveDocument() {
|
|
287
|
+
const document = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
288
|
+
if (!document) return null;
|
|
289
|
+
return this._injector.createInstance(FDocument, document);
|
|
290
|
+
}
|
|
291
|
+
getDocument(id) {
|
|
292
|
+
const document = this._univerInstanceService.getUnit(id, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
293
|
+
if (!document) return null;
|
|
294
|
+
return this._injector.createInstance(FDocument, document);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
_univerjs_core_facade.FUniver.extend(FUniverDocsUIMixin);
|
|
298
|
+
|
|
299
|
+
//#endregion
|
|
300
|
+
Object.defineProperty(exports, 'FDocument', {
|
|
301
|
+
enumerable: true,
|
|
302
|
+
get: function () {
|
|
303
|
+
return FDocument;
|
|
304
|
+
}
|
|
305
|
+
});
|
package/lib/cjs/index.js
CHANGED
|
@@ -13,7 +13,7 @@ const SetTextSelectionsOperation = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
//#endregion
|
|
16
|
-
//#region \0@oxc-project+runtime@0.
|
|
16
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
17
17
|
function _typeof(o) {
|
|
18
18
|
"@babel/helpers - typeof";
|
|
19
19
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -24,7 +24,7 @@ function _typeof(o) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
//#endregion
|
|
27
|
-
//#region \0@oxc-project+runtime@0.
|
|
27
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
28
28
|
function toPrimitive(t, r) {
|
|
29
29
|
if ("object" != _typeof(t) || !t) return t;
|
|
30
30
|
var e = t[Symbol.toPrimitive];
|
|
@@ -37,14 +37,14 @@ function toPrimitive(t, r) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
40
|
-
//#region \0@oxc-project+runtime@0.
|
|
40
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
41
41
|
function toPropertyKey(t) {
|
|
42
42
|
var i = toPrimitive(t, "string");
|
|
43
43
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
//#endregion
|
|
47
|
-
//#region \0@oxc-project+runtime@0.
|
|
47
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
48
48
|
function _defineProperty(e, r, t) {
|
|
49
49
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
50
50
|
value: t,
|
|
@@ -55,7 +55,7 @@ function _defineProperty(e, r, t) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
//#endregion
|
|
58
|
-
//#region \0@oxc-project+runtime@0.
|
|
58
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
59
59
|
function __decorateParam(paramIndex, decorator) {
|
|
60
60
|
return function(target, key) {
|
|
61
61
|
decorator(target, key, paramIndex);
|
|
@@ -63,7 +63,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
//#endregion
|
|
66
|
-
//#region \0@oxc-project+runtime@0.
|
|
66
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
|
|
67
67
|
function __decorate(decorators, target, key, desc) {
|
|
68
68
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
69
69
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -377,10 +377,162 @@ const RichTextEditingMutation = {
|
|
|
377
377
|
}
|
|
378
378
|
};
|
|
379
379
|
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/commands/commands/core-editing.command.ts
|
|
382
|
+
/**
|
|
383
|
+
* The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
|
|
384
|
+
*/
|
|
385
|
+
const InsertTextCommand = {
|
|
386
|
+
id: "doc.command.insert-text",
|
|
387
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
388
|
+
handler: async (accessor, params) => {
|
|
389
|
+
var _activeRange$segmentI;
|
|
390
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
391
|
+
const { range, segmentId, body, unitId, cursorOffset } = params;
|
|
392
|
+
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
393
|
+
const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
394
|
+
if (docDataModel == null) return false;
|
|
395
|
+
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
396
|
+
const originBody = docDataModel.getSelfOrHeaderFooterModel((_activeRange$segmentI = activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) !== null && _activeRange$segmentI !== void 0 ? _activeRange$segmentI : "").getBody();
|
|
397
|
+
if (originBody == null) return false;
|
|
398
|
+
const { startOffset, collapsed } = range;
|
|
399
|
+
const cursorMove = cursorOffset !== null && cursorOffset !== void 0 ? cursorOffset : body.dataStream.length;
|
|
400
|
+
const textRanges = [{
|
|
401
|
+
startOffset: startOffset + cursorMove,
|
|
402
|
+
endOffset: startOffset + cursorMove,
|
|
403
|
+
style: activeRange === null || activeRange === void 0 ? void 0 : activeRange.style,
|
|
404
|
+
collapsed
|
|
405
|
+
}];
|
|
406
|
+
const doMutation = {
|
|
407
|
+
id: RichTextEditingMutation.id,
|
|
408
|
+
params: {
|
|
409
|
+
unitId,
|
|
410
|
+
actions: [],
|
|
411
|
+
textRanges,
|
|
412
|
+
debounce: true
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const textX = new _univerjs_core.TextX();
|
|
416
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
417
|
+
if (collapsed) {
|
|
418
|
+
if (startOffset > 0) textX.push({
|
|
419
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
420
|
+
len: startOffset
|
|
421
|
+
});
|
|
422
|
+
textX.push({
|
|
423
|
+
t: _univerjs_core.TextXActionType.INSERT,
|
|
424
|
+
body,
|
|
425
|
+
len: body.dataStream.length
|
|
426
|
+
});
|
|
427
|
+
} else {
|
|
428
|
+
const dos = _univerjs_core.BuildTextUtils.selection.delete([range], originBody, 0, body);
|
|
429
|
+
textX.push(...dos);
|
|
430
|
+
}
|
|
431
|
+
doMutation.params.textRanges = [{
|
|
432
|
+
startOffset: startOffset + cursorMove,
|
|
433
|
+
endOffset: startOffset + cursorMove,
|
|
434
|
+
collapsed
|
|
435
|
+
}];
|
|
436
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(docDataModel, segmentId);
|
|
437
|
+
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
438
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
439
|
+
return Boolean(result);
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
/**
|
|
443
|
+
* The command to delete text, mainly used in BACKSPACE and DELETE when collapsed is true. ONLY handle collapsed range!!!
|
|
444
|
+
*/
|
|
445
|
+
const DeleteTextCommand = {
|
|
446
|
+
id: "doc.command.delete-text",
|
|
447
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
448
|
+
handler: async (accessor, params) => {
|
|
449
|
+
var _body$customRanges;
|
|
450
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
451
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
452
|
+
const { range, segmentId, unitId, direction, len = 1 } = params;
|
|
453
|
+
const docDataModel = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
454
|
+
const body = docDataModel === null || docDataModel === void 0 ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
455
|
+
if (docDataModel == null || body == null) return false;
|
|
456
|
+
const { startOffset } = range;
|
|
457
|
+
let start = direction === _univerjs_core.DeleteDirection.LEFT ? startOffset - len : startOffset;
|
|
458
|
+
let end = direction === _univerjs_core.DeleteDirection.LEFT ? startOffset - 1 : startOffset + len - 1;
|
|
459
|
+
const customRange = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((customRange) => customRange.startIndex <= start && customRange.endIndex >= end);
|
|
460
|
+
if (customRange === null || customRange === void 0 ? void 0 : customRange.wholeEntity) {
|
|
461
|
+
start = customRange.startIndex;
|
|
462
|
+
end = Math.max(end, customRange.endIndex);
|
|
463
|
+
}
|
|
464
|
+
const doMutation = {
|
|
465
|
+
id: RichTextEditingMutation.id,
|
|
466
|
+
params: {
|
|
467
|
+
unitId,
|
|
468
|
+
actions: [],
|
|
469
|
+
textRanges: [{
|
|
470
|
+
startOffset: start,
|
|
471
|
+
endOffset: start,
|
|
472
|
+
collapsed: true
|
|
473
|
+
}],
|
|
474
|
+
debounce: true
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
const textX = new _univerjs_core.TextX();
|
|
478
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
479
|
+
textX.push({
|
|
480
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
481
|
+
len: start - 0
|
|
482
|
+
});
|
|
483
|
+
textX.push({
|
|
484
|
+
t: _univerjs_core.TextXActionType.DELETE,
|
|
485
|
+
len: end - start + 1
|
|
486
|
+
});
|
|
487
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(docDataModel, segmentId);
|
|
488
|
+
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
489
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
490
|
+
return Boolean(result);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* The command to update text properties, mainly used in BACKSPACE.
|
|
495
|
+
*/
|
|
496
|
+
const UpdateTextCommand = {
|
|
497
|
+
id: "doc.command.update-text",
|
|
498
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
499
|
+
handler: async (accessor, params) => {
|
|
500
|
+
const { range, segmentId, updateBody, coverType, unitId, textRanges } = params;
|
|
501
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
502
|
+
const docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUniverDocInstance();
|
|
503
|
+
if (docDataModel == null) return false;
|
|
504
|
+
const doMutation = {
|
|
505
|
+
id: RichTextEditingMutation.id,
|
|
506
|
+
params: {
|
|
507
|
+
unitId,
|
|
508
|
+
actions: [],
|
|
509
|
+
textRanges
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
const textX = new _univerjs_core.TextX();
|
|
513
|
+
const jsonX = _univerjs_core.JSONX.getInstance();
|
|
514
|
+
const { startOffset, endOffset } = range;
|
|
515
|
+
textX.push({
|
|
516
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
517
|
+
len: startOffset
|
|
518
|
+
});
|
|
519
|
+
textX.push({
|
|
520
|
+
t: _univerjs_core.TextXActionType.RETAIN,
|
|
521
|
+
body: updateBody,
|
|
522
|
+
len: endOffset - startOffset,
|
|
523
|
+
coverType
|
|
524
|
+
});
|
|
525
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(docDataModel, segmentId);
|
|
526
|
+
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
527
|
+
const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
528
|
+
return Boolean(result);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
380
532
|
//#endregion
|
|
381
533
|
//#region package.json
|
|
382
534
|
var name = "@univerjs/docs";
|
|
383
|
-
var version = "0.
|
|
535
|
+
var version = "0.25.0-insiders.20260604-29ebbff";
|
|
384
536
|
|
|
385
537
|
//#endregion
|
|
386
538
|
//#region src/commands/mutations/docs-rename.mutation.ts
|
|
@@ -469,6 +621,43 @@ DocCustomRangeController = __decorate([
|
|
|
469
621
|
__decorateParam(2, _univerjs_core.IUniverInstanceService)
|
|
470
622
|
], DocCustomRangeController);
|
|
471
623
|
|
|
624
|
+
//#endregion
|
|
625
|
+
//#region src/services/doc-content-insert.service.ts
|
|
626
|
+
/**
|
|
627
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
628
|
+
*
|
|
629
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
630
|
+
* you may not use this file except in compliance with the License.
|
|
631
|
+
* You may obtain a copy of the License at
|
|
632
|
+
*
|
|
633
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
634
|
+
*
|
|
635
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
636
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
637
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
638
|
+
* See the License for the specific language governing permissions and
|
|
639
|
+
* limitations under the License.
|
|
640
|
+
*/
|
|
641
|
+
var DocContentInsertService = class extends _univerjs_core.Disposable {
|
|
642
|
+
constructor(..._args) {
|
|
643
|
+
super(..._args);
|
|
644
|
+
_defineProperty(this, "_range", null);
|
|
645
|
+
}
|
|
646
|
+
setInsertRange(range) {
|
|
647
|
+
this._range = range;
|
|
648
|
+
}
|
|
649
|
+
consumeInsertRange(unitId) {
|
|
650
|
+
if (!this._range) return null;
|
|
651
|
+
if (unitId && this._range.unitId !== unitId) return null;
|
|
652
|
+
const range = this._range;
|
|
653
|
+
this._range = null;
|
|
654
|
+
return range;
|
|
655
|
+
}
|
|
656
|
+
clearInsertRange() {
|
|
657
|
+
this._range = null;
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
|
|
472
661
|
//#endregion
|
|
473
662
|
//#region src/plugin.ts
|
|
474
663
|
let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
@@ -486,6 +675,9 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
|
486
675
|
}
|
|
487
676
|
_initializeCommands() {
|
|
488
677
|
[
|
|
678
|
+
InsertTextCommand,
|
|
679
|
+
DeleteTextCommand,
|
|
680
|
+
UpdateTextCommand,
|
|
489
681
|
RichTextEditingMutation,
|
|
490
682
|
DocsRenameMutation,
|
|
491
683
|
SetTextSelectionsOperation
|
|
@@ -497,6 +689,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
|
|
|
497
689
|
[
|
|
498
690
|
[DocSelectionManagerService],
|
|
499
691
|
[DocStateEmitService],
|
|
692
|
+
[DocContentInsertService],
|
|
500
693
|
[DocCustomRangeController]
|
|
501
694
|
].forEach((d) => this._injector.add(d));
|
|
502
695
|
}
|
|
@@ -588,25 +781,6 @@ DocInterceptorService = __decorate([__decorateParam(1, (0, _univerjs_core.Inject
|
|
|
588
781
|
|
|
589
782
|
//#endregion
|
|
590
783
|
//#region src/utils/custom-range-factory.ts
|
|
591
|
-
/**
|
|
592
|
-
* @deprecated This is a duplication from docs-ui to avoid making too much breaking changes.
|
|
593
|
-
*/
|
|
594
|
-
function getRichTextEditPath(docDataModel, segmentId = "") {
|
|
595
|
-
if (!segmentId) return ["body"];
|
|
596
|
-
const { headers, footers } = docDataModel.getSnapshot();
|
|
597
|
-
if (headers == null && footers == null) throw new Error("Document data model must have headers or footers when update by segment id");
|
|
598
|
-
if ((headers === null || headers === void 0 ? void 0 : headers[segmentId]) != null) return [
|
|
599
|
-
"headers",
|
|
600
|
-
segmentId,
|
|
601
|
-
"body"
|
|
602
|
-
];
|
|
603
|
-
else if ((footers === null || footers === void 0 ? void 0 : footers[segmentId]) != null) return [
|
|
604
|
-
"footers",
|
|
605
|
-
segmentId,
|
|
606
|
-
"body"
|
|
607
|
-
];
|
|
608
|
-
else throw new Error("Segment id not found in headers or footers");
|
|
609
|
-
}
|
|
610
784
|
function addCustomRangeFactory(accessor, param, body) {
|
|
611
785
|
const { unitId, segmentId } = param;
|
|
612
786
|
const documentDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
|
|
@@ -625,7 +799,7 @@ function addCustomRangeFactory(accessor, param, body) {
|
|
|
625
799
|
body
|
|
626
800
|
});
|
|
627
801
|
if (!textX) return false;
|
|
628
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
802
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
629
803
|
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
630
804
|
return doMutation;
|
|
631
805
|
}
|
|
@@ -665,7 +839,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
665
839
|
},
|
|
666
840
|
textX
|
|
667
841
|
};
|
|
668
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
842
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
669
843
|
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
670
844
|
return doMutation;
|
|
671
845
|
}
|
|
@@ -690,7 +864,7 @@ function deleteCustomRangeFactory(accessor, params) {
|
|
|
690
864
|
segmentId
|
|
691
865
|
});
|
|
692
866
|
if (!textX) return false;
|
|
693
|
-
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
867
|
+
const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
|
|
694
868
|
doMutation.params.actions = jsonX.editOp(textX.serialize(), path);
|
|
695
869
|
doMutation.params.textRanges = textX.selections;
|
|
696
870
|
return doMutation;
|
|
@@ -740,6 +914,8 @@ function replaceSelectionFactory(accessor, params) {
|
|
|
740
914
|
|
|
741
915
|
//#endregion
|
|
742
916
|
exports.DOC_INTERCEPTOR_POINT = DOC_INTERCEPTOR_POINT;
|
|
917
|
+
exports.DeleteTextCommand = DeleteTextCommand;
|
|
918
|
+
exports.DocContentInsertService = DocContentInsertService;
|
|
743
919
|
Object.defineProperty(exports, 'DocInterceptorService', {
|
|
744
920
|
enumerable: true,
|
|
745
921
|
get: function () {
|
|
@@ -759,6 +935,7 @@ Object.defineProperty(exports, 'DocSkeletonManagerService', {
|
|
|
759
935
|
}
|
|
760
936
|
});
|
|
761
937
|
exports.DocStateEmitService = DocStateEmitService;
|
|
938
|
+
exports.InsertTextCommand = InsertTextCommand;
|
|
762
939
|
exports.RichTextEditingMutation = RichTextEditingMutation;
|
|
763
940
|
exports.SetTextSelectionsOperation = SetTextSelectionsOperation;
|
|
764
941
|
Object.defineProperty(exports, 'UniverDocsPlugin', {
|
|
@@ -767,6 +944,7 @@ Object.defineProperty(exports, 'UniverDocsPlugin', {
|
|
|
767
944
|
return UniverDocsPlugin;
|
|
768
945
|
}
|
|
769
946
|
});
|
|
947
|
+
exports.UpdateTextCommand = UpdateTextCommand;
|
|
770
948
|
exports.addCustomRangeBySelectionFactory = addCustomRangeBySelectionFactory;
|
|
771
949
|
exports.addCustomRangeFactory = addCustomRangeFactory;
|
|
772
950
|
exports.deleteCustomRangeFactory = deleteCustomRangeFactory;
|