@univerjs/docs-thread-comment 1.0.0-rc.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.
@@ -0,0 +1,288 @@
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";
4
+
5
+ //#region src/common/const.ts
6
+ /**
7
+ * Copyright 2023-present DreamNum Co., Ltd.
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ /** Stable subunit used by document text comments. */
22
+ const DEFAULT_DOC_SUBUNIT_ID = "default_doc";
23
+ const DOCS_THREAD_COMMENT_PLUGIN_NAME = "DOC_THREAD_COMMENT_PLUGIN";
24
+
25
+ //#endregion
26
+ //#region src/commands/commands/create-doc-text-range-comment.command.ts
27
+ /** Applies document comment decoration actions without render or selection services. */
28
+ const AddDocCommentDecorationMutation = {
29
+ id: "docs-thread-comment.mutation.add-decoration",
30
+ type: CommandType.MUTATION,
31
+ handler(accessor, params) {
32
+ if (!params || JSONX.isNoop(params.actions)) return false;
33
+ const document = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
34
+ if (!document) return false;
35
+ const undoActions = JSONX.invertWithDoc(params.actions, document.getSnapshot());
36
+ document.apply(params.actions);
37
+ return {
38
+ ...params,
39
+ actions: undoActions
40
+ };
41
+ }
42
+ };
43
+ function getValidRange(accessor, unitId, range) {
44
+ var _document$getSelfOrHe;
45
+ const { startOffset, endOffset } = range;
46
+ if (!Number.isInteger(startOffset) || !Number.isInteger(endOffset) || startOffset < 0 || endOffset <= startOffset) return null;
47
+ const document = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
48
+ const body = document === null || document === void 0 || (_document$getSelfOrHe = document.getSelfOrHeaderFooterModel(range.segmentId)) === null || _document$getSelfOrHe === void 0 ? void 0 : _document$getSelfOrHe.getBody();
49
+ if (!body || endOffset > body.dataStream.length) return null;
50
+ return {
51
+ ...range,
52
+ startOffset,
53
+ endOffset,
54
+ collapsed: false
55
+ };
56
+ }
57
+ /** Builds the model mutations shared by headless and UI document comment commands. */
58
+ async function prepareDocTextRangeComment(accessor, params) {
59
+ const range = getValidRange(accessor, params.unitId, params.range);
60
+ if (!range) return null;
61
+ const savedComment = await accessor.get(IThreadCommentDataSourceService).addComment(params.comment);
62
+ const comment = {
63
+ ...params.comment,
64
+ ...savedComment,
65
+ unitId: params.unitId,
66
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
67
+ startOffset: range.startOffset,
68
+ endOffset: range.endOffset,
69
+ segmentId: range.segmentId,
70
+ collapsed: false
71
+ };
72
+ const textX = BuildTextUtils.customDecoration.add({
73
+ ranges: [range],
74
+ id: comment.id,
75
+ type: CustomDecorationType.COMMENT
76
+ });
77
+ const decorationMutationParams = {
78
+ unitId: params.unitId,
79
+ actions: JSONX.getInstance().editOp(textX.serialize()),
80
+ segmentId: range.segmentId
81
+ };
82
+ return {
83
+ comment,
84
+ commentMutation: {
85
+ id: AddCommentMutation.id,
86
+ params: {
87
+ unitId: params.unitId,
88
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
89
+ comment
90
+ }
91
+ },
92
+ decorationMutationParams
93
+ };
94
+ }
95
+ /**
96
+ * Creates a root comment and document decoration for an explicit text range.
97
+ * This model command is safe to execute without loading document UI packages.
98
+ */
99
+ const CreateDocTextRangeCommentCommand = {
100
+ id: "docs.command.create-text-range-comment",
101
+ type: CommandType.COMMAND,
102
+ async handler(accessor, params) {
103
+ var _document$getSelfOrHe2;
104
+ if (!params) return false;
105
+ const range = getValidRange(accessor, params.unitId, params.range);
106
+ if (!range) return false;
107
+ const document = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
108
+ const body = document === null || document === void 0 || (_document$getSelfOrHe2 = document.getSelfOrHeaderFooterModel(range.segmentId)) === null || _document$getSelfOrHe2 === void 0 ? void 0 : _document$getSelfOrHe2.getBody();
109
+ if (!body) return false;
110
+ const id = params.id ?? generateRandomId();
111
+ const comment = {
112
+ id,
113
+ threadId: params.threadId ?? id,
114
+ unitId: params.unitId,
115
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
116
+ ref: BuildTextUtils.transform.getPlainText(body.dataStream.slice(range.startOffset, range.endOffset)),
117
+ text: normalizeThreadCommentContent(params.content),
118
+ attachments: params.attachments ?? [],
119
+ dT: getDT(params.dateTime),
120
+ personId: params.personId ?? accessor.get(UserManagerService).getCurrentUser().userID,
121
+ startOffset: range.startOffset,
122
+ endOffset: range.endOffset,
123
+ segmentId: range.segmentId,
124
+ collapsed: false
125
+ };
126
+ const prepared = await prepareDocTextRangeComment(accessor, {
127
+ unitId: params.unitId,
128
+ range,
129
+ comment
130
+ });
131
+ if (!prepared) return false;
132
+ return (await sequenceExecute([prepared.commentMutation, {
133
+ id: AddDocCommentDecorationMutation.id,
134
+ params: prepared.decorationMutationParams
135
+ }], accessor.get(ICommandService))).result;
136
+ }
137
+ };
138
+
139
+ //#endregion
140
+ //#region package.json
141
+ var name = "@univerjs/docs-thread-comment";
142
+ var version = "1.0.0-rc.0";
143
+
144
+ //#endregion
145
+ //#region src/config/config.ts
146
+ /**
147
+ * Copyright 2023-present DreamNum Co., Ltd.
148
+ *
149
+ * Licensed under the Apache License, Version 2.0 (the "License");
150
+ * you may not use this file except in compliance with the License.
151
+ * You may obtain a copy of the License at
152
+ *
153
+ * http://www.apache.org/licenses/LICENSE-2.0
154
+ *
155
+ * Unless required by applicable law or agreed to in writing, software
156
+ * distributed under the License is distributed on an "AS IS" BASIS,
157
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158
+ * See the License for the specific language governing permissions and
159
+ * limitations under the License.
160
+ */
161
+ const DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "docs-thread-comment.config";
162
+ const configSymbol = Symbol(DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
163
+ const defaultPluginConfig = {};
164
+
165
+ //#endregion
166
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
167
+ function __decorateParam(paramIndex, decorator) {
168
+ return function(target, key) {
169
+ decorator(target, key, paramIndex);
170
+ };
171
+ }
172
+
173
+ //#endregion
174
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
175
+ function __decorate(decorators, target, key, desc) {
176
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
177
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
178
+ 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;
179
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
180
+ }
181
+
182
+ //#endregion
183
+ //#region src/controllers/docs-thread-comment-resource.controller.ts
184
+ /**
185
+ * Copyright 2023-present DreamNum Co., Ltd.
186
+ *
187
+ * Licensed under the Apache License, Version 2.0 (the "License");
188
+ * you may not use this file except in compliance with the License.
189
+ * You may obtain a copy of the License at
190
+ *
191
+ * http://www.apache.org/licenses/LICENSE-2.0
192
+ *
193
+ * Unless required by applicable law or agreed to in writing, software
194
+ * distributed under the License is distributed on an "AS IS" BASIS,
195
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196
+ * See the License for the specific language governing permissions and
197
+ * limitations under the License.
198
+ */
199
+ const DOC_UNIVER_THREAD_COMMENT_PLUGIN = `DOC_${TC_PLUGIN_NAME}`;
200
+ let DocsThreadCommentResourceController = class DocsThreadCommentResourceController extends Disposable {
201
+ constructor(_resourceManagerService, _threadCommentModel, _threadCommentDataSourceService) {
202
+ super();
203
+ this._resourceManagerService = _resourceManagerService;
204
+ this._threadCommentModel = _threadCommentModel;
205
+ this._threadCommentDataSourceService = _threadCommentDataSourceService;
206
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource(createThreadCommentResourceHook(this._threadCommentModel, this._threadCommentDataSourceService, DOC_UNIVER_THREAD_COMMENT_PLUGIN, [UniverInstanceType.UNIVER_DOC])));
207
+ }
208
+ };
209
+ DocsThreadCommentResourceController = __decorate([
210
+ __decorateParam(0, IResourceManagerService),
211
+ __decorateParam(1, Inject(ThreadCommentModel)),
212
+ __decorateParam(2, IThreadCommentDataSourceService)
213
+ ], DocsThreadCommentResourceController);
214
+
215
+ //#endregion
216
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
217
+ function _typeof(o) {
218
+ "@babel/helpers - typeof";
219
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
220
+ return typeof o;
221
+ } : function(o) {
222
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
223
+ }, _typeof(o);
224
+ }
225
+
226
+ //#endregion
227
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
228
+ function toPrimitive(t, r) {
229
+ if ("object" != _typeof(t) || !t) return t;
230
+ var e = t[Symbol.toPrimitive];
231
+ if (void 0 !== e) {
232
+ var i = e.call(t, r || "default");
233
+ if ("object" != _typeof(i)) return i;
234
+ throw new TypeError("@@toPrimitive must return a primitive value.");
235
+ }
236
+ return ("string" === r ? String : Number)(t);
237
+ }
238
+
239
+ //#endregion
240
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
241
+ function toPropertyKey(t) {
242
+ var i = toPrimitive(t, "string");
243
+ return "symbol" == _typeof(i) ? i : i + "";
244
+ }
245
+
246
+ //#endregion
247
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
248
+ function _defineProperty(e, r, t) {
249
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
250
+ value: t,
251
+ enumerable: !0,
252
+ configurable: !0,
253
+ writable: !0
254
+ }) : e[r] = t, e;
255
+ }
256
+
257
+ //#endregion
258
+ //#region src/plugin.ts
259
+ let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends Plugin {
260
+ constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
261
+ super();
262
+ this._config = _config;
263
+ this._injector = _injector;
264
+ this._configService = _configService;
265
+ this._commandService = _commandService;
266
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
267
+ this._configService.setConfig(DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY, rest);
268
+ }
269
+ onStarting() {
270
+ this._injector.add([DocsThreadCommentResourceController]);
271
+ this._injector.get(DocsThreadCommentResourceController);
272
+ this.disposeWithMe(this._commandService.registerCommand(CreateDocTextRangeCommentCommand));
273
+ this.disposeWithMe(this._commandService.registerCommand(AddDocCommentDecorationMutation));
274
+ }
275
+ };
276
+ _defineProperty(UniverDocsThreadCommentPlugin, "pluginName", DOCS_THREAD_COMMENT_PLUGIN_NAME);
277
+ _defineProperty(UniverDocsThreadCommentPlugin, "packageName", name);
278
+ _defineProperty(UniverDocsThreadCommentPlugin, "version", version);
279
+ _defineProperty(UniverDocsThreadCommentPlugin, "type", UniverInstanceType.UNIVER_DOC);
280
+ UniverDocsThreadCommentPlugin = __decorate([
281
+ DependentOn(UniverDocsPlugin, UniverThreadCommentPlugin),
282
+ __decorateParam(1, Inject(Injector)),
283
+ __decorateParam(2, IConfigService),
284
+ __decorateParam(3, ICommandService)
285
+ ], UniverDocsThreadCommentPlugin);
286
+
287
+ //#endregion
288
+ export { AddDocCommentDecorationMutation, CreateDocTextRangeCommentCommand, DEFAULT_DOC_SUBUNIT_ID, UniverDocsThreadCommentPlugin, prepareDocTextRangeComment };
package/lib/facade.js ADDED
@@ -0,0 +1,53 @@
1
+ import { CustomDecorationType, ICommandService } from "@univerjs/core";
2
+ import * as DocsThreadComment from "@univerjs/docs-thread-comment";
3
+ import * as DocsFacade from "@univerjs/docs/facade";
4
+ import * as ThreadComment from "@univerjs/thread-comment";
5
+
6
+ //#region src/facade/f-document-text-range.ts
7
+ var FDocumentTextRangeThreadCommentMixin = class extends DocsFacade.FDocumentTextRange {
8
+ _initialize(injector) {
9
+ this._threadCommentCommandService = injector.get(ICommandService);
10
+ let commentService;
11
+ Object.defineProperty(this, "_threadCommentFacadeService", { get: () => commentService ??= injector.get(ThreadComment.ThreadCommentFacadeService) });
12
+ }
13
+ /** @inheritdoc */
14
+ createCommentAsync(content, options = {}) {
15
+ return this._threadCommentCommandService.executeCommand(DocsThreadComment.CreateDocTextRangeCommentCommand.id, {
16
+ ...options,
17
+ unitId: this._document.getId(),
18
+ range: {
19
+ ...this.getRange(),
20
+ collapsed: false
21
+ },
22
+ content
23
+ });
24
+ }
25
+ /** @inheritdoc */
26
+ getComments() {
27
+ const range = this.getRange();
28
+ const commentIds = this._getOverlappingCommentIds(range);
29
+ return this._threadCommentFacadeService.getComments({
30
+ unitIds: [this._document.getId()],
31
+ subUnitIds: [DocsThreadComment.DEFAULT_DOC_SUBUNIT_ID],
32
+ anchorKinds: [ThreadComment.ThreadCommentAnchorKind.DOC_TEXT_RANGE]
33
+ }).filter((comment) => commentIds.has(comment.root.id));
34
+ }
35
+ /** @inheritdoc */
36
+ async listCommentsAsync() {
37
+ const range = this.getRange();
38
+ const commentIds = this._getOverlappingCommentIds(range);
39
+ return (await this._threadCommentFacadeService.listCommentsAsync({
40
+ unitIds: [this._document.getId()],
41
+ subUnitIds: [DocsThreadComment.DEFAULT_DOC_SUBUNIT_ID],
42
+ anchorKinds: [ThreadComment.ThreadCommentAnchorKind.DOC_TEXT_RANGE]
43
+ })).filter((comment) => commentIds.has(comment.root.id));
44
+ }
45
+ _getOverlappingCommentIds(range) {
46
+ const decorations = this._document.getBody(range.segmentId).customDecorations ?? [];
47
+ return new Set(decorations.filter((decoration) => decoration.type === CustomDecorationType.COMMENT && decoration.startIndex < range.endOffset && decoration.endIndex >= range.startOffset).map((decoration) => decoration.id));
48
+ }
49
+ };
50
+ DocsFacade.FDocumentTextRange.extend(FDocumentTextRangeThreadCommentMixin);
51
+
52
+ //#endregion
53
+ export { };
package/lib/index.js ADDED
@@ -0,0 +1,288 @@
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";
4
+
5
+ //#region src/common/const.ts
6
+ /**
7
+ * Copyright 2023-present DreamNum Co., Ltd.
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ /** Stable subunit used by document text comments. */
22
+ const DEFAULT_DOC_SUBUNIT_ID = "default_doc";
23
+ const DOCS_THREAD_COMMENT_PLUGIN_NAME = "DOC_THREAD_COMMENT_PLUGIN";
24
+
25
+ //#endregion
26
+ //#region src/commands/commands/create-doc-text-range-comment.command.ts
27
+ /** Applies document comment decoration actions without render or selection services. */
28
+ const AddDocCommentDecorationMutation = {
29
+ id: "docs-thread-comment.mutation.add-decoration",
30
+ type: CommandType.MUTATION,
31
+ handler(accessor, params) {
32
+ if (!params || JSONX.isNoop(params.actions)) return false;
33
+ const document = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
34
+ if (!document) return false;
35
+ const undoActions = JSONX.invertWithDoc(params.actions, document.getSnapshot());
36
+ document.apply(params.actions);
37
+ return {
38
+ ...params,
39
+ actions: undoActions
40
+ };
41
+ }
42
+ };
43
+ function getValidRange(accessor, unitId, range) {
44
+ var _document$getSelfOrHe;
45
+ const { startOffset, endOffset } = range;
46
+ if (!Number.isInteger(startOffset) || !Number.isInteger(endOffset) || startOffset < 0 || endOffset <= startOffset) return null;
47
+ const document = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
48
+ const body = document === null || document === void 0 || (_document$getSelfOrHe = document.getSelfOrHeaderFooterModel(range.segmentId)) === null || _document$getSelfOrHe === void 0 ? void 0 : _document$getSelfOrHe.getBody();
49
+ if (!body || endOffset > body.dataStream.length) return null;
50
+ return {
51
+ ...range,
52
+ startOffset,
53
+ endOffset,
54
+ collapsed: false
55
+ };
56
+ }
57
+ /** Builds the model mutations shared by headless and UI document comment commands. */
58
+ async function prepareDocTextRangeComment(accessor, params) {
59
+ const range = getValidRange(accessor, params.unitId, params.range);
60
+ if (!range) return null;
61
+ const savedComment = await accessor.get(IThreadCommentDataSourceService).addComment(params.comment);
62
+ const comment = {
63
+ ...params.comment,
64
+ ...savedComment,
65
+ unitId: params.unitId,
66
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
67
+ startOffset: range.startOffset,
68
+ endOffset: range.endOffset,
69
+ segmentId: range.segmentId,
70
+ collapsed: false
71
+ };
72
+ const textX = BuildTextUtils.customDecoration.add({
73
+ ranges: [range],
74
+ id: comment.id,
75
+ type: CustomDecorationType.COMMENT
76
+ });
77
+ const decorationMutationParams = {
78
+ unitId: params.unitId,
79
+ actions: JSONX.getInstance().editOp(textX.serialize()),
80
+ segmentId: range.segmentId
81
+ };
82
+ return {
83
+ comment,
84
+ commentMutation: {
85
+ id: AddCommentMutation.id,
86
+ params: {
87
+ unitId: params.unitId,
88
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
89
+ comment
90
+ }
91
+ },
92
+ decorationMutationParams
93
+ };
94
+ }
95
+ /**
96
+ * Creates a root comment and document decoration for an explicit text range.
97
+ * This model command is safe to execute without loading document UI packages.
98
+ */
99
+ const CreateDocTextRangeCommentCommand = {
100
+ id: "docs.command.create-text-range-comment",
101
+ type: CommandType.COMMAND,
102
+ async handler(accessor, params) {
103
+ var _document$getSelfOrHe2;
104
+ if (!params) return false;
105
+ const range = getValidRange(accessor, params.unitId, params.range);
106
+ if (!range) return false;
107
+ const document = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
108
+ const body = document === null || document === void 0 || (_document$getSelfOrHe2 = document.getSelfOrHeaderFooterModel(range.segmentId)) === null || _document$getSelfOrHe2 === void 0 ? void 0 : _document$getSelfOrHe2.getBody();
109
+ if (!body) return false;
110
+ const id = params.id ?? generateRandomId();
111
+ const comment = {
112
+ id,
113
+ threadId: params.threadId ?? id,
114
+ unitId: params.unitId,
115
+ subUnitId: DEFAULT_DOC_SUBUNIT_ID,
116
+ ref: BuildTextUtils.transform.getPlainText(body.dataStream.slice(range.startOffset, range.endOffset)),
117
+ text: normalizeThreadCommentContent(params.content),
118
+ attachments: params.attachments ?? [],
119
+ dT: getDT(params.dateTime),
120
+ personId: params.personId ?? accessor.get(UserManagerService).getCurrentUser().userID,
121
+ startOffset: range.startOffset,
122
+ endOffset: range.endOffset,
123
+ segmentId: range.segmentId,
124
+ collapsed: false
125
+ };
126
+ const prepared = await prepareDocTextRangeComment(accessor, {
127
+ unitId: params.unitId,
128
+ range,
129
+ comment
130
+ });
131
+ if (!prepared) return false;
132
+ return (await sequenceExecute([prepared.commentMutation, {
133
+ id: AddDocCommentDecorationMutation.id,
134
+ params: prepared.decorationMutationParams
135
+ }], accessor.get(ICommandService))).result;
136
+ }
137
+ };
138
+
139
+ //#endregion
140
+ //#region package.json
141
+ var name = "@univerjs/docs-thread-comment";
142
+ var version = "1.0.0-rc.0";
143
+
144
+ //#endregion
145
+ //#region src/config/config.ts
146
+ /**
147
+ * Copyright 2023-present DreamNum Co., Ltd.
148
+ *
149
+ * Licensed under the Apache License, Version 2.0 (the "License");
150
+ * you may not use this file except in compliance with the License.
151
+ * You may obtain a copy of the License at
152
+ *
153
+ * http://www.apache.org/licenses/LICENSE-2.0
154
+ *
155
+ * Unless required by applicable law or agreed to in writing, software
156
+ * distributed under the License is distributed on an "AS IS" BASIS,
157
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158
+ * See the License for the specific language governing permissions and
159
+ * limitations under the License.
160
+ */
161
+ const DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY = "docs-thread-comment.config";
162
+ const configSymbol = Symbol(DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY);
163
+ const defaultPluginConfig = {};
164
+
165
+ //#endregion
166
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
167
+ function __decorateParam(paramIndex, decorator) {
168
+ return function(target, key) {
169
+ decorator(target, key, paramIndex);
170
+ };
171
+ }
172
+
173
+ //#endregion
174
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
175
+ function __decorate(decorators, target, key, desc) {
176
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
177
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
178
+ 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;
179
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
180
+ }
181
+
182
+ //#endregion
183
+ //#region src/controllers/docs-thread-comment-resource.controller.ts
184
+ /**
185
+ * Copyright 2023-present DreamNum Co., Ltd.
186
+ *
187
+ * Licensed under the Apache License, Version 2.0 (the "License");
188
+ * you may not use this file except in compliance with the License.
189
+ * You may obtain a copy of the License at
190
+ *
191
+ * http://www.apache.org/licenses/LICENSE-2.0
192
+ *
193
+ * Unless required by applicable law or agreed to in writing, software
194
+ * distributed under the License is distributed on an "AS IS" BASIS,
195
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196
+ * See the License for the specific language governing permissions and
197
+ * limitations under the License.
198
+ */
199
+ const DOC_UNIVER_THREAD_COMMENT_PLUGIN = `DOC_${TC_PLUGIN_NAME}`;
200
+ let DocsThreadCommentResourceController = class DocsThreadCommentResourceController extends Disposable {
201
+ constructor(_resourceManagerService, _threadCommentModel, _threadCommentDataSourceService) {
202
+ super();
203
+ this._resourceManagerService = _resourceManagerService;
204
+ this._threadCommentModel = _threadCommentModel;
205
+ this._threadCommentDataSourceService = _threadCommentDataSourceService;
206
+ this.disposeWithMe(this._resourceManagerService.registerPluginResource(createThreadCommentResourceHook(this._threadCommentModel, this._threadCommentDataSourceService, DOC_UNIVER_THREAD_COMMENT_PLUGIN, [UniverInstanceType.UNIVER_DOC])));
207
+ }
208
+ };
209
+ DocsThreadCommentResourceController = __decorate([
210
+ __decorateParam(0, IResourceManagerService),
211
+ __decorateParam(1, Inject(ThreadCommentModel)),
212
+ __decorateParam(2, IThreadCommentDataSourceService)
213
+ ], DocsThreadCommentResourceController);
214
+
215
+ //#endregion
216
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
217
+ function _typeof(o) {
218
+ "@babel/helpers - typeof";
219
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
220
+ return typeof o;
221
+ } : function(o) {
222
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
223
+ }, _typeof(o);
224
+ }
225
+
226
+ //#endregion
227
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
228
+ function toPrimitive(t, r) {
229
+ if ("object" != _typeof(t) || !t) return t;
230
+ var e = t[Symbol.toPrimitive];
231
+ if (void 0 !== e) {
232
+ var i = e.call(t, r || "default");
233
+ if ("object" != _typeof(i)) return i;
234
+ throw new TypeError("@@toPrimitive must return a primitive value.");
235
+ }
236
+ return ("string" === r ? String : Number)(t);
237
+ }
238
+
239
+ //#endregion
240
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
241
+ function toPropertyKey(t) {
242
+ var i = toPrimitive(t, "string");
243
+ return "symbol" == _typeof(i) ? i : i + "";
244
+ }
245
+
246
+ //#endregion
247
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
248
+ function _defineProperty(e, r, t) {
249
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
250
+ value: t,
251
+ enumerable: !0,
252
+ configurable: !0,
253
+ writable: !0
254
+ }) : e[r] = t, e;
255
+ }
256
+
257
+ //#endregion
258
+ //#region src/plugin.ts
259
+ let UniverDocsThreadCommentPlugin = class UniverDocsThreadCommentPlugin extends Plugin {
260
+ constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
261
+ super();
262
+ this._config = _config;
263
+ this._injector = _injector;
264
+ this._configService = _configService;
265
+ this._commandService = _commandService;
266
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
267
+ this._configService.setConfig(DOCS_THREAD_COMMENT_PLUGIN_CONFIG_KEY, rest);
268
+ }
269
+ onStarting() {
270
+ this._injector.add([DocsThreadCommentResourceController]);
271
+ this._injector.get(DocsThreadCommentResourceController);
272
+ this.disposeWithMe(this._commandService.registerCommand(CreateDocTextRangeCommentCommand));
273
+ this.disposeWithMe(this._commandService.registerCommand(AddDocCommentDecorationMutation));
274
+ }
275
+ };
276
+ _defineProperty(UniverDocsThreadCommentPlugin, "pluginName", DOCS_THREAD_COMMENT_PLUGIN_NAME);
277
+ _defineProperty(UniverDocsThreadCommentPlugin, "packageName", name);
278
+ _defineProperty(UniverDocsThreadCommentPlugin, "version", version);
279
+ _defineProperty(UniverDocsThreadCommentPlugin, "type", UniverInstanceType.UNIVER_DOC);
280
+ UniverDocsThreadCommentPlugin = __decorate([
281
+ DependentOn(UniverDocsPlugin, UniverThreadCommentPlugin),
282
+ __decorateParam(1, Inject(Injector)),
283
+ __decorateParam(2, IConfigService),
284
+ __decorateParam(3, ICommandService)
285
+ ], UniverDocsThreadCommentPlugin);
286
+
287
+ //#endregion
288
+ export { AddDocCommentDecorationMutation, CreateDocTextRangeCommentCommand, DEFAULT_DOC_SUBUNIT_ID, UniverDocsThreadCommentPlugin, prepareDocTextRangeComment };
@@ -0,0 +1,52 @@
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 { IAccessor, ICommand, IMutation, IMutationInfo, ITextRangeParam, JSONXActions } from '@univerjs/core';
17
+ import type { IThreadComment, ThreadCommentContent } from '@univerjs/thread-comment';
18
+ export interface IAddDocTextRangeCommentParams {
19
+ unitId: string;
20
+ comment: IThreadComment;
21
+ range: ITextRangeParam;
22
+ }
23
+ /** Parameters accepted by the document text-range Facade. */
24
+ export interface ICreateDocTextRangeCommentParams {
25
+ unitId: string;
26
+ range: ITextRangeParam;
27
+ content: ThreadCommentContent;
28
+ attachments?: string[];
29
+ id?: string;
30
+ threadId?: string;
31
+ personId?: string;
32
+ dateTime?: Date;
33
+ }
34
+ export interface IPreparedDocTextRangeComment {
35
+ comment: IThreadComment;
36
+ commentMutation: IMutationInfo;
37
+ decorationMutationParams: IDocCommentDecorationMutationParams;
38
+ }
39
+ export interface IDocCommentDecorationMutationParams {
40
+ unitId: string;
41
+ actions: JSONXActions;
42
+ segmentId?: string;
43
+ }
44
+ /** Applies document comment decoration actions without render or selection services. */
45
+ export declare const AddDocCommentDecorationMutation: IMutation<IDocCommentDecorationMutationParams, IDocCommentDecorationMutationParams | false>;
46
+ /** Builds the model mutations shared by headless and UI document comment commands. */
47
+ export declare function prepareDocTextRangeComment(accessor: IAccessor, params: IAddDocTextRangeCommentParams): Promise<IPreparedDocTextRangeComment | null>;
48
+ /**
49
+ * Creates a root comment and document decoration for an explicit text range.
50
+ * This model command is safe to execute without loading document UI packages.
51
+ */
52
+ export declare const CreateDocTextRangeCommentCommand: ICommand<ICreateDocTextRangeCommentParams>;