@sequent-org/moodboard 1.4.32 → 1.4.34

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.
Files changed (137) hide show
  1. package/package.json +5 -1
  2. package/src/assets/fonts/inter/inter-cyrillic-400-normal.woff2 +0 -0
  3. package/src/assets/fonts/inter/inter-cyrillic-500-normal.woff2 +0 -0
  4. package/src/assets/fonts/inter/inter-latin-400-normal.woff2 +0 -0
  5. package/src/assets/fonts/inter/inter-latin-500-normal.woff2 +0 -0
  6. package/src/assets/icons/attachments.svg +3 -1
  7. package/src/assets/icons/comments.svg +2 -2
  8. package/src/assets/icons/connector.svg +6 -0
  9. package/src/assets/icons/emoji.svg +6 -1
  10. package/src/assets/icons/frame.svg +4 -1
  11. package/src/assets/icons/image.svg +5 -1
  12. package/src/assets/icons/laser.svg +1 -0
  13. package/src/assets/icons/lasso.svg +5 -0
  14. package/src/assets/icons/mindmap.svg +10 -2
  15. package/src/assets/icons/note.svg +4 -1
  16. package/src/assets/icons/pan.svg +5 -2
  17. package/src/assets/icons/pencil.svg +4 -1
  18. package/src/assets/icons/reactions.svg +5 -0
  19. package/src/assets/icons/redo.svg +3 -2
  20. package/src/assets/icons/select.svg +2 -8
  21. package/src/assets/icons/shapes.svg +5 -1
  22. package/src/assets/icons/text-add.svg +15 -1
  23. package/src/assets/icons/undo.svg +3 -2
  24. package/src/assets/reactions/1f44d.svg +20 -0
  25. package/src/assets/reactions/1f44e.svg +20 -0
  26. package/src/assets/reactions/2705.svg +20 -0
  27. package/src/assets/reactions/274c.svg +19 -0
  28. package/src/assets/reactions/2753.svg +20 -0
  29. package/src/assets/reactions/2764.svg +22 -0
  30. package/src/assets/reactions/2b50.svg +19 -0
  31. package/src/assets/reactions/plus-one.svg +25 -0
  32. package/src/core/PixiEngine.js +23 -0
  33. package/src/core/bootstrap/CoreInitializer.js +43 -0
  34. package/src/core/commands/GroupDeleteCommand.js +13 -1
  35. package/src/core/commands/UpdateShapeStyleCommand.js +121 -0
  36. package/src/core/commands/UpdateTextStyleCommand.js +17 -6
  37. package/src/core/commands/index.js +3 -0
  38. package/src/core/events/Events.js +22 -0
  39. package/src/core/flows/LayerAndViewportFlow.js +1 -0
  40. package/src/core/flows/ObjectLifecycleFlow.js +155 -7
  41. package/src/core/index.js +28 -1
  42. package/src/grid/CrossGridZoomPhases.js +3 -3
  43. package/src/initNoBundler.js +1 -1
  44. package/src/moodboard/DataManager.js +28 -0
  45. package/src/moodboard/MoodBoard.js +27 -0
  46. package/src/moodboard/bootstrap/MoodBoardInitializer.js +69 -1
  47. package/src/moodboard/bootstrap/MoodBoardUiFactory.js +22 -4
  48. package/src/moodboard/integration/MoodBoardEventBindings.js +5 -1
  49. package/src/moodboard/integration/MoodBoardLoadApi.js +10 -1
  50. package/src/moodboard/lifecycle/MoodBoardDestroyer.js +9 -0
  51. package/src/objects/ConnectorObject.js +2 -2
  52. package/src/objects/FrameObject.js +119 -59
  53. package/src/objects/ShapeObject.js +49 -74
  54. package/src/objects/shape/ShapeDrawer.js +210 -0
  55. package/src/services/ConnectorBindingResolver.js +112 -0
  56. package/src/services/ConnectorRouter.js +210 -0
  57. package/src/services/ai/ChatSessionController.js +14 -8
  58. package/src/services/comments/CommentService.js +344 -0
  59. package/src/tools/object-tools/CommentTool.js +85 -0
  60. package/src/tools/object-tools/DrawingTool.js +110 -10
  61. package/src/tools/object-tools/LaserPointerTool.js +121 -0
  62. package/src/tools/object-tools/SelectTool.js +25 -1
  63. package/src/tools/object-tools/TextTool.js +6 -1
  64. package/src/tools/object-tools/connector/ConnectorDragController.js +50 -3
  65. package/src/tools/object-tools/connector/connectorGesture.js +33 -19
  66. package/src/tools/object-tools/placement/PlacementInputRouter.js +22 -1
  67. package/src/tools/object-tools/selection/BoxSelectController.js +24 -2
  68. package/src/tools/object-tools/selection/FrameTitleInlineEditorController.js +139 -0
  69. package/src/tools/object-tools/selection/InlineEditorController.js +12 -0
  70. package/src/tools/object-tools/selection/InlineEditorDomFactory.js +36 -0
  71. package/src/tools/object-tools/selection/LassoSelectController.js +125 -0
  72. package/src/tools/object-tools/selection/MindmapInlineEditorController.js +1 -0
  73. package/src/tools/object-tools/selection/SelectInputRouter.js +64 -5
  74. package/src/tools/object-tools/selection/SelectToolLifecycleController.js +11 -1
  75. package/src/tools/object-tools/selection/SelectToolSetup.js +13 -1
  76. package/src/tools/object-tools/selection/TextEditorInteractionController.js +46 -12
  77. package/src/tools/object-tools/selection/TextEditorSyncService.js +1 -0
  78. package/src/tools/object-tools/selection/TextInlineEditorController.js +65 -6
  79. package/src/ui/CommentPopover.js +6 -0
  80. package/src/ui/CommentsBar.js +91 -0
  81. package/src/ui/ConnectorPropertiesPanel.js +150 -0
  82. package/src/ui/ContextMenu.js +25 -0
  83. package/src/ui/DrawingPropertiesPanel.js +362 -0
  84. package/src/ui/FilePropertiesPanel.js +5 -0
  85. package/src/ui/FramePropertiesPanel.js +5 -0
  86. package/src/ui/HtmlTextLayer.js +246 -66
  87. package/src/ui/NotePropertiesPanel.js +6 -0
  88. package/src/ui/ShapePropertiesPanel.js +307 -0
  89. package/src/ui/TextPropertiesPanel.js +100 -1
  90. package/src/ui/Toolbar.js +25 -2
  91. package/src/ui/Topbar.js +2 -2
  92. package/src/ui/animation/HoverLiftController.js +6 -7
  93. package/src/ui/chat/ChatComposer.js +63 -9
  94. package/src/ui/chat/ChatWindow.js +329 -166
  95. package/src/ui/comments/CommentListPanel.js +213 -0
  96. package/src/ui/comments/CommentPinLayer.js +448 -0
  97. package/src/ui/comments/CommentThreadPopover.js +539 -0
  98. package/src/ui/comments/commentFormat.js +32 -0
  99. package/src/ui/connector-properties/ConnectorPropertiesPanelBindings.js +223 -0
  100. package/src/ui/connector-properties/ConnectorPropertiesPanelEventBridge.js +114 -0
  101. package/src/ui/connector-properties/ConnectorPropertiesPanelMapper.js +144 -0
  102. package/src/ui/connector-properties/ConnectorPropertiesPanelRenderer.js +447 -0
  103. package/src/ui/connector-properties/ConnectorPropertiesPanelState.js +61 -0
  104. package/src/ui/connectors/ConnectionAnchorsLayer.js +1 -0
  105. package/src/ui/connectors/ConnectorHandlesLayer.js +321 -0
  106. package/src/ui/connectors/ConnectorLabelLayer.js +334 -0
  107. package/src/ui/connectors/ConnectorLayer.js +264 -57
  108. package/src/ui/handles/HandlesDomRenderer.js +5 -13
  109. package/src/ui/handles/HandlesEventBridge.js +1 -0
  110. package/src/ui/handles/SingleSelectionHandlesController.js +4 -0
  111. package/src/ui/mindmap/MindmapCollapseLayer.js +1 -0
  112. package/src/ui/mindmap/MindmapConnectionLayer.js +1 -0
  113. package/src/ui/mindmap/MindmapHtmlTextLayer.js +6 -0
  114. package/src/ui/shape-properties/ShapePropertiesPanelDom.js +533 -0
  115. package/src/ui/shape-properties/ShapePropertiesPanelSync.js +132 -0
  116. package/src/ui/styles/chat.css +710 -18
  117. package/src/ui/styles/index.css +1 -0
  118. package/src/ui/styles/panels.css +112 -2
  119. package/src/ui/styles/shape-properties-panel.css +250 -0
  120. package/src/ui/styles/toolbar.css +7 -2
  121. package/src/ui/styles/topbar.css +1 -1
  122. package/src/ui/styles/workspace.css +257 -6
  123. package/src/ui/text-properties/TextFormatControls.js +88 -0
  124. package/src/ui/text-properties/TextListRenderer.js +137 -0
  125. package/src/ui/text-properties/TextPropertiesPanelBindings.js +27 -0
  126. package/src/ui/text-properties/TextPropertiesPanelEventBridge.js +3 -1
  127. package/src/ui/text-properties/TextPropertiesPanelMapper.js +56 -0
  128. package/src/ui/text-properties/TextPropertiesPanelRenderer.js +24 -0
  129. package/src/ui/text-properties/TextPropertiesPanelState.js +8 -0
  130. package/src/ui/toolbar/ReactionsPopupController.js +88 -0
  131. package/src/ui/toolbar/ToolbarActionRouter.js +71 -5
  132. package/src/ui/toolbar/ToolbarPopupsController.js +120 -118
  133. package/src/ui/toolbar/ToolbarRenderer.js +9 -1
  134. package/src/ui/toolbar/ToolbarStateController.js +4 -1
  135. package/src/utils/iconLoader.js +17 -16
  136. package/src/utils/markdown.js +14 -0
  137. package/src/utils/richText.js +125 -0
