@univerjs/docs-thread-comment 1.5.2 → 1.6.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/lib/cjs/index.js +91 -7
- package/lib/es/index.js +94 -10
- package/lib/index.js +94 -10
- package/lib/types/controllers/docs-thread-comment-permission.controller.d.ts +30 -0
- package/lib/types/facade/f-document-text-range.d.ts +1 -1
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/docs-thread-comment-authz.service.d.ts +29 -0
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/cjs/index.js
CHANGED
|
@@ -138,7 +138,7 @@ const CreateDocTextRangeCommentCommand = {
|
|
|
138
138
|
|
|
139
139
|
// package.json
|
|
140
140
|
var name = "@univerjs/docs-thread-comment";
|
|
141
|
-
var version = "1.
|
|
141
|
+
var version = "1.6.0";
|
|
142
142
|
|
|
143
143
|
// src/config/config.ts
|
|
144
144
|
/**
|
|
@@ -160,14 +160,14 @@ const DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "docs-thread-comment.config";
|
|
|
160
160
|
const configSymbol = Symbol(DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
|
|
161
161
|
const defaultPluginConfig = {};
|
|
162
162
|
|
|
163
|
-
// \0@oxc-project+runtime@0.
|
|
163
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
164
164
|
function __decorateParam(paramIndex, decorator) {
|
|
165
165
|
return function(target, key) {
|
|
166
166
|
decorator(target, key, paramIndex);
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
// \0@oxc-project+runtime@0.
|
|
170
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
171
171
|
function __decorate(decorators, target, key, desc) {
|
|
172
172
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
173
173
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -175,6 +175,54 @@ function __decorate(decorators, target, key, desc) {
|
|
|
175
175
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
// src/controllers/docs-thread-comment-permission.controller.ts
|
|
179
|
+
let DocsThreadCommentPermissionController = class DocsThreadCommentPermissionController extends _univerjs_core.Disposable {
|
|
180
|
+
constructor(_errorService, _commandService, _threadCommentModel, _authzService) {
|
|
181
|
+
super();
|
|
182
|
+
this._errorService = _errorService;
|
|
183
|
+
this._commandService = _commandService;
|
|
184
|
+
this._threadCommentModel = _threadCommentModel;
|
|
185
|
+
this._authzService = _authzService;
|
|
186
|
+
this._commandExecutedListener();
|
|
187
|
+
}
|
|
188
|
+
_commandExecutedListener() {
|
|
189
|
+
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
190
|
+
const { id } = command;
|
|
191
|
+
if (!command.params) return;
|
|
192
|
+
if (id === _univerjs_thread_comment.AddCommentCommand.id) {
|
|
193
|
+
const { unitId, subUnitId, comment } = command.params;
|
|
194
|
+
this._checkWrite(comment.parentId ? "reply" : "add", unitId, subUnitId, comment.ref, comment.personId);
|
|
195
|
+
} else if (id === _univerjs_thread_comment.UpdateCommentCommand.id) {
|
|
196
|
+
const { unitId, subUnitId, payload } = command.params;
|
|
197
|
+
const comment = this._threadCommentModel.getComment(unitId, subUnitId, payload.commentId);
|
|
198
|
+
if (comment) this._checkWrite("update", unitId, subUnitId, comment.ref, comment.personId);
|
|
199
|
+
} else if (id === _univerjs_thread_comment.ResolveCommentCommand.id || id === _univerjs_thread_comment.DeleteCommentCommand.id || id === _univerjs_thread_comment.DeleteCommentTreeCommand.id) {
|
|
200
|
+
var _this$_threadCommentM;
|
|
201
|
+
const { unitId, subUnitId, commentId } = command.params;
|
|
202
|
+
const action = id === _univerjs_thread_comment.ResolveCommentCommand.id ? "resolve" : "delete";
|
|
203
|
+
const comment = action === "delete" && id === _univerjs_thread_comment.DeleteCommentTreeCommand.id ? (_this$_threadCommentM = this._threadCommentModel.getCommentWithChildren(unitId, subUnitId, commentId)) === null || _this$_threadCommentM === void 0 ? void 0 : _this$_threadCommentM.root : this._threadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
204
|
+
if (comment) this._checkWrite(action, unitId, subUnitId, comment.ref, comment.personId);
|
|
205
|
+
}
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
_checkWrite(action, unitId, subUnitId, ref, personId) {
|
|
209
|
+
if (this._authzService.canWrite(action, {
|
|
210
|
+
unitId,
|
|
211
|
+
subUnitId,
|
|
212
|
+
ref,
|
|
213
|
+
personId
|
|
214
|
+
})) return;
|
|
215
|
+
this._errorService.emitPermissionDenied(unitId);
|
|
216
|
+
throw new _univerjs_core.CustomCommandExecutionError(`Thread comment ${action} permission denied.`);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
DocsThreadCommentPermissionController = __decorate([
|
|
220
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.ErrorService)),
|
|
221
|
+
__decorateParam(1, _univerjs_core.ICommandService),
|
|
222
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_thread_comment.ThreadCommentModel)),
|
|
223
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_thread_comment.IThreadCommentAuthzService))
|
|
224
|
+
], DocsThreadCommentPermissionController);
|
|
225
|
+
|
|
178
226
|
// src/controllers/docs-thread-comment-resource.controller.ts
|
|
179
227
|
/**
|
|
180
228
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
@@ -207,7 +255,24 @@ DocsThreadCommentResourceController = __decorate([
|
|
|
207
255
|
__decorateParam(2, _univerjs_thread_comment.IThreadCommentDataSourceService)
|
|
208
256
|
], DocsThreadCommentResourceController);
|
|
209
257
|
|
|
210
|
-
//
|
|
258
|
+
// src/services/docs-thread-comment-authz.service.ts
|
|
259
|
+
let DocsThreadCommentAuthz = class DocsThreadCommentAuthz extends _univerjs_core.Disposable {
|
|
260
|
+
constructor(_permissionService, _authzService) {
|
|
261
|
+
super();
|
|
262
|
+
this._permissionService = _permissionService;
|
|
263
|
+
this._authzService = _authzService;
|
|
264
|
+
this.disposeWithMe(this._authzService.registerAuthz(_univerjs_core.UniverInstanceType.UNIVER_DOC, this));
|
|
265
|
+
}
|
|
266
|
+
canRead() {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
canWrite(_action, target) {
|
|
270
|
+
return (0, _univerjs_docs.getDocumentCommentPermission)(this._permissionService, target.unitId);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
DocsThreadCommentAuthz = __decorate([__decorateParam(0, _univerjs_core.IPermissionService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_thread_comment.IThreadCommentAuthzService))], DocsThreadCommentAuthz);
|
|
274
|
+
|
|
275
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
211
276
|
function _typeof(o) {
|
|
212
277
|
"@babel/helpers - typeof";
|
|
213
278
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -217,7 +282,7 @@ function _typeof(o) {
|
|
|
217
282
|
}, _typeof(o);
|
|
218
283
|
}
|
|
219
284
|
|
|
220
|
-
// \0@oxc-project+runtime@0.
|
|
285
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
221
286
|
function toPrimitive(t, e) {
|
|
222
287
|
if ("object" != _typeof(t) || !t) return t;
|
|
223
288
|
var r;
|
|
@@ -229,13 +294,13 @@ function toPrimitive(t, e) {
|
|
|
229
294
|
return ("string" === e ? String : Number)(t);
|
|
230
295
|
}
|
|
231
296
|
|
|
232
|
-
// \0@oxc-project+runtime@0.
|
|
297
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
233
298
|
function toPropertyKey(t) {
|
|
234
299
|
var i = toPrimitive(t, "string");
|
|
235
300
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
236
301
|
}
|
|
237
302
|
|
|
238
|
-
// \0@oxc-project+runtime@0.
|
|
303
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
239
304
|
function _defineProperty(e, r, t) {
|
|
240
305
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
241
306
|
value: t,
|
|
@@ -246,6 +311,21 @@ function _defineProperty(e, r, t) {
|
|
|
246
311
|
}
|
|
247
312
|
|
|
248
313
|
// src/plugin.ts
|
|
314
|
+
/**
|
|
315
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
316
|
+
*
|
|
317
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
318
|
+
* you may not use this file except in compliance with the License.
|
|
319
|
+
* You may obtain a copy of the License at
|
|
320
|
+
*
|
|
321
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
322
|
+
*
|
|
323
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
324
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
325
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
326
|
+
* See the License for the specific language governing permissions and
|
|
327
|
+
* limitations under the License.
|
|
328
|
+
*/
|
|
249
329
|
let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends _univerjs_core.Plugin {
|
|
250
330
|
constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
|
|
251
331
|
super();
|
|
@@ -259,6 +339,10 @@ let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends
|
|
|
259
339
|
onStarting() {
|
|
260
340
|
this._injector.add([DocsThreadCommentResourceController]);
|
|
261
341
|
this._injector.get(DocsThreadCommentResourceController);
|
|
342
|
+
this._injector.add([DocsThreadCommentAuthz]);
|
|
343
|
+
this._injector.get(DocsThreadCommentAuthz);
|
|
344
|
+
this._injector.add([DocsThreadCommentPermissionController]);
|
|
345
|
+
this._injector.get(DocsThreadCommentPermissionController);
|
|
262
346
|
this.disposeWithMe(this._commandService.registerCommand(CreateDocTextRangeCommentCommand));
|
|
263
347
|
this.disposeWithMe(this._commandService.registerCommand(AddDocCommentDecorationMutation));
|
|
264
348
|
}
|
package/lib/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BuildTextUtils, CommandType, CustomDecorationType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUniverInstanceService, Inject, Injector, JSONX, Plugin, UniverInstanceType, UserManagerService, generateRandomId, merge, sequenceExecute } from "@univerjs/core";
|
|
2
|
-
import { AddCommentMutation, IThreadCommentDataSourceService, TC_PLUGIN_NAME, ThreadCommentModel, UniverThreadCommentPlugin, createThreadCommentResourceHook, getDT, normalizeThreadCommentContent } from "@univerjs/thread-comment";
|
|
3
|
-
import { UniverDocsPlugin } from "@univerjs/docs";
|
|
1
|
+
import { BuildTextUtils, CommandType, CustomCommandExecutionError, CustomDecorationType, DependentOn, Disposable, ErrorService, ICommandService, IConfigService, IPermissionService, IResourceManagerService, IUniverInstanceService, Inject, Injector, JSONX, Plugin, UniverInstanceType, UserManagerService, generateRandomId, merge, sequenceExecute } from "@univerjs/core";
|
|
2
|
+
import { AddCommentCommand, AddCommentMutation, DeleteCommentCommand, DeleteCommentTreeCommand, IThreadCommentAuthzService, IThreadCommentDataSourceService, ResolveCommentCommand, TC_PLUGIN_NAME, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentCommand, createThreadCommentResourceHook, getDT, normalizeThreadCommentContent } from "@univerjs/thread-comment";
|
|
3
|
+
import { UniverDocsPlugin, getDocumentCommentPermission } from "@univerjs/docs";
|
|
4
4
|
|
|
5
5
|
// src/common/const.ts
|
|
6
6
|
/**
|
|
@@ -137,7 +137,7 @@ const CreateDocTextRangeCommentCommand = {
|
|
|
137
137
|
|
|
138
138
|
// package.json
|
|
139
139
|
var name = "@univerjs/docs-thread-comment";
|
|
140
|
-
var version = "1.
|
|
140
|
+
var version = "1.6.0";
|
|
141
141
|
|
|
142
142
|
// src/config/config.ts
|
|
143
143
|
/**
|
|
@@ -159,14 +159,14 @@ const DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "docs-thread-comment.config";
|
|
|
159
159
|
const configSymbol = Symbol(DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
|
|
160
160
|
const defaultPluginConfig = {};
|
|
161
161
|
|
|
162
|
-
// \0@oxc-project+runtime@0.
|
|
162
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
163
163
|
function __decorateParam(paramIndex, decorator) {
|
|
164
164
|
return function(target, key) {
|
|
165
165
|
decorator(target, key, paramIndex);
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
// \0@oxc-project+runtime@0.
|
|
169
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
170
170
|
function __decorate(decorators, target, key, desc) {
|
|
171
171
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
172
172
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -174,6 +174,54 @@ function __decorate(decorators, target, key, desc) {
|
|
|
174
174
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
// src/controllers/docs-thread-comment-permission.controller.ts
|
|
178
|
+
let DocsThreadCommentPermissionController = class DocsThreadCommentPermissionController extends Disposable {
|
|
179
|
+
constructor(_errorService, _commandService, _threadCommentModel, _authzService) {
|
|
180
|
+
super();
|
|
181
|
+
this._errorService = _errorService;
|
|
182
|
+
this._commandService = _commandService;
|
|
183
|
+
this._threadCommentModel = _threadCommentModel;
|
|
184
|
+
this._authzService = _authzService;
|
|
185
|
+
this._commandExecutedListener();
|
|
186
|
+
}
|
|
187
|
+
_commandExecutedListener() {
|
|
188
|
+
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
189
|
+
const { id } = command;
|
|
190
|
+
if (!command.params) return;
|
|
191
|
+
if (id === AddCommentCommand.id) {
|
|
192
|
+
const { unitId, subUnitId, comment } = command.params;
|
|
193
|
+
this._checkWrite(comment.parentId ? "reply" : "add", unitId, subUnitId, comment.ref, comment.personId);
|
|
194
|
+
} else if (id === UpdateCommentCommand.id) {
|
|
195
|
+
const { unitId, subUnitId, payload } = command.params;
|
|
196
|
+
const comment = this._threadCommentModel.getComment(unitId, subUnitId, payload.commentId);
|
|
197
|
+
if (comment) this._checkWrite("update", unitId, subUnitId, comment.ref, comment.personId);
|
|
198
|
+
} else if (id === ResolveCommentCommand.id || id === DeleteCommentCommand.id || id === DeleteCommentTreeCommand.id) {
|
|
199
|
+
var _this$_threadCommentM;
|
|
200
|
+
const { unitId, subUnitId, commentId } = command.params;
|
|
201
|
+
const action = id === ResolveCommentCommand.id ? "resolve" : "delete";
|
|
202
|
+
const comment = action === "delete" && id === DeleteCommentTreeCommand.id ? (_this$_threadCommentM = this._threadCommentModel.getCommentWithChildren(unitId, subUnitId, commentId)) === null || _this$_threadCommentM === void 0 ? void 0 : _this$_threadCommentM.root : this._threadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
203
|
+
if (comment) this._checkWrite(action, unitId, subUnitId, comment.ref, comment.personId);
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
_checkWrite(action, unitId, subUnitId, ref, personId) {
|
|
208
|
+
if (this._authzService.canWrite(action, {
|
|
209
|
+
unitId,
|
|
210
|
+
subUnitId,
|
|
211
|
+
ref,
|
|
212
|
+
personId
|
|
213
|
+
})) return;
|
|
214
|
+
this._errorService.emitPermissionDenied(unitId);
|
|
215
|
+
throw new CustomCommandExecutionError(`Thread comment ${action} permission denied.`);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
DocsThreadCommentPermissionController = __decorate([
|
|
219
|
+
__decorateParam(0, Inject(ErrorService)),
|
|
220
|
+
__decorateParam(1, ICommandService),
|
|
221
|
+
__decorateParam(2, Inject(ThreadCommentModel)),
|
|
222
|
+
__decorateParam(3, Inject(IThreadCommentAuthzService))
|
|
223
|
+
], DocsThreadCommentPermissionController);
|
|
224
|
+
|
|
177
225
|
// src/controllers/docs-thread-comment-resource.controller.ts
|
|
178
226
|
/**
|
|
179
227
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
@@ -206,7 +254,24 @@ DocsThreadCommentResourceController = __decorate([
|
|
|
206
254
|
__decorateParam(2, IThreadCommentDataSourceService)
|
|
207
255
|
], DocsThreadCommentResourceController);
|
|
208
256
|
|
|
209
|
-
//
|
|
257
|
+
// src/services/docs-thread-comment-authz.service.ts
|
|
258
|
+
let DocsThreadCommentAuthz = class DocsThreadCommentAuthz extends Disposable {
|
|
259
|
+
constructor(_permissionService, _authzService) {
|
|
260
|
+
super();
|
|
261
|
+
this._permissionService = _permissionService;
|
|
262
|
+
this._authzService = _authzService;
|
|
263
|
+
this.disposeWithMe(this._authzService.registerAuthz(UniverInstanceType.UNIVER_DOC, this));
|
|
264
|
+
}
|
|
265
|
+
canRead() {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
canWrite(_action, target) {
|
|
269
|
+
return getDocumentCommentPermission(this._permissionService, target.unitId);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
DocsThreadCommentAuthz = __decorate([__decorateParam(0, IPermissionService), __decorateParam(1, Inject(IThreadCommentAuthzService))], DocsThreadCommentAuthz);
|
|
273
|
+
|
|
274
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
210
275
|
function _typeof(o) {
|
|
211
276
|
"@babel/helpers - typeof";
|
|
212
277
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -216,7 +281,7 @@ function _typeof(o) {
|
|
|
216
281
|
}, _typeof(o);
|
|
217
282
|
}
|
|
218
283
|
|
|
219
|
-
// \0@oxc-project+runtime@0.
|
|
284
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
220
285
|
function toPrimitive(t, e) {
|
|
221
286
|
if ("object" != _typeof(t) || !t) return t;
|
|
222
287
|
var r;
|
|
@@ -228,13 +293,13 @@ function toPrimitive(t, e) {
|
|
|
228
293
|
return ("string" === e ? String : Number)(t);
|
|
229
294
|
}
|
|
230
295
|
|
|
231
|
-
// \0@oxc-project+runtime@0.
|
|
296
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
232
297
|
function toPropertyKey(t) {
|
|
233
298
|
var i = toPrimitive(t, "string");
|
|
234
299
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
235
300
|
}
|
|
236
301
|
|
|
237
|
-
// \0@oxc-project+runtime@0.
|
|
302
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
238
303
|
function _defineProperty(e, r, t) {
|
|
239
304
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
240
305
|
value: t,
|
|
@@ -245,6 +310,21 @@ function _defineProperty(e, r, t) {
|
|
|
245
310
|
}
|
|
246
311
|
|
|
247
312
|
// src/plugin.ts
|
|
313
|
+
/**
|
|
314
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
315
|
+
*
|
|
316
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
317
|
+
* you may not use this file except in compliance with the License.
|
|
318
|
+
* You may obtain a copy of the License at
|
|
319
|
+
*
|
|
320
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
321
|
+
*
|
|
322
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
323
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
324
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
325
|
+
* See the License for the specific language governing permissions and
|
|
326
|
+
* limitations under the License.
|
|
327
|
+
*/
|
|
248
328
|
let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends Plugin {
|
|
249
329
|
constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
|
|
250
330
|
super();
|
|
@@ -258,6 +338,10 @@ let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends
|
|
|
258
338
|
onStarting() {
|
|
259
339
|
this._injector.add([DocsThreadCommentResourceController]);
|
|
260
340
|
this._injector.get(DocsThreadCommentResourceController);
|
|
341
|
+
this._injector.add([DocsThreadCommentAuthz]);
|
|
342
|
+
this._injector.get(DocsThreadCommentAuthz);
|
|
343
|
+
this._injector.add([DocsThreadCommentPermissionController]);
|
|
344
|
+
this._injector.get(DocsThreadCommentPermissionController);
|
|
261
345
|
this.disposeWithMe(this._commandService.registerCommand(CreateDocTextRangeCommentCommand));
|
|
262
346
|
this.disposeWithMe(this._commandService.registerCommand(AddDocCommentDecorationMutation));
|
|
263
347
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BuildTextUtils, CommandType, CustomDecorationType, DependentOn, Disposable, ICommandService, IConfigService, IResourceManagerService, IUniverInstanceService, Inject, Injector, JSONX, Plugin, UniverInstanceType, UserManagerService, generateRandomId, merge, sequenceExecute } from "@univerjs/core";
|
|
2
|
-
import { AddCommentMutation, IThreadCommentDataSourceService, TC_PLUGIN_NAME, ThreadCommentModel, UniverThreadCommentPlugin, createThreadCommentResourceHook, getDT, normalizeThreadCommentContent } from "@univerjs/thread-comment";
|
|
3
|
-
import { UniverDocsPlugin } from "@univerjs/docs";
|
|
1
|
+
import { BuildTextUtils, CommandType, CustomCommandExecutionError, CustomDecorationType, DependentOn, Disposable, ErrorService, ICommandService, IConfigService, IPermissionService, IResourceManagerService, IUniverInstanceService, Inject, Injector, JSONX, Plugin, UniverInstanceType, UserManagerService, generateRandomId, merge, sequenceExecute } from "@univerjs/core";
|
|
2
|
+
import { AddCommentCommand, AddCommentMutation, DeleteCommentCommand, DeleteCommentTreeCommand, IThreadCommentAuthzService, IThreadCommentDataSourceService, ResolveCommentCommand, TC_PLUGIN_NAME, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentCommand, createThreadCommentResourceHook, getDT, normalizeThreadCommentContent } from "@univerjs/thread-comment";
|
|
3
|
+
import { UniverDocsPlugin, getDocumentCommentPermission } from "@univerjs/docs";
|
|
4
4
|
|
|
5
5
|
// src/common/const.ts
|
|
6
6
|
/**
|
|
@@ -137,7 +137,7 @@ const CreateDocTextRangeCommentCommand = {
|
|
|
137
137
|
|
|
138
138
|
// package.json
|
|
139
139
|
var name = "@univerjs/docs-thread-comment";
|
|
140
|
-
var version = "1.
|
|
140
|
+
var version = "1.6.0";
|
|
141
141
|
|
|
142
142
|
// src/config/config.ts
|
|
143
143
|
/**
|
|
@@ -159,14 +159,14 @@ const DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "docs-thread-comment.config";
|
|
|
159
159
|
const configSymbol = Symbol(DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
|
|
160
160
|
const defaultPluginConfig = {};
|
|
161
161
|
|
|
162
|
-
// \0@oxc-project+runtime@0.
|
|
162
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
163
163
|
function __decorateParam(paramIndex, decorator) {
|
|
164
164
|
return function(target, key) {
|
|
165
165
|
decorator(target, key, paramIndex);
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
// \0@oxc-project+runtime@0.
|
|
169
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
170
170
|
function __decorate(decorators, target, key, desc) {
|
|
171
171
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
172
172
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -174,6 +174,54 @@ function __decorate(decorators, target, key, desc) {
|
|
|
174
174
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
// src/controllers/docs-thread-comment-permission.controller.ts
|
|
178
|
+
let DocsThreadCommentPermissionController = class DocsThreadCommentPermissionController extends Disposable {
|
|
179
|
+
constructor(_errorService, _commandService, _threadCommentModel, _authzService) {
|
|
180
|
+
super();
|
|
181
|
+
this._errorService = _errorService;
|
|
182
|
+
this._commandService = _commandService;
|
|
183
|
+
this._threadCommentModel = _threadCommentModel;
|
|
184
|
+
this._authzService = _authzService;
|
|
185
|
+
this._commandExecutedListener();
|
|
186
|
+
}
|
|
187
|
+
_commandExecutedListener() {
|
|
188
|
+
this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
|
|
189
|
+
const { id } = command;
|
|
190
|
+
if (!command.params) return;
|
|
191
|
+
if (id === AddCommentCommand.id) {
|
|
192
|
+
const { unitId, subUnitId, comment } = command.params;
|
|
193
|
+
this._checkWrite(comment.parentId ? "reply" : "add", unitId, subUnitId, comment.ref, comment.personId);
|
|
194
|
+
} else if (id === UpdateCommentCommand.id) {
|
|
195
|
+
const { unitId, subUnitId, payload } = command.params;
|
|
196
|
+
const comment = this._threadCommentModel.getComment(unitId, subUnitId, payload.commentId);
|
|
197
|
+
if (comment) this._checkWrite("update", unitId, subUnitId, comment.ref, comment.personId);
|
|
198
|
+
} else if (id === ResolveCommentCommand.id || id === DeleteCommentCommand.id || id === DeleteCommentTreeCommand.id) {
|
|
199
|
+
var _this$_threadCommentM;
|
|
200
|
+
const { unitId, subUnitId, commentId } = command.params;
|
|
201
|
+
const action = id === ResolveCommentCommand.id ? "resolve" : "delete";
|
|
202
|
+
const comment = action === "delete" && id === DeleteCommentTreeCommand.id ? (_this$_threadCommentM = this._threadCommentModel.getCommentWithChildren(unitId, subUnitId, commentId)) === null || _this$_threadCommentM === void 0 ? void 0 : _this$_threadCommentM.root : this._threadCommentModel.getComment(unitId, subUnitId, commentId);
|
|
203
|
+
if (comment) this._checkWrite(action, unitId, subUnitId, comment.ref, comment.personId);
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
_checkWrite(action, unitId, subUnitId, ref, personId) {
|
|
208
|
+
if (this._authzService.canWrite(action, {
|
|
209
|
+
unitId,
|
|
210
|
+
subUnitId,
|
|
211
|
+
ref,
|
|
212
|
+
personId
|
|
213
|
+
})) return;
|
|
214
|
+
this._errorService.emitPermissionDenied(unitId);
|
|
215
|
+
throw new CustomCommandExecutionError(`Thread comment ${action} permission denied.`);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
DocsThreadCommentPermissionController = __decorate([
|
|
219
|
+
__decorateParam(0, Inject(ErrorService)),
|
|
220
|
+
__decorateParam(1, ICommandService),
|
|
221
|
+
__decorateParam(2, Inject(ThreadCommentModel)),
|
|
222
|
+
__decorateParam(3, Inject(IThreadCommentAuthzService))
|
|
223
|
+
], DocsThreadCommentPermissionController);
|
|
224
|
+
|
|
177
225
|
// src/controllers/docs-thread-comment-resource.controller.ts
|
|
178
226
|
/**
|
|
179
227
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
@@ -206,7 +254,24 @@ DocsThreadCommentResourceController = __decorate([
|
|
|
206
254
|
__decorateParam(2, IThreadCommentDataSourceService)
|
|
207
255
|
], DocsThreadCommentResourceController);
|
|
208
256
|
|
|
209
|
-
//
|
|
257
|
+
// src/services/docs-thread-comment-authz.service.ts
|
|
258
|
+
let DocsThreadCommentAuthz = class DocsThreadCommentAuthz extends Disposable {
|
|
259
|
+
constructor(_permissionService, _authzService) {
|
|
260
|
+
super();
|
|
261
|
+
this._permissionService = _permissionService;
|
|
262
|
+
this._authzService = _authzService;
|
|
263
|
+
this.disposeWithMe(this._authzService.registerAuthz(UniverInstanceType.UNIVER_DOC, this));
|
|
264
|
+
}
|
|
265
|
+
canRead() {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
canWrite(_action, target) {
|
|
269
|
+
return getDocumentCommentPermission(this._permissionService, target.unitId);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
DocsThreadCommentAuthz = __decorate([__decorateParam(0, IPermissionService), __decorateParam(1, Inject(IThreadCommentAuthzService))], DocsThreadCommentAuthz);
|
|
273
|
+
|
|
274
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
210
275
|
function _typeof(o) {
|
|
211
276
|
"@babel/helpers - typeof";
|
|
212
277
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -216,7 +281,7 @@ function _typeof(o) {
|
|
|
216
281
|
}, _typeof(o);
|
|
217
282
|
}
|
|
218
283
|
|
|
219
|
-
// \0@oxc-project+runtime@0.
|
|
284
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
220
285
|
function toPrimitive(t, e) {
|
|
221
286
|
if ("object" != _typeof(t) || !t) return t;
|
|
222
287
|
var r;
|
|
@@ -228,13 +293,13 @@ function toPrimitive(t, e) {
|
|
|
228
293
|
return ("string" === e ? String : Number)(t);
|
|
229
294
|
}
|
|
230
295
|
|
|
231
|
-
// \0@oxc-project+runtime@0.
|
|
296
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
232
297
|
function toPropertyKey(t) {
|
|
233
298
|
var i = toPrimitive(t, "string");
|
|
234
299
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
235
300
|
}
|
|
236
301
|
|
|
237
|
-
// \0@oxc-project+runtime@0.
|
|
302
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
238
303
|
function _defineProperty(e, r, t) {
|
|
239
304
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
240
305
|
value: t,
|
|
@@ -245,6 +310,21 @@ function _defineProperty(e, r, t) {
|
|
|
245
310
|
}
|
|
246
311
|
|
|
247
312
|
// src/plugin.ts
|
|
313
|
+
/**
|
|
314
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
315
|
+
*
|
|
316
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
317
|
+
* you may not use this file except in compliance with the License.
|
|
318
|
+
* You may obtain a copy of the License at
|
|
319
|
+
*
|
|
320
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
321
|
+
*
|
|
322
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
323
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
324
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
325
|
+
* See the License for the specific language governing permissions and
|
|
326
|
+
* limitations under the License.
|
|
327
|
+
*/
|
|
248
328
|
let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends Plugin {
|
|
249
329
|
constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
|
|
250
330
|
super();
|
|
@@ -258,6 +338,10 @@ let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends
|
|
|
258
338
|
onStarting() {
|
|
259
339
|
this._injector.add([DocsThreadCommentResourceController]);
|
|
260
340
|
this._injector.get(DocsThreadCommentResourceController);
|
|
341
|
+
this._injector.add([DocsThreadCommentAuthz]);
|
|
342
|
+
this._injector.get(DocsThreadCommentAuthz);
|
|
343
|
+
this._injector.add([DocsThreadCommentPermissionController]);
|
|
344
|
+
this._injector.get(DocsThreadCommentPermissionController);
|
|
261
345
|
this.disposeWithMe(this._commandService.registerCommand(CreateDocTextRangeCommentCommand));
|
|
262
346
|
this.disposeWithMe(this._commandService.registerCommand(AddDocCommentDecorationMutation));
|
|
263
347
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Disposable, ErrorService, ICommandService } from '@univerjs/core';
|
|
17
|
+
import { IThreadCommentAuthzService, ThreadCommentModel } from '@univerjs/thread-comment';
|
|
18
|
+
/**
|
|
19
|
+
* Enforces comment permissions for docs in the base package. The generic
|
|
20
|
+
* permission-denied notification is rendered by `@univerjs/ui`.
|
|
21
|
+
*/
|
|
22
|
+
export declare class DocsThreadCommentPermissionController extends Disposable {
|
|
23
|
+
private readonly _errorService;
|
|
24
|
+
private readonly _commandService;
|
|
25
|
+
private readonly _threadCommentModel;
|
|
26
|
+
private readonly _authzService;
|
|
27
|
+
constructor(_errorService: ErrorService, _commandService: ICommandService, _threadCommentModel: ThreadCommentModel, _authzService: IThreadCommentAuthzService);
|
|
28
|
+
private _commandExecutedListener;
|
|
29
|
+
private _checkWrite;
|
|
30
|
+
}
|
|
@@ -24,7 +24,7 @@ export interface IFDocumentTextRangeThreadCommentMixin {
|
|
|
24
24
|
* Creates a comment on this text range.
|
|
25
25
|
* @param content Plain text or a Univer document body for rich comment content.
|
|
26
26
|
* @param [options] Optional stable IDs, author, attachments, and creation time.
|
|
27
|
-
* @returns {Promise<boolean>} `true` when the create command succeeds; otherwise, `false`.
|
|
27
|
+
* @returns {Promise<boolean>} `true` when the create command succeeds; otherwise, `false`. Rejects when a host permission interceptor denies the write.
|
|
28
28
|
* @throws {TypeError} If the content is empty.
|
|
29
29
|
* @example
|
|
30
30
|
* ```ts
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IUniverDocsThreadCommentConfig } from './config/config';
|
|
17
16
|
import { ICommandService, IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
17
|
+
import type { IUniverDocsThreadCommentConfig } from './config/config';
|
|
18
18
|
export declare class UniverDocsThreadCommentPlugin extends Plugin {
|
|
19
19
|
private readonly _config;
|
|
20
20
|
protected _injector: Injector;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IThreadCommentAuthz, IThreadCommentAuthzTarget, ThreadCommentWriteAction } from '@univerjs/thread-comment';
|
|
17
|
+
import { Disposable, IPermissionService } from '@univerjs/core';
|
|
18
|
+
import { IThreadCommentAuthzService } from '@univerjs/thread-comment';
|
|
19
|
+
/**
|
|
20
|
+
* Docs comment permissions: opening a document already grants read access, while
|
|
21
|
+
* writing requires the document comment permission.
|
|
22
|
+
*/
|
|
23
|
+
export declare class DocsThreadCommentAuthz extends Disposable implements IThreadCommentAuthz {
|
|
24
|
+
private readonly _permissionService;
|
|
25
|
+
private readonly _authzService;
|
|
26
|
+
constructor(_permissionService: IPermissionService, _authzService: IThreadCommentAuthzService);
|
|
27
|
+
canRead(): boolean;
|
|
28
|
+
canWrite(_action: ThreadCommentWriteAction, target: IThreadCommentAuthzTarget): boolean;
|
|
29
|
+
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/thread-comment"),require("@univerjs/docs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/thread-comment`,`@univerjs/docs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsThreadComment={},e.UniverCore,e.UniverThreadComment,e.UniverDocs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=`default_doc`,a={id:`docs-thread-comment.mutation.add-decoration`,type:t.CommandType.MUTATION,handler(e,n){if(!n||t.JSONX.isNoop(n.actions))return!1;let r=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);if(!r)return!1;let i=t.JSONX.invertWithDoc(n.actions,r.getSnapshot());return r.apply(n.actions),{...n,actions:i}}};function o(e,n,r){var i;let{startOffset:a,endOffset:o}=r;if(!Number.isInteger(a)||!Number.isInteger(o)||a<0||o<=a)return null;let s=e.get(t.IUniverInstanceService).getUnit(n,t.UniverInstanceType.UNIVER_DOC),c=s==null||(i=s.getSelfOrHeaderFooterModel(r.segmentId))==null?void 0:i.getBody();return!c||o>c.dataStream.length?null:{...r,startOffset:a,endOffset:o,collapsed:!1}}async function s(e,r){let a=o(e,r.unitId,r.range);if(!a)return null;let s=await e.get(n.IThreadCommentDataSourceService).addComment(r.comment),c={...r.comment,...s,unitId:r.unitId,subUnitId:i,startOffset:a.startOffset,endOffset:a.endOffset,segmentId:a.segmentId,collapsed:!1},l=t.BuildTextUtils.customDecoration.add({ranges:[a],id:c.id,type:t.CustomDecorationType.COMMENT}),u={unitId:r.unitId,actions:t.JSONX.getInstance().editOp(l.serialize()),segmentId:a.segmentId};return{comment:c,commentMutation:{id:n.AddCommentMutation.id,params:{unitId:r.unitId,subUnitId:i,comment:c}},decorationMutationParams:u}}let c={id:`docs.command.create-text-range-comment`,type:t.CommandType.COMMAND,async handler(e,r){var c;if(!r)return!1;let l=o(e,r.unitId,r.range);if(!l)return!1;let u=e.get(t.IUniverInstanceService).getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC),d=u==null||(c=u.getSelfOrHeaderFooterModel(l.segmentId))==null?void 0:c.getBody();if(!d)return!1;let f=r.id??(0,t.generateRandomId)(),p={id:f,threadId:r.threadId??f,unitId:r.unitId,subUnitId:i,ref:t.BuildTextUtils.transform.getPlainText(d.dataStream.slice(l.startOffset,l.endOffset)),text:(0,n.normalizeThreadCommentContent)(r.content),attachments:r.attachments??[],dT:(0,n.getDT)(r.dateTime),personId:r.personId??e.get(t.UserManagerService).getCurrentUser().userID,startOffset:l.startOffset,endOffset:l.endOffset,segmentId:l.segmentId,collapsed:!1},m=await s(e,{unitId:r.unitId,range:l,comment:p});return m?(await(0,t.sequenceExecute)([m.commentMutation,{id:a.id,params:m.decorationMutationParams}],e.get(t.ICommandService))).result:!1}};var l=`@univerjs/docs-thread-comment`,u=`1.
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/thread-comment"),require("@univerjs/docs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/thread-comment`,`@univerjs/docs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsThreadComment={},e.UniverCore,e.UniverThreadComment,e.UniverDocs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=`default_doc`,a={id:`docs-thread-comment.mutation.add-decoration`,type:t.CommandType.MUTATION,handler(e,n){if(!n||t.JSONX.isNoop(n.actions))return!1;let r=e.get(t.IUniverInstanceService).getUnit(n.unitId,t.UniverInstanceType.UNIVER_DOC);if(!r)return!1;let i=t.JSONX.invertWithDoc(n.actions,r.getSnapshot());return r.apply(n.actions),{...n,actions:i}}};function o(e,n,r){var i;let{startOffset:a,endOffset:o}=r;if(!Number.isInteger(a)||!Number.isInteger(o)||a<0||o<=a)return null;let s=e.get(t.IUniverInstanceService).getUnit(n,t.UniverInstanceType.UNIVER_DOC),c=s==null||(i=s.getSelfOrHeaderFooterModel(r.segmentId))==null?void 0:i.getBody();return!c||o>c.dataStream.length?null:{...r,startOffset:a,endOffset:o,collapsed:!1}}async function s(e,r){let a=o(e,r.unitId,r.range);if(!a)return null;let s=await e.get(n.IThreadCommentDataSourceService).addComment(r.comment),c={...r.comment,...s,unitId:r.unitId,subUnitId:i,startOffset:a.startOffset,endOffset:a.endOffset,segmentId:a.segmentId,collapsed:!1},l=t.BuildTextUtils.customDecoration.add({ranges:[a],id:c.id,type:t.CustomDecorationType.COMMENT}),u={unitId:r.unitId,actions:t.JSONX.getInstance().editOp(l.serialize()),segmentId:a.segmentId};return{comment:c,commentMutation:{id:n.AddCommentMutation.id,params:{unitId:r.unitId,subUnitId:i,comment:c}},decorationMutationParams:u}}let c={id:`docs.command.create-text-range-comment`,type:t.CommandType.COMMAND,async handler(e,r){var c;if(!r)return!1;let l=o(e,r.unitId,r.range);if(!l)return!1;let u=e.get(t.IUniverInstanceService).getUnit(r.unitId,t.UniverInstanceType.UNIVER_DOC),d=u==null||(c=u.getSelfOrHeaderFooterModel(l.segmentId))==null?void 0:c.getBody();if(!d)return!1;let f=r.id??(0,t.generateRandomId)(),p={id:f,threadId:r.threadId??f,unitId:r.unitId,subUnitId:i,ref:t.BuildTextUtils.transform.getPlainText(d.dataStream.slice(l.startOffset,l.endOffset)),text:(0,n.normalizeThreadCommentContent)(r.content),attachments:r.attachments??[],dT:(0,n.getDT)(r.dateTime),personId:r.personId??e.get(t.UserManagerService).getCurrentUser().userID,startOffset:l.startOffset,endOffset:l.endOffset,segmentId:l.segmentId,collapsed:!1},m=await s(e,{unitId:r.unitId,range:l,comment:p});return m?(await(0,t.sequenceExecute)([m.commentMutation,{id:a.id,params:m.decorationMutationParams}],e.get(t.ICommandService))).result:!1}};var l=`@univerjs/docs-thread-comment`,u=`1.6.0`;let d={};function f(e,t){return function(n,r){t(n,r,e)}}function p(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let m=class extends t.Disposable{constructor(e,t,n,r){super(),this._errorService=e,this._commandService=t,this._threadCommentModel=n,this._authzService=r,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let{id:t}=e;if(e.params){if(t===n.AddCommentCommand.id){let{unitId:t,subUnitId:n,comment:r}=e.params;this._checkWrite(r.parentId?`reply`:`add`,t,n,r.ref,r.personId)}else if(t===n.UpdateCommentCommand.id){let{unitId:t,subUnitId:n,payload:r}=e.params,i=this._threadCommentModel.getComment(t,n,r.commentId);i&&this._checkWrite(`update`,t,n,i.ref,i.personId)}else if(t===n.ResolveCommentCommand.id||t===n.DeleteCommentCommand.id||t===n.DeleteCommentTreeCommand.id){var r;let{unitId:i,subUnitId:a,commentId:o}=e.params,s=t===n.ResolveCommentCommand.id?`resolve`:`delete`,c=s===`delete`&&t===n.DeleteCommentTreeCommand.id?(r=this._threadCommentModel.getCommentWithChildren(i,a,o))==null?void 0:r.root:this._threadCommentModel.getComment(i,a,o);c&&this._checkWrite(s,i,a,c.ref,c.personId)}}}))}_checkWrite(e,n,r,i,a){if(!this._authzService.canWrite(e,{unitId:n,subUnitId:r,ref:i,personId:a}))throw this._errorService.emitPermissionDenied(n),new t.CustomCommandExecutionError(`Thread comment ${e} permission denied.`)}};m=p([f(0,(0,t.Inject)(t.ErrorService)),f(1,t.ICommandService),f(2,(0,t.Inject)(n.ThreadCommentModel)),f(3,(0,t.Inject)(n.IThreadCommentAuthzService))],m);let h=`DOC_${n.TC_PLUGIN_NAME}`,g=class extends t.Disposable{constructor(e,r,i){super(),this._resourceManagerService=e,this._threadCommentModel=r,this._threadCommentDataSourceService=i,this.disposeWithMe(this._resourceManagerService.registerPluginResource((0,n.createThreadCommentResourceHook)(this._threadCommentModel,this._threadCommentDataSourceService,h,[t.UniverInstanceType.UNIVER_DOC])))}};g=p([f(0,t.IResourceManagerService),f(1,(0,t.Inject)(n.ThreadCommentModel)),f(2,n.IThreadCommentDataSourceService)],g);let _=class extends t.Disposable{constructor(e,n){super(),this._permissionService=e,this._authzService=n,this.disposeWithMe(this._authzService.registerAuthz(t.UniverInstanceType.UNIVER_DOC,this))}canRead(){return!0}canWrite(e,t){return(0,r.getDocumentCommentPermission)(this._permissionService,t.unitId)}};_=p([f(0,t.IPermissionService),f(1,(0,t.Inject)(n.IThreadCommentAuthzService))],_);function v(e){"@babel/helpers - typeof";return v=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},v(e)}function y(e,t){if(v(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(v(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function b(e){var t=y(e,`string`);return v(t)==`symbol`?t:t+``}function x(e,t,n){return(t=b(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let S=class extends t.Plugin{constructor(e=d,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},d,this._config);this._configService.setConfig(`docs-thread-comment.config`,a)}onStarting(){this._injector.add([g]),this._injector.get(g),this._injector.add([_]),this._injector.get(_),this._injector.add([m]),this._injector.get(m),this.disposeWithMe(this._commandService.registerCommand(c)),this.disposeWithMe(this._commandService.registerCommand(a))}};x(S,`pluginName`,`DOC_THREAD_COMMENT_PLUGIN`),x(S,`packageName`,l),x(S,`version`,u),x(S,`type`,t.UniverInstanceType.UNIVER_DOC),S=p([(0,t.DependentOn)(r.UniverDocsPlugin,n.UniverThreadCommentPlugin),f(1,(0,t.Inject)(t.Injector)),f(2,t.IConfigService),f(3,t.ICommandService)],S),e.AddDocCommentDecorationMutation=a,e.CreateDocTextRangeCommentCommand=c,e.DEFAULT_DOC_SUBUNIT_ID=i,Object.defineProperty(e,"UniverDocsThreadCommentPlugin",{enumerable:!0,get:function(){return S}}),e.prepareDocTextRangeComment=s});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-thread-comment",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Thread comment model integration and Facade APIs for Univer Docs.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -58,15 +58,15 @@
|
|
|
58
58
|
"lib"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/core": "1.
|
|
62
|
-
"@univerjs/docs": "1.
|
|
63
|
-
"@univerjs/thread-comment": "1.
|
|
61
|
+
"@univerjs/core": "1.6.0",
|
|
62
|
+
"@univerjs/docs": "1.6.0",
|
|
63
|
+
"@univerjs/thread-comment": "1.6.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@univerjs-infra/shared": "1.
|
|
66
|
+
"@univerjs-infra/shared": "1.6.0",
|
|
67
67
|
"rxjs": "7.8.2",
|
|
68
|
-
"tsrs": "
|
|
69
|
-
"vitest": "^5.1.
|
|
68
|
+
"tsrs": "7.1.0-beta.tsrs2",
|
|
69
|
+
"vitest": "^5.1.1"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"test": "vitest run",
|