@sequent-org/moodboard 1.4.2 → 1.4.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequent-org/moodboard",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -18,8 +18,6 @@ export class HistoryManager {
18
18
  // Флаг для предотвращения зацикливания при undo/redo
19
19
  this.isExecutingCommand = false;
20
20
  this._listenersAttached = false;
21
- this._onUndo = () => this.undo();
22
- this._onRedo = () => this.redo();
23
21
  this._onDebug = () => this.debugHistory();
24
22
 
25
23
  this.initEventListeners();
@@ -28,10 +26,6 @@ export class HistoryManager {
28
26
  initEventListeners() {
29
27
  if (this._listenersAttached) return;
30
28
  this._listenersAttached = true;
31
- // Слушаем события клавиатуры
32
- this.eventBus.on(Events.Keyboard.Undo, this._onUndo);
33
- this.eventBus.on(Events.Keyboard.Redo, this._onRedo);
34
-
35
29
  // Для отладки
36
30
  this.eventBus.on(Events.History.Debug, this._onDebug);
37
31
  }
@@ -253,8 +247,6 @@ export class HistoryManager {
253
247
  */
254
248
  destroy() {
255
249
  this.clear();
256
- this.eventBus.off(Events.Keyboard.Undo, this._onUndo);
257
- this.eventBus.off(Events.Keyboard.Redo, this._onRedo);
258
250
  this.eventBus.off(Events.History.Debug, this._onDebug);
259
251
  this._listenersAttached = false;
260
252
  }
@@ -133,6 +133,7 @@ export class SaveManager {
133
133
  // Эмитируем событие успешного сохранения
134
134
  this.eventBus.emit(Events.Save.Success, {
135
135
  data: saveData,
136
+ response,
136
137
  timestamp: new Date().toISOString()
137
138
  });
138
139
  } else {
package/src/core/index.js CHANGED
@@ -226,13 +226,6 @@ export class CoreMoodBoard {
226
226
  historySize: data.historySize,
227
227
  });
228
228
  }
229
-
230
-
231
- // Можно здесь обновить состояние кнопок Undo/Redo в UI
232
- this.eventBus.emit(Events.UI.UpdateHistoryButtons, {
233
- canUndo: data.canUndo,
234
- canRedo: data.canRedo
235
- });
236
229
  });
237
230
  }
238
231
 
@@ -10,11 +10,11 @@ export class KeyboardSelectionActions {
10
10
  switch (actionId) {
11
11
  case 'undo':
12
12
  return () => {
13
- this.eventBus.emit(Events.Keyboard.Undo);
13
+ this.eventBus.emit(Events.UI.LoadPrevVersion);
14
14
  };
15
15
  case 'redo':
16
16
  return () => {
17
- this.eventBus.emit(Events.Keyboard.Redo);
17
+ this.eventBus.emit(Events.UI.LoadNextVersion);
18
18
  };
19
19
  case 'select-all':
20
20
  return () => {
@@ -154,8 +154,17 @@ export function bindSaveCallbacks(board) {
154
154
  return;
155
155
  }
156
156
 
157
- if (typeof board.options.onSave === 'function') {
158
- board.coreMoodboard.eventBus.on('save:success', (data) => {
157
+ board.coreMoodboard.eventBus.on('save:success', (data) => {
158
+ const savedVersion = Number(data?.response?.historyVersion);
159
+ if (Number.isFinite(savedVersion) && savedVersion > 0) {
160
+ board.currentLoadedVersion = savedVersion;
161
+ board.coreMoodboard.eventBus.emit(Events.UI.UpdateHistoryButtons, {
162
+ canUndo: savedVersion > 1,
163
+ canRedo: false,
164
+ });
165
+ }
166
+
167
+ if (typeof board.options.onSave === 'function') {
159
168
  try {
160
169
  let screenshot = null;
161
170
  if (board.coreMoodboard.pixi && board.coreMoodboard.pixi.app && board.coreMoodboard.pixi.app.view) {
@@ -171,9 +180,11 @@ export function bindSaveCallbacks(board) {
171
180
  } catch (error) {
172
181
  console.warn('⚠️ Ошибка в коллбеке onSave:', error);
173
182
  }
174
- });
183
+ }
184
+ });
175
185
 
176
- board.coreMoodboard.eventBus.on('save:error', (data) => {
186
+ board.coreMoodboard.eventBus.on('save:error', (data) => {
187
+ if (typeof board.options.onSave === 'function') {
177
188
  try {
178
189
  board.options.onSave({
179
190
  success: false,
@@ -183,6 +194,6 @@ export function bindSaveCallbacks(board) {
183
194
  } catch (error) {
184
195
  console.warn('⚠️ Ошибка в коллбеке onSave:', error);
185
196
  }
186
- });
187
- }
197
+ }
198
+ });
188
199
  }
@@ -17,6 +17,21 @@ export function getCsrfToken(board) {
17
17
  || '';
18
18
  }
19
19
 
20
+ function resolveMoodboardApiBase(board) {
21
+ const raw = String(board?.options?.apiUrl || '').trim();
22
+ if (!raw) return '/api/v2/moodboard';
23
+
24
+ // Совместимость с legacy конфигом: /api/moodboard -> /api/v2/moodboard
25
+ if (raw.endsWith('/api/moodboard')) {
26
+ return raw.replace(/\/api\/moodboard$/, '/api/v2/moodboard');
27
+ }
28
+ if (raw.endsWith('/api/moodboard/')) {
29
+ return raw.replace(/\/api\/moodboard\/$/, '/api/v2/moodboard/');
30
+ }
31
+
32
+ return raw;
33
+ }
34
+
20
35
  function normalizeLoadedPayload(payload, moodboardIdFallback) {
21
36
  const state = (payload?.state && typeof payload.state === 'object')
22
37
  ? payload.state
@@ -47,11 +62,12 @@ export async function loadExistingBoard(board, version = null, options = {}) {
47
62
  return;
48
63
  }
49
64
 
50
- console.log(`📦 MoodBoard: загружаем доску ${boardId} с ${board.options.apiUrl}`);
65
+ const apiBase = resolveMoodboardApiBase(board);
66
+ console.log(`📦 MoodBoard: загружаем доску ${boardId} с ${apiBase}`);
51
67
 
52
- const baseUrl = board.options.apiUrl.endsWith('/')
53
- ? `${board.options.apiUrl}${boardId}`
54
- : `${board.options.apiUrl}/${boardId}`;
68
+ const baseUrl = apiBase.endsWith('/')
69
+ ? `${apiBase}${boardId}`
70
+ : `${apiBase}/${boardId}`;
55
71
  const loadUrl = Number.isFinite(version) ? `${baseUrl}/${version}` : baseUrl;
56
72
 
57
73
  const response = await fetch(loadUrl, {