@@ -0,0 +1,539 @@
1
+ import * as PIXI from 'pixi.js';
2
+ import { Events } from '../../core/events/Events.js';
3
+ import { ChatComposer } from '../chat/ChatComposer.js';
4
+
5
+ const ARROW_UP_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M5 12l7-7 7 7"/></svg>`;
6
+ const CHECKMARK_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>`;
7
+ const TRASH_SVG = `<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M6 6l1 14a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-14"/></svg>`;
8
+
9
+ const PALETTE = ['#5B5FE9', '#1E88E5', '#00A88F', '#34A853', '#F2A600', '#F2622E', '#E5484D', '#9B51E0'];
10
+
11
+ function _pluralize(n, one, two, five) {
12
+ const m = Math.abs(n) % 100;
13
+ const m1 = m % 10;
14
+ if (m >= 11 && m <= 19) return five;
15
+ if (m1 === 1) return one;
16
+ if (m1 >= 2 && m1 <= 4) return two;
17
+ return five;
18
+ }
19
+
20
+ /** Лента сообщений треда (структура как ChatMessageList, автор вместо роли). */
21
+ class CommentMessageList {
22
+ constructor(root) {
23
+ this._root = root;
24
+ this._lastCount = 0;
25
+ }
26
+
27
+ render(messages) {
28
+ if (!messages.length) {
29
+ this._root.classList.remove('is-visible');
30
+ this._root.replaceChildren();
31
+ this._lastCount = 0;
32
+ return;
33
+ }
34
+ this._root.classList.add('is-visible');
35
+ const fragment = document.createDocumentFragment();
36
+ for (const msg of messages) {
37
+ const wrap = document.createElement('div');
38
+ wrap.className = 'comment-thread-msg';
39
+
40
+ const avatarWrap = document.createElement('div');
41
+ avatarWrap.className = 'comment-thread-msg__avatar-wrap';
42
+ if (msg.authorAvatar) {
43
+ const img = document.createElement('img');
44
+ img.className = 'comment-thread-msg__avatar';
45
+ img.src = msg.authorAvatar;
46
+ img.alt = '';
47
+ avatarWrap.appendChild(img);
48
+ } else {
49
+ const initials = document.createElement('span');
50
+ initials.className = 'comment-thread-msg__initials';
51
+ initials.textContent = (msg.authorLabel || '?').charAt(0).toUpperCase();
52
+ avatarWrap.appendChild(initials);
53
+ }
54
+
55
+ const col = document.createElement('div');
56
+ col.className = 'comment-thread-msg__col';
57
+
58
+ const meta = document.createElement('div');
59
+ meta.className = 'comment-thread-msg__meta';
60
+ const name = document.createElement('span');
61
+ name.className = 'comment-thread-msg__name';
62
+ name.textContent = msg.authorLabel || 'Участник';
63
+ meta.appendChild(name);
64
+ if (msg.created_at) {
65
+ const time = document.createElement('span');
66
+ time.className = 'comment-thread-msg__time';
67
+ time.textContent = this._formatTime(msg.created_at);
68
+ meta.appendChild(time);
69
+ }
70
+
71
+ const body = document.createElement('div');
72
+ body.className = 'comment-thread-msg__body';
73
+ body.textContent = msg.content || '';
74
+
75
+ col.appendChild(meta);
76
+ col.appendChild(body);
77
+ wrap.appendChild(avatarWrap);
78
+ wrap.appendChild(col);
79
+ fragment.appendChild(wrap);
80
+ }
81
+ this._root.replaceChildren(fragment);
82
+ if (messages.length !== this._lastCount) {
83
+ this._root.scrollTop = this._root.scrollHeight;
84
+ }
85
+ this._lastCount = messages.length;
86
+ }
87
+
88
+ _formatTime(iso) {
89
+ try {
90
+ const d = new Date(iso);
91
+ const diffMs = Date.now() - d.getTime();
92
+ const diffMin = Math.floor(diffMs / 60000);
93
+ if (diffMin < 1) return 'только что';
94
+ if (diffMin < 60) return `${diffMin} ${_pluralize(diffMin, 'минуту', 'минуты', 'минут')} назад`;
95
+ const diffH = Math.floor(diffMin / 60);
96
+ if (diffH < 24) return `${diffH} ${_pluralize(diffH, 'час', 'часа', 'часов')} назад`;
97
+ const diffD = Math.floor(diffH / 24);
98
+ if (diffD < 8) return `${diffD} ${_pluralize(diffD, 'день', 'дня', 'дней')} назад`;
99
+ return d.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' });
100
+ } catch (_) {
101
+ return '';
102
+ }
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Popover треда комментариев (замена CommentPopover).
108
+ */
109
+ export class CommentThreadPopover {
110
+ constructor(container, eventBus, core, commentService) {
111
+ this.container = container;
112
+ this.eventBus = eventBus;
113
+ this.core = core;
114
+ this.commentService = commentService;
115
+ this.layer = null;
116
+ this.popover = null;
117
+ this.messageList = null;
118
+ this.composer = null;
119
+ this.currentThreadId = null;
120
+ this._draftWorld = null;
121
+ this._colorBtn = null;
122
+ this._paletteEl = null;
123
+ this._paletteOpen = false;
124
+ this._onDocMouseDown = this._onDocMouseDown.bind(this);
125
+ this._onThreadOpened = this._onThreadOpened.bind(this);
126
+ this._onRemote = () => this._refreshIfOpen();
127
+ this._onOpenDraftAt = this._onOpenDraftAt.bind(this);
128
+ this._onThreadDeleted = this._onThreadDeleted.bind(this);
129
+ }
130
+
131
+ attach() {
132
+ this.layer = document.createElement('div');
133
+ this.layer.className = 'comment-thread-popover-layer';
134
+ Object.assign(this.layer.style, {
135
+ position: 'absolute',
136
+ inset: '0',
137
+ pointerEvents: 'none',
138
+ zIndex: 26,
139
+ });
140
+ this.container.appendChild(this.layer);
141
+
142
+ this.eventBus.on(Events.Comment.ThreadOpened, this._onThreadOpened);
143
+ this.eventBus.on(Events.Comment.RemoteUpdated, this._onRemote);
144
+ this.eventBus.on(Events.Comment.MessageAdded, this._onRemote);
145
+ this.eventBus.on(Events.Comment.OpenDraftAt, this._onOpenDraftAt);
146
+ this.eventBus.on(Events.Comment.ThreadDeleted, this._onThreadDeleted);
147
+ this.eventBus.on(Events.Viewport.Changed, () => this.reposition());
148
+ this.eventBus.on(Events.Tool.PanUpdate, () => this.reposition());
149
+ this.eventBus.on(Events.UI.ZoomPercent, () => this.reposition());
150
+ }
151
+
152
+ destroy() {
153
+ this.hide();
154
+ this.eventBus.off(Events.Comment.ThreadOpened, this._onThreadOpened);
155
+ this.eventBus.off(Events.Comment.RemoteUpdated, this._onRemote);
156
+ this.eventBus.off(Events.Comment.MessageAdded, this._onRemote);
157
+ this.eventBus.off(Events.Comment.OpenDraftAt, this._onOpenDraftAt);
158
+ this.eventBus.off(Events.Comment.ThreadDeleted, this._onThreadDeleted);
159
+ if (this.layer) this.layer.remove();
160
+ this.layer = null;
161
+ if (this.composer) this.composer.destroy();
162
+ }
163
+
164
+ openDraftAt(worldPos, anchor = null) {
165
+ this._draftWorld = { ...worldPos, anchor };
166
+ this.currentThreadId = null;
167
+ this._showPopover('Новый комментарий');
168
+ this._renderMessages([]);
169
+ this.repositionAtWorld(worldPos.x, worldPos.y);
170
+ this.composer?.focus();
171
+ this.eventBus.emit(Events.Comment.DraftOpened, { x: worldPos.x, y: worldPos.y });
172
+ }
173
+
174
+ _onOpenDraftAt({ screenX, screenY }) {
175
+ const worldLayer = this.core?.pixi?.worldLayer;
176
+ if (!worldLayer) return;
177
+ const local = worldLayer.toLocal(new PIXI.Point(screenX, screenY));
178
+ this.openDraftAt({ x: local.x, y: local.y });
179
+ }
180
+
181
+ _onThreadOpened({ threadId, pinEl }) {
182
+ if (threadId == null && this._draftWorld) return;
183
+ this._draftWorld = null;
184
+ this.currentThreadId = threadId;
185
+ const thread = this.commentService.getThread(threadId);
186
+ if (!thread) return;
187
+ this._showPopover(thread.resolved ? 'Комментарий (решён)' : 'Комментарий');
188
+ this._renderThread(thread);
189
+ if (pinEl) {
190
+ this._positionNearPinEl(pinEl);
191
+ } else {
192
+ const pos = this.commentService.getThreadWorldPosition(thread, this.core);
193
+ if (pos) this.repositionAtWorld(pos.x, pos.y);
194
+ }
195
+ this.composer?.focus();
196
+ }
197
+
198
+ hide() {
199
+ this.currentThreadId = null;
200
+ const wasDraft = this._draftWorld != null;
201
+ this._draftWorld = null;
202
+ if (this.popover) this.popover.style.display = 'none';
203
+ this._closePalette();
204
+ this._disarmOutsideClose();
205
+ if (wasDraft) this.eventBus.emit(Events.Comment.DraftClosed, {});
206
+ }
207
+
208
+ reposition() {
209
+ if (!this.popover || this.popover.style.display === 'none') return;
210
+ if (this._draftWorld) {
211
+ this.repositionAtWorld(this._draftWorld.x, this._draftWorld.y);
212
+ return;
213
+ }
214
+ if (this.currentThreadId == null) return;
215
+ const thread = this.commentService.getThread(this.currentThreadId);
216
+ const pos = this.commentService.getThreadWorldPosition(thread, this.core);
217
+ if (pos) this.repositionAtWorld(pos.x, pos.y);
218
+ }
219
+
220
+ repositionAtWorld(worldX, worldY) {
221
+ if (!this.popover) return;
222
+ const pinLayer = this._worldPointToCss(worldX, worldY);
223
+ if (!pinLayer) return;
224
+ // Смещение согласовано с _positionNearPinEl: wrap находится на -14px (PIN_SIZE/2)
225
+ // от центра пина, попап — на +42px от левого края обёртки.
226
+ const left = Math.round(pinLayer.left + 28);
227
+ const top = Math.round(pinLayer.top - 14);
228
+ this.popover.style.left = `${left}px`;
229
+ this.popover.style.top = `${top}px`;
230
+ }
231
+
232
+ _positionNearPinEl(pinEl) {
233
+ if (!this.popover || !pinEl) return;
234
+ const wrap = pinEl.closest('.comment-pin-wrap') || pinEl;
235
+ const left = Math.round(parseFloat(wrap.style.left || '0') + 42);
236
+ const top = Math.round(parseFloat(wrap.style.top || '0'));
237
+ this.popover.style.left = `${left}px`;
238
+ this.popover.style.top = `${top}px`;
239
+ }
240
+
241
+ _showPopover(title) {
242
+ if (!this.layer) return;
243
+ if (!this.popover) {
244
+ this.popover = this._createPopover();
245
+ this.layer.appendChild(this.popover);
246
+ }
247
+ const titleEl = this.popover.querySelector('.comment-thread-popover__title');
248
+ if (titleEl) titleEl.textContent = title;
249
+ this.popover.classList.toggle('comment-thread-popover--draft', this.currentThreadId == null);
250
+ this.popover.style.display = 'flex';
251
+ this._armOutsideClose();
252
+ }
253
+
254
+ /**
255
+ * Подписка на закрытие по клику снаружи откладывается на следующий тик:
256
+ * попап открывается на pointerdown, а нативный mousedown того же клика
257
+ * приходит сразу после — без задержки он бы мгновенно закрыл попап.
258
+ */
259
+ _armOutsideClose() {
260
+ this._disarmOutsideClose();
261
+ this._outsideCloseTimer = setTimeout(() => {
262
+ this._outsideCloseTimer = null;
263
+ document.addEventListener('mousedown', this._onDocMouseDown, true);
264
+ }, 0);
265
+ }
266
+
267
+ _disarmOutsideClose() {
268
+ if (this._outsideCloseTimer) {
269
+ clearTimeout(this._outsideCloseTimer);
270
+ this._outsideCloseTimer = null;
271
+ }
272
+ document.removeEventListener('mousedown', this._onDocMouseDown, true);
273
+ }
274
+
275
+ _createPopover() {
276
+ const el = document.createElement('div');
277
+ el.className = 'comment-thread-popover';
278
+ Object.assign(el.style, {
279
+ position: 'absolute',
280
+ pointerEvents: 'auto',
281
+ display: 'flex',
282
+ flexDirection: 'column',
283
+ minWidth: '280px',
284
+ maxWidth: '360px',
285
+ });
286
+
287
+ // Шапка: [...] | ● | spacer | ✓ | ✕
288
+ const header = document.createElement('div');
289
+ header.className = 'comment-thread-popover__header';
290
+
291
+ // Кнопка удаления треда
292
+ const deleteBtn = document.createElement('button');
293
+ deleteBtn.type = 'button';
294
+ deleteBtn.className = 'comment-thread-popover__delete-btn';
295
+ deleteBtn.setAttribute('aria-label', 'Удалить тред');
296
+ deleteBtn.innerHTML = TRASH_SVG;
297
+ deleteBtn.addEventListener('click', () => this._onDeleteClick());
298
+
299
+ // Обёртка кружка-цвета + всплывающая палитра
300
+ const colorWrap = document.createElement('div');
301
+ colorWrap.className = 'comment-thread-popover__color-wrap';
302
+
303
+ const colorBtn = document.createElement('button');
304
+ colorBtn.type = 'button';
305
+ colorBtn.className = 'comment-thread-popover__color-btn';
306
+ colorBtn.setAttribute('aria-label', 'Цвет треда');
307
+ colorBtn.style.background = PALETTE[0];
308
+ this._colorBtn = colorBtn;
309
+
310
+ const palette = document.createElement('div');
311
+ palette.className = 'comment-thread-popover__palette';
312
+ palette.hidden = true;
313
+ for (const hex of PALETTE) {
314
+ const sw = document.createElement('button');
315
+ sw.type = 'button';
316
+ sw.className = 'comment-thread-popover__palette-swatch';
317
+ sw.style.background = hex;
318
+ sw.dataset.color = hex;
319
+ sw.addEventListener('click', () => {
320
+ if (this.currentThreadId != null) {
321
+ this.commentService.setThreadColor(this.currentThreadId, hex).catch(console.error);
322
+ }
323
+ this._setActiveSwatchByColor(hex);
324
+ this._closePalette();
325
+ });
326
+ palette.appendChild(sw);
327
+ }
328
+ this._paletteEl = palette;
329
+ colorBtn.addEventListener('click', () => this._paletteOpen ? this._closePalette() : this._openPalette());
330
+ colorWrap.appendChild(colorBtn);
331
+ colorWrap.appendChild(palette);
332
+
333
+ const spacer = document.createElement('div');
334
+ spacer.style.flex = '1';
335
+
336
+ const resolveBtn = document.createElement('button');
337
+ resolveBtn.type = 'button';
338
+ resolveBtn.className = 'comment-thread-popover__resolve';
339
+ resolveBtn.setAttribute('aria-label', 'Отметить решённым');
340
+ resolveBtn.innerHTML = CHECKMARK_SVG;
341
+ resolveBtn.addEventListener('click', () => this._toggleResolve());
342
+
343
+ const close = document.createElement('button');
344
+ close.type = 'button';
345
+ close.className = 'comment-thread-popover__close';
346
+ close.textContent = '✕';
347
+ close.addEventListener('click', () => this.hide());
348
+
349
+ header.appendChild(deleteBtn);
350
+ header.appendChild(colorWrap);
351
+ header.appendChild(spacer);
352
+ header.appendChild(resolveBtn);
353
+ header.appendChild(close);
354
+
355
+ const history = document.createElement('div');
356
+ history.className = 'moodboard-chat__history comment-thread-popover__history';
357
+
358
+ const footer = document.createElement('div');
359
+ footer.className = 'moodboard-chat__input-row comment-thread-popover__footer';
360
+ const textarea = document.createElement('textarea');
361
+ textarea.className = 'moodboard-chat__textarea';
362
+ textarea.placeholder = 'Напишите комментарий…';
363
+ textarea.rows = 2;
364
+ const send = document.createElement('button');
365
+ send.type = 'button';
366
+ send.className = 'moodboard-chat__send';
367
+ send.dataset.state = 'ready';
368
+ send.innerHTML = ARROW_UP_SVG;
369
+ footer.appendChild(textarea);
370
+ footer.appendChild(send);
371
+
372
+ el.appendChild(header);
373
+ el.appendChild(history);
374
+ el.appendChild(footer);
375
+
376
+ this.messageList = new CommentMessageList(history);
377
+ this.composer = new ChatComposer(
378
+ { textarea, send },
379
+ {
380
+ onSubmit: (text) => this._onSubmit(text),
381
+ onAbort: () => {},
382
+ }
383
+ );
384
+ this.composer.attach();
385
+ this._resolveBtn = resolveBtn;
386
+ return el;
387
+ }
388
+
389
+ _renderThread(thread) {
390
+ const messages = (thread.messages?.items || []).map((m) => this._toListMessage(m));
391
+ this._renderMessages(messages);
392
+ if (this._resolveBtn) {
393
+ this._resolveBtn.classList.toggle('comment-thread-popover__resolve--resolved', !!thread.resolved);
394
+ this._resolveBtn.setAttribute('aria-label', thread.resolved ? 'Открыть снова' : 'Отметить решённым');
395
+ }
396
+ const titleEl = this.popover?.querySelector('.comment-thread-popover__title');
397
+ if (titleEl) titleEl.textContent = thread.resolved ? 'Комментарий (решён)' : 'Комментарий';
398
+ this._setActiveSwatchByColor(thread.color || null);
399
+ }
400
+
401
+ _setActiveSwatchByColor(color) {
402
+ if (this._colorBtn) this._colorBtn.style.background = color || PALETTE[0];
403
+ if (!this._paletteEl) return;
404
+ for (const sw of this._paletteEl.querySelectorAll('.comment-thread-popover__palette-swatch')) {
405
+ sw.classList.toggle('comment-thread-popover__palette-swatch--active', sw.dataset.color === color);
406
+ }
407
+ }
408
+
409
+ _onThreadDeleted({ threadId }) {
410
+ if (String(threadId) === String(this.currentThreadId)) {
411
+ this.hide();
412
+ }
413
+ }
414
+
415
+ async _onDeleteClick() {
416
+ if (this.currentThreadId == null) return;
417
+ try {
418
+ await this.commentService.deleteThread(this.currentThreadId);
419
+ this.hide();
420
+ } catch (err) {
421
+ console.error('Comment delete failed:', err);
422
+ }
423
+ }
424
+
425
+ _renderMessages(messages) {
426
+ this.messageList?.render(messages);
427
+ }
428
+
429
+ _toListMessage(m) {
430
+ const uid = this.commentService.currentUser?.id;
431
+ const isSelf = uid != null && m.user_id != null && String(m.user_id) === String(uid);
432
+ const author = m.author_name || (isSelf ? 'Вы' : 'Участник');
433
+ const cu = this.commentService.currentUser;
434
+ const avatarUrl = m.author_avatar || (isSelf ? cu?.avatar || null : null);
435
+ return {
436
+ id: String(m.id),
437
+ role: isSelf ? 'user' : 'assistant',
438
+ content: this._stripHtml(m.content || ''),
439
+ authorLabel: author,
440
+ authorAvatar: avatarUrl || null,
441
+ created_at: m.created_at,
442
+ };
443
+ }
444
+
445
+ _stripHtml(html) {
446
+ if (!html || typeof html !== 'string') return '';
447
+ const tmp = document.createElement('div');
448
+ tmp.innerHTML = html;
449
+ return (tmp.textContent || '').trim();
450
+ }
451
+
452
+ async _onSubmit(text) {
453
+ const trimmed = text.trim();
454
+ if (!trimmed) return;
455
+ try {
456
+ if (this._draftWorld) {
457
+ const payload = {
458
+ x: this._draftWorld.x,
459
+ y: this._draftWorld.y,
460
+ content: trimmed,
461
+ };
462
+ const anchor = this._draftWorld.anchor;
463
+ if (anchor?.anchor_object_id) {
464
+ payload.anchor_object_id = anchor.anchor_object_id;
465
+ payload.anchor_dx = anchor.anchor_dx;
466
+ payload.anchor_dy = anchor.anchor_dy;
467
+ }
468
+ const thread = await this.commentService.createThread(payload);
469
+ this._draftWorld = null;
470
+ this.currentThreadId = thread?.id ?? null;
471
+ this.eventBus.emit(Events.Comment.DraftClosed, {});
472
+ if (thread) {
473
+ if (this.popover) this.popover.classList.remove('comment-thread-popover--draft');
474
+ this._renderThread(thread);
475
+ }
476
+ } else if (this.currentThreadId != null) {
477
+ await this.commentService.addReply(this.currentThreadId, trimmed);
478
+ const thread = this.commentService.getThread(this.currentThreadId);
479
+ if (thread) this._renderThread(thread);
480
+ }
481
+ } catch (err) {
482
+ console.error('Comment submit failed:', err);
483
+ }
484
+ }
485
+
486
+ async _toggleResolve() {
487
+ if (this.currentThreadId == null) return;
488
+ const thread = this.commentService.getThread(this.currentThreadId);
489
+ if (!thread) return;
490
+ try {
491
+ await this.commentService.resolveThread(this.currentThreadId, !thread.resolved);
492
+ const updated = this.commentService.getThread(this.currentThreadId);
493
+ if (updated) this._renderThread(updated);
494
+ } catch (err) {
495
+ console.error('Comment resolve failed:', err);
496
+ }
497
+ }
498
+
499
+ _refreshIfOpen() {
500
+ if (this.popover?.style.display === 'none') return;
501
+ if (this.currentThreadId != null) {
502
+ const thread = this.commentService.getThread(this.currentThreadId);
503
+ if (thread) this._renderThread(thread);
504
+ }
505
+ }
506
+
507
+ _onDocMouseDown(e) {
508
+ if (!this.popover || this.popover.style.display === 'none') return;
509
+ if (this.popover.contains(e.target)) {
510
+ if (this._paletteOpen && !this._paletteEl?.contains(e.target) && !this._colorBtn?.contains(e.target)) {
511
+ this._closePalette();
512
+ }
513
+ return;
514
+ }
515
+ this.hide();
516
+ }
517
+
518
+ _openPalette() {
519
+ if (this._paletteEl) this._paletteEl.hidden = false;
520
+ this._paletteOpen = true;
521
+ }
522
+
523
+ _closePalette() {
524
+ if (this._paletteEl) this._paletteEl.hidden = true;
525
+ this._paletteOpen = false;
526
+ }
527
+
528
+ _worldPointToCss(worldX, worldY) {
529
+ const worldLayer = this.core?.pixi?.worldLayer || this.core?.pixi?.app?.stage;
530
+ const view = this.core?.pixi?.app?.view;
531
+ if (!worldLayer || !view?.parentElement) return null;
532
+ const containerRect = this.container.getBoundingClientRect();
533
+ const viewRect = view.getBoundingClientRect();
534
+ const offsetLeft = viewRect.left - containerRect.left;
535
+ const offsetTop = viewRect.top - containerRect.top;
536
+ const g = worldLayer.toGlobal(new PIXI.Point(worldX, worldY));
537
+ return { left: offsetLeft + g.x, top: offsetTop + g.y };
538
+ }
539
+ }
@@ -0,0 +1,32 @@
1
+ export function pluralize(n, one, two, five) {
2
+ const m = Math.abs(n) % 100;
3
+ const m1 = m % 10;
4
+ if (m >= 11 && m <= 19) return five;
5
+ if (m1 === 1) return one;
6
+ if (m1 >= 2 && m1 <= 4) return two;
7
+ return five;
8
+ }
9
+
10
+ export function formatTime(iso) {
11
+ try {
12
+ const d = new Date(iso);
13
+ const diffMs = Date.now() - d.getTime();
14
+ const diffMin = Math.floor(diffMs / 60000);
15
+ if (diffMin < 1) return 'только что';
16
+ if (diffMin < 60) return `${diffMin} ${pluralize(diffMin, 'минуту', 'минуты', 'минут')} назад`;
17
+ const diffH = Math.floor(diffMin / 60);
18
+ if (diffH < 24) return `${diffH} ${pluralize(diffH, 'час', 'часа', 'часов')} назад`;
19
+ const diffD = Math.floor(diffH / 24);
20
+ if (diffD < 8) return `${diffD} ${pluralize(diffD, 'день', 'дня', 'дней')} назад`;
21
+ return d.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' });
22
+ } catch (_) {
23
+ return '';
24
+ }
25
+ }
26
+
27
+ export function stripHtml(html) {
28
+ if (!html || typeof html !== 'string') return '';
29
+ const tmp = document.createElement('div');
30
+ tmp.innerHTML = html;
31
+ return (tmp.textContent || '').trim();
32
+ }