@sequent-org/moodboard 1.4.3 → 1.4.4
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
|
@@ -91,40 +91,25 @@ export function bindToolbarEvents(board) {
|
|
|
91
91
|
if (!moodboardId) return;
|
|
92
92
|
if (!Number.isFinite(targetVersion) || targetVersion < 1) return;
|
|
93
93
|
try {
|
|
94
|
-
await board.loadFromApi(moodboardId, targetVersion, {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const restoreSnapshot = board.coreMoodboard?.getBoardData?.();
|
|
99
|
-
if (restoreSnapshot && board.coreMoodboard?.apiClient) {
|
|
100
|
-
const saveResult = await board.coreMoodboard.apiClient.saveBoard(
|
|
101
|
-
moodboardId,
|
|
102
|
-
restoreSnapshot,
|
|
103
|
-
{ actionType: 'history_restore' }
|
|
104
|
-
);
|
|
105
|
-
const restoredVersion = Number(saveResult?.historyVersion);
|
|
106
|
-
if (Number.isFinite(restoredVersion) && restoredVersion > 0) {
|
|
107
|
-
board.currentLoadedVersion = restoredVersion;
|
|
108
|
-
board.coreMoodboard.eventBus.emit(Events.UI.UpdateHistoryButtons, {
|
|
109
|
-
canUndo: restoredVersion > 1,
|
|
110
|
-
canRedo: false,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
94
|
+
await board.loadFromApi(moodboardId, targetVersion, {
|
|
95
|
+
fallbackToSeedOnError: false,
|
|
96
|
+
historyNavigation: true,
|
|
97
|
+
});
|
|
114
98
|
} catch (error) {
|
|
115
99
|
console.warn(`⚠️ Не удалось загрузить версию ${targetVersion}:`, error?.message || error);
|
|
116
100
|
}
|
|
117
101
|
};
|
|
118
102
|
|
|
119
103
|
board.coreMoodboard.eventBus.on(Events.UI.LoadPrevVersion, () => {
|
|
120
|
-
const current = Number(board.
|
|
104
|
+
const current = Number(board.historyCursorVersion);
|
|
121
105
|
if (!Number.isFinite(current) || current <= 1) return;
|
|
122
106
|
loadVersion(current - 1);
|
|
123
107
|
});
|
|
124
108
|
|
|
125
109
|
board.coreMoodboard.eventBus.on(Events.UI.LoadNextVersion, () => {
|
|
126
|
-
const current = Number(board.
|
|
127
|
-
|
|
110
|
+
const current = Number(board.historyCursorVersion);
|
|
111
|
+
const head = Number(board.historyHeadVersion);
|
|
112
|
+
if (!Number.isFinite(current) || !Number.isFinite(head) || current >= head) return;
|
|
128
113
|
loadVersion(current + 1);
|
|
129
114
|
});
|
|
130
115
|
}
|
|
@@ -158,6 +143,8 @@ export function bindSaveCallbacks(board) {
|
|
|
158
143
|
const savedVersion = Number(data?.response?.historyVersion);
|
|
159
144
|
if (Number.isFinite(savedVersion) && savedVersion > 0) {
|
|
160
145
|
board.currentLoadedVersion = savedVersion;
|
|
146
|
+
board.historyHeadVersion = savedVersion;
|
|
147
|
+
board.historyCursorVersion = savedVersion;
|
|
161
148
|
board.coreMoodboard.eventBus.emit(Events.UI.UpdateHistoryButtons, {
|
|
162
149
|
canUndo: savedVersion > 1,
|
|
163
150
|
canRedo: false,
|
|
@@ -51,6 +51,7 @@ function normalizeLoadedPayload(payload, moodboardIdFallback) {
|
|
|
51
51
|
|
|
52
52
|
export async function loadExistingBoard(board, version = null, options = {}) {
|
|
53
53
|
const fallbackToSeedOnError = options?.fallbackToSeedOnError !== false;
|
|
54
|
+
const historyNavigation = options?.historyNavigation === true;
|
|
54
55
|
try {
|
|
55
56
|
const boardId = board.options.boardId;
|
|
56
57
|
|
|
@@ -87,14 +88,20 @@ export async function loadExistingBoard(board, version = null, options = {}) {
|
|
|
87
88
|
|
|
88
89
|
if (apiResponse?.success && payload) {
|
|
89
90
|
const normalizedData = normalizeLoadedPayload(payload, boardId);
|
|
90
|
-
|
|
91
|
+
const loadedVersion = Number(normalizedData.version) || null;
|
|
92
|
+
board.currentLoadedVersion = loadedVersion;
|
|
93
|
+
board.historyCursorVersion = loadedVersion;
|
|
94
|
+
if (!historyNavigation) {
|
|
95
|
+
board.historyHeadVersion = loadedVersion;
|
|
96
|
+
}
|
|
91
97
|
console.log('✅ MoodBoard: данные загружены с сервера', normalizedData);
|
|
92
98
|
board.dataManager.loadData(normalizedData);
|
|
93
99
|
if (board?.coreMoodboard?.eventBus) {
|
|
100
|
+
const cursor = Number(board.historyCursorVersion);
|
|
101
|
+
const head = Number(board.historyHeadVersion);
|
|
94
102
|
board.coreMoodboard.eventBus.emit(Events.UI.UpdateHistoryButtons, {
|
|
95
|
-
canUndo: Number(
|
|
96
|
-
|
|
97
|
-
canRedo: true,
|
|
103
|
+
canUndo: Number.isFinite(cursor) && cursor > 1,
|
|
104
|
+
canRedo: Number.isFinite(cursor) && Number.isFinite(head) && cursor < head,
|
|
98
105
|
});
|
|
99
106
|
}
|
|
100
107
|
invokeOnLoad(board, { success: true, data: normalizedData });
|