@sequent-org/moodboard 1.2.46 → 1.2.48

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.2.46",
3
+ "version": "1.2.48",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
package/src/core/index.js CHANGED
@@ -1854,6 +1854,17 @@ export class CoreMoodBoard {
1854
1854
  requestData.data = this.getBoardData();
1855
1855
  });
1856
1856
 
1857
+ // Обновляем состояние board.grid при смене сетки
1858
+ this.eventBus.on(Events.Grid.BoardDataChanged, ({ grid }) => {
1859
+ try {
1860
+ if (grid) {
1861
+ if (!this.state.state.board) this.state.state.board = {};
1862
+ this.state.state.board.grid = grid;
1863
+ this.state.markDirty();
1864
+ }
1865
+ } catch (_) {}
1866
+ });
1867
+
1857
1868
  // Обработка статуса сохранения
1858
1869
  this.eventBus.on(Events.Save.StatusChanged, (data) => {
1859
1870
  // Можно добавить UI индикатор статуса сохранения
@@ -16,6 +16,19 @@ export class DataManager {
16
16
 
17
17
  // Очищаем доску перед загрузкой
18
18
  this.clearBoard();
19
+
20
+ // Восстанавливаем тип сетки и её параметры до загрузки объектов
21
+ try {
22
+ const grid = data.grid || (data.board && data.board.grid);
23
+ if (grid && grid.type) {
24
+ const payload = { type: grid.type };
25
+ const opts = grid.options || null;
26
+ if (opts && typeof opts === 'object') {
27
+ payload.options = opts;
28
+ }
29
+ this.coreMoodboard.eventBus.emit(this.coreMoodboard.Events?.UI?.GridChange || 'ui:grid:change', payload);
30
+ }
31
+ } catch (_) {}
19
32
 
20
33
  // Загружаем объекты
21
34
  if (data.objects && Array.isArray(data.objects)) {
@@ -24,31 +24,51 @@ export class BoardService {
24
24
  this.grid.updateVisual();
25
25
  this.pixi.setGrid(this.grid);
26
26
  this.eventBus.emit(Events.UI.GridCurrent, { type: 'line' });
27
+ // Сообщаем о текущих данных сетки для сохранения в boardData
28
+ try {
29
+ this.eventBus.emit(Events.Grid.BoardDataChanged, {
30
+ grid: { type: 'line', options: this.grid.serialize ? this.grid.serialize() : {} }
31
+ });
32
+ } catch (_) {}
27
33
 
28
34
  this._attachEvents();
29
35
  }
30
36
 
31
37
  _attachEvents() {
32
38
  // Смена вида сетки из UI
33
- this.eventBus.on(Events.UI.GridChange, ({ type }) => {
39
+ this.eventBus.on(Events.UI.GridChange, ({ type, options: overrideOptions }) => {
34
40
  const size = this._getCanvasSize?.() || { width: 800, height: 600 };
35
41
  if (type === 'off') {
36
42
  this.grid?.setEnabled(false);
37
43
  this.grid?.updateVisual();
38
44
  this.pixi.setGrid(this.grid);
45
+ // Обновляем сохранённые данные
46
+ try {
47
+ this.eventBus.emit(Events.Grid.BoardDataChanged, {
48
+ grid: { type: 'off', options: this.grid?.serialize ? this.grid.serialize() : {} }
49
+ });
50
+ } catch (_) {}
39
51
  return;
40
52
  }
41
- const options = {
53
+ const gridOptions = {
42
54
  ...GridFactory.getDefaultOptions(type),
43
55
  enabled: true,
44
56
  width: size.width,
45
- height: size.height
57
+ height: size.height,
58
+ // Перекрываем входящими опциями (если пришли из сохранения)
59
+ ...(overrideOptions || {})
46
60
  };
47
61
  try {
48
- this.grid = GridFactory.createGrid(type, options);
62
+ this.grid = GridFactory.createGrid(type, gridOptions);
49
63
  this.grid.updateVisual();
50
64
  this.pixi.setGrid(this.grid);
51
65
  this.eventBus.emit(Events.UI.GridCurrent, { type });
66
+ // Сообщаем об обновлении данных сетки для сохранения в boardData
67
+ try {
68
+ this.eventBus.emit(Events.Grid.BoardDataChanged, {
69
+ grid: { type, options: this.grid.serialize ? this.grid.serialize() : gridOptions }
70
+ });
71
+ } catch (_) {}
52
72
  } catch (e) {
53
73
  console.warn('Unknown grid type:', type);
54
74
  }