@jhits/plugin-blog 0.0.19 → 0.0.20
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/dist/api/categories.d.ts.map +1 -1
- package/dist/api/categories.js +42 -38
- package/dist/api/handler.d.ts +1 -26
- package/dist/api/handler.d.ts.map +1 -1
- package/dist/api/handler.js +81 -490
- package/dist/api/router.d.ts +0 -5
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +8 -35
- package/dist/api/service.d.ts +80 -0
- package/dist/api/service.d.ts.map +1 -0
- package/dist/api/service.js +219 -0
- package/dist/hooks/useAutoSave.d.ts +10 -0
- package/dist/hooks/useAutoSave.d.ts.map +1 -0
- package/dist/hooks/useAutoSave.js +57 -0
- package/dist/hooks/useCategories.d.ts +1 -1
- package/dist/hooks/useCategories.d.ts.map +1 -1
- package/dist/hooks/useCategories.js +15 -46
- package/dist/index.d.ts +24 -31
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -201
- package/dist/init.d.ts +20 -7
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +8 -7
- package/dist/lib/blocks/BlockRenderer.d.ts.map +1 -1
- package/dist/lib/layouts/blocks/ColumnsBlock.d.ts.map +1 -1
- package/dist/lib/layouts/blocks/ColumnsBlock.js +30 -113
- package/dist/lib/layouts/blocks/SectionBlock.d.ts.map +1 -1
- package/dist/lib/layouts/blocks/SectionBlock.js +9 -21
- package/dist/lib/layouts/index.d.ts +3 -3
- package/dist/lib/layouts/index.js +4 -4
- package/dist/lib/mappers/apiMapper.d.ts +10 -0
- package/dist/lib/mappers/apiMapper.d.ts.map +1 -1
- package/dist/lib/mappers/apiMapper.js +47 -32
- package/dist/lib/rich-text/RichTextEditor.d.ts +4 -2
- package/dist/lib/rich-text/RichTextEditor.d.ts.map +1 -1
- package/dist/lib/rich-text/RichTextEditor.js +12 -9
- package/dist/lib/utils/config-resolver.d.ts +28 -0
- package/dist/lib/utils/config-resolver.d.ts.map +1 -0
- package/dist/lib/utils/config-resolver.js +46 -0
- package/dist/lib/utils/tree.d.ts +29 -0
- package/dist/lib/utils/tree.d.ts.map +1 -0
- package/dist/lib/utils/tree.js +129 -0
- package/dist/state/EditorContext.d.ts +3 -25
- package/dist/state/EditorContext.d.ts.map +1 -1
- package/dist/state/EditorContext.js +124 -174
- package/dist/state/reducer.d.ts +1 -5
- package/dist/state/reducer.d.ts.map +1 -1
- package/dist/state/reducer.js +128 -521
- package/dist/state/types.d.ts +12 -1
- package/dist/state/types.d.ts.map +1 -1
- package/dist/types/block.d.ts +9 -0
- package/dist/types/block.d.ts.map +1 -1
- package/dist/types/post.d.ts +17 -1
- package/dist/types/post.d.ts.map +1 -1
- package/dist/views/CanvasEditor/BlockWrapper.d.ts +5 -6
- package/dist/views/CanvasEditor/BlockWrapper.d.ts.map +1 -1
- package/dist/views/CanvasEditor/BlockWrapper.js +56 -264
- package/dist/views/CanvasEditor/CanvasEditorView.d.ts +5 -3
- package/dist/views/CanvasEditor/CanvasEditorView.d.ts.map +1 -1
- package/dist/views/CanvasEditor/CanvasEditorView.js +55 -315
- package/dist/views/CanvasEditor/EditorBody.d.ts +6 -8
- package/dist/views/CanvasEditor/EditorBody.d.ts.map +1 -1
- package/dist/views/CanvasEditor/EditorBody.js +34 -482
- package/dist/views/CanvasEditor/EditorHeader.d.ts.map +1 -1
- package/dist/views/CanvasEditor/EditorHeader.js +27 -63
- package/dist/views/CanvasEditor/LayoutContainer.d.ts.map +1 -1
- package/dist/views/CanvasEditor/LayoutContainer.js +49 -70
- package/dist/views/CanvasEditor/components/CustomBlockItem.js +1 -1
- package/dist/views/CanvasEditor/components/EditorCanvas.d.ts +15 -3
- package/dist/views/CanvasEditor/components/EditorCanvas.d.ts.map +1 -1
- package/dist/views/CanvasEditor/components/EditorCanvas.js +40 -18
- package/dist/views/CanvasEditor/components/EditorLibrary.d.ts +5 -1
- package/dist/views/CanvasEditor/components/EditorLibrary.d.ts.map +1 -1
- package/dist/views/CanvasEditor/components/EditorLibrary.js +11 -7
- package/dist/views/CanvasEditor/components/EditorSidebar.d.ts.map +1 -1
- package/dist/views/CanvasEditor/components/EditorSidebar.js +32 -14
- package/dist/views/CanvasEditor/components/FeaturedMediaSection.d.ts +0 -6
- package/dist/views/CanvasEditor/components/FeaturedMediaSection.d.ts.map +1 -1
- package/dist/views/CanvasEditor/components/FeaturedMediaSection.js +17 -128
- package/dist/views/CanvasEditor/components/JSONInspector.d.ts +9 -0
- package/dist/views/CanvasEditor/components/JSONInspector.d.ts.map +1 -0
- package/dist/views/CanvasEditor/components/JSONInspector.js +56 -0
- package/dist/views/CanvasEditor/components/LibraryItem.js +2 -2
- package/dist/views/CanvasEditor/components/PrivacySettingsSection.d.ts +0 -4
- package/dist/views/CanvasEditor/components/PrivacySettingsSection.d.ts.map +1 -1
- package/dist/views/CanvasEditor/components/PrivacySettingsSection.js +6 -28
- package/dist/views/CanvasEditor/components/index.d.ts +2 -0
- package/dist/views/CanvasEditor/components/index.d.ts.map +1 -1
- package/dist/views/CanvasEditor/components/index.js +1 -0
- package/dist/views/CanvasEditor/hooks/useHeroBlock.d.ts.map +1 -1
- package/dist/views/CanvasEditor/hooks/useHeroBlock.js +15 -18
- package/dist/views/CanvasEditor/hooks/usePostLoader.d.ts +3 -0
- package/dist/views/CanvasEditor/hooks/usePostLoader.d.ts.map +1 -1
- package/dist/views/CanvasEditor/hooks/usePostLoader.js +12 -13
- package/dist/views/CanvasEditor/hooks/useUnsavedChanges.js +0 -4
- package/dist/views/PostManager/EmptyState.d.ts +1 -1
- package/dist/views/PostManager/EmptyState.js +4 -4
- package/dist/views/PostManager/FilterDropdown.d.ts +21 -0
- package/dist/views/PostManager/FilterDropdown.d.ts.map +1 -0
- package/dist/views/PostManager/FilterDropdown.js +28 -0
- package/dist/views/PostManager/LanguageFlags.d.ts.map +1 -1
- package/dist/views/PostManager/LanguageFlags.js +4 -1
- package/dist/views/PostManager/PostCards.d.ts.map +1 -1
- package/dist/views/PostManager/PostCards.js +23 -40
- package/dist/views/PostManager/PostFilters.d.ts.map +1 -1
- package/dist/views/PostManager/PostFilters.js +34 -3
- package/dist/views/PostManager/PostManagerView.d.ts +1 -2
- package/dist/views/PostManager/PostManagerView.d.ts.map +1 -1
- package/dist/views/PostManager/PostManagerView.js +30 -96
- package/dist/views/PostManager/PostStats.d.ts.map +1 -1
- package/dist/views/PostManager/PostStats.js +10 -10
- package/dist/views/PostManager/PostTable.d.ts.map +1 -1
- package/dist/views/PostManager/PostTable.js +23 -40
- package/dist/views/Settings/SettingsView.d.ts +1 -1
- package/dist/views/Settings/SettingsView.d.ts.map +1 -1
- package/dist/views/Settings/SettingsView.js +12 -39
- package/dist/views/SlugSEO/SlugSEOManagerView.d.ts.map +1 -1
- package/dist/views/SlugSEO/SlugSEOManagerView.js +2 -2
- package/package.json +42 -6
- package/src/api/categories.ts +48 -52
- package/src/api/handler.ts +87 -594
- package/src/api/router.ts +15 -65
- package/src/api/service.ts +241 -0
- package/src/hooks/useAutoSave.ts +64 -0
- package/src/hooks/useCategories.ts +19 -47
- package/src/index.tsx +79 -293
- package/src/init.tsx +24 -11
- package/src/lib/blocks/BlockRenderer.tsx +1 -0
- package/src/lib/layouts/blocks/ColumnsBlock.tsx +60 -173
- package/src/lib/layouts/blocks/SectionBlock.tsx +22 -26
- package/src/lib/layouts/index.ts +4 -4
- package/src/lib/mappers/apiMapper.ts +63 -32
- package/src/lib/rich-text/RichTextEditor.tsx +16 -9
- package/src/lib/utils/config-resolver.ts +64 -0
- package/src/lib/utils/tree.ts +150 -0
- package/src/state/EditorContext.tsx +153 -232
- package/src/state/reducer.ts +141 -606
- package/src/state/types.ts +14 -1
- package/src/types/block.ts +10 -0
- package/src/types/post.ts +19 -1
- package/src/views/CanvasEditor/BlockWrapper.tsx +130 -460
- package/src/views/CanvasEditor/CanvasEditorView.tsx +145 -420
- package/src/views/CanvasEditor/EditorBody.tsx +98 -610
- package/src/views/CanvasEditor/EditorHeader.tsx +176 -196
- package/src/views/CanvasEditor/LayoutContainer.tsx +74 -89
- package/src/views/CanvasEditor/components/CustomBlockItem.tsx +7 -8
- package/src/views/CanvasEditor/components/EditorCanvas.tsx +139 -84
- package/src/views/CanvasEditor/components/EditorLibrary.tsx +25 -10
- package/src/views/CanvasEditor/components/EditorSidebar.tsx +196 -127
- package/src/views/CanvasEditor/components/FeaturedMediaSection.tsx +78 -210
- package/src/views/CanvasEditor/components/JSONInspector.tsx +125 -0
- package/src/views/CanvasEditor/components/LibraryItem.tsx +5 -6
- package/src/views/CanvasEditor/components/PrivacySettingsSection.tsx +73 -124
- package/src/views/CanvasEditor/components/index.ts +2 -1
- package/src/views/CanvasEditor/hooks/useHeroBlock.ts +15 -18
- package/src/views/CanvasEditor/hooks/usePostLoader.ts +21 -13
- package/src/views/CanvasEditor/hooks/useUnsavedChanges.ts +4 -4
- package/src/views/PostManager/EmptyState.tsx +9 -10
- package/src/views/PostManager/FilterDropdown.tsx +95 -0
- package/src/views/PostManager/LanguageFlags.tsx +6 -2
- package/src/views/PostManager/PostCards.tsx +127 -133
- package/src/views/PostManager/PostFilters.tsx +73 -68
- package/src/views/PostManager/PostManagerView.tsx +132 -179
- package/src/views/PostManager/PostStats.tsx +21 -20
- package/src/views/PostManager/PostTable.tsx +137 -165
- package/src/views/Settings/SettingsView.tsx +64 -180
- package/src/views/SlugSEO/SlugSEOManagerView.tsx +59 -44
- package/src/hooks/index.d.ts +0 -8
- package/src/hooks/index.d.ts.map +0 -1
- package/src/hooks/useBlog.d.ts +0 -31
- package/src/hooks/useBlog.d.ts.map +0 -1
- package/src/hooks/useBlogs.d.ts +0 -39
- package/src/hooks/useBlogs.d.ts.map +0 -1
- package/src/hooks/useCategories.d.ts +0 -9
- package/src/hooks/useCategories.d.ts.map +0 -1
- package/src/lib/blocks/BlockRenderer.d.ts +0 -54
- package/src/lib/blocks/BlockRenderer.d.ts.map +0 -1
- package/src/lib/config-storage.d.ts +0 -30
- package/src/lib/config-storage.d.ts.map +0 -1
- package/src/lib/layouts/blocks/ColumnsBlock.d.ts +0 -25
- package/src/lib/layouts/blocks/ColumnsBlock.d.ts.map +0 -1
- package/src/lib/layouts/blocks/SectionBlock.d.ts +0 -25
- package/src/lib/layouts/blocks/SectionBlock.d.ts.map +0 -1
- package/src/lib/layouts/index.d.ts +0 -23
- package/src/lib/layouts/index.d.ts.map +0 -1
- package/src/lib/layouts/registerLayoutBlocks.d.ts +0 -9
- package/src/lib/layouts/registerLayoutBlocks.d.ts.map +0 -1
- package/src/lib/mappers/apiMapper.d.ts +0 -66
- package/src/lib/mappers/apiMapper.d.ts.map +0 -1
- package/src/lib/rich-text/RichTextEditor.d.ts +0 -45
- package/src/lib/rich-text/RichTextEditor.d.ts.map +0 -1
- package/src/lib/rich-text/RichTextPreview.d.ts +0 -16
- package/src/lib/rich-text/RichTextPreview.d.ts.map +0 -1
- package/src/lib/rich-text/index.d.ts +0 -9
- package/src/lib/rich-text/index.d.ts.map +0 -1
- package/src/lib/utils/blockHelpers.d.ts +0 -23
- package/src/lib/utils/blockHelpers.d.ts.map +0 -1
- package/src/lib/utils/configValidation.d.ts +0 -23
- package/src/lib/utils/configValidation.d.ts.map +0 -1
- package/src/registry/BlockRegistry.d.ts +0 -62
- package/src/registry/BlockRegistry.d.ts.map +0 -1
- package/src/registry/index.d.ts +0 -6
- package/src/registry/index.d.ts.map +0 -1
- package/src/state/EditorContext.d.ts +0 -45
- package/src/state/EditorContext.d.ts.map +0 -1
- package/src/state/index.d.ts +0 -7
- package/src/state/index.d.ts.map +0 -1
- package/src/state/reducer.d.ts +0 -11
- package/src/state/reducer.d.ts.map +0 -1
- package/src/state/types.d.ts +0 -162
- package/src/state/types.d.ts.map +0 -1
- package/src/types/block.d.ts +0 -221
- package/src/types/block.d.ts.map +0 -1
- package/src/types/index.d.ts +0 -8
- package/src/types/index.d.ts.map +0 -1
- package/src/types/post.d.ts +0 -136
- package/src/types/post.d.ts.map +0 -1
- package/src/utils/client.d.ts +0 -48
- package/src/utils/client.d.ts.map +0 -1
- package/src/views/CanvasEditor/BlockWrapper.d.ts +0 -16
- package/src/views/CanvasEditor/BlockWrapper.d.ts.map +0 -1
- package/src/views/CanvasEditor/CanvasEditorView.d.ts +0 -14
- package/src/views/CanvasEditor/CanvasEditorView.d.ts.map +0 -1
- package/src/views/CanvasEditor/EditorBody.d.ts +0 -22
- package/src/views/CanvasEditor/EditorBody.d.ts.map +0 -1
- package/src/views/CanvasEditor/EditorHeader.d.ts +0 -18
- package/src/views/CanvasEditor/EditorHeader.d.ts.map +0 -1
- package/src/views/CanvasEditor/LayoutContainer.d.ts +0 -17
- package/src/views/CanvasEditor/LayoutContainer.d.ts.map +0 -1
- package/src/views/CanvasEditor/SaveConfirmationModal.d.ts +0 -13
- package/src/views/CanvasEditor/SaveConfirmationModal.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/CustomBlockItem.d.ts +0 -14
- package/src/views/CanvasEditor/components/CustomBlockItem.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/EditorCanvas.d.ts +0 -29
- package/src/views/CanvasEditor/components/EditorCanvas.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/EditorLibrary.d.ts +0 -7
- package/src/views/CanvasEditor/components/EditorLibrary.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/EditorSidebar.d.ts +0 -13
- package/src/views/CanvasEditor/components/EditorSidebar.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/ErrorBanner.d.ts +0 -6
- package/src/views/CanvasEditor/components/ErrorBanner.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/FeaturedMediaSection.d.ts +0 -25
- package/src/views/CanvasEditor/components/FeaturedMediaSection.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/LibraryItem.d.ts +0 -14
- package/src/views/CanvasEditor/components/LibraryItem.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/PrivacySettingsSection.d.ts +0 -15
- package/src/views/CanvasEditor/components/PrivacySettingsSection.d.ts.map +0 -1
- package/src/views/CanvasEditor/components/index.d.ts +0 -21
- package/src/views/CanvasEditor/components/index.d.ts.map +0 -1
- package/src/views/CanvasEditor/hooks/index.d.ts +0 -10
- package/src/views/CanvasEditor/hooks/index.d.ts.map +0 -1
- package/src/views/CanvasEditor/hooks/useHeroBlock.d.ts +0 -8
- package/src/views/CanvasEditor/hooks/useHeroBlock.d.ts.map +0 -1
- package/src/views/CanvasEditor/hooks/useKeyboardShortcuts.d.ts +0 -3
- package/src/views/CanvasEditor/hooks/useKeyboardShortcuts.d.ts.map +0 -1
- package/src/views/CanvasEditor/hooks/usePostLoader.d.ts +0 -5
- package/src/views/CanvasEditor/hooks/usePostLoader.d.ts.map +0 -1
- package/src/views/CanvasEditor/hooks/useRegisteredBlocks.d.ts +0 -2
- package/src/views/CanvasEditor/hooks/useRegisteredBlocks.d.ts.map +0 -1
- package/src/views/CanvasEditor/hooks/useUnsavedChanges.d.ts +0 -25
- package/src/views/CanvasEditor/hooks/useUnsavedChanges.d.ts.map +0 -1
- package/src/views/CanvasEditor/index.d.ts +0 -16
- package/src/views/CanvasEditor/index.d.ts.map +0 -1
- package/src/views/PostManager/EmptyState.d.ts +0 -10
- package/src/views/PostManager/EmptyState.d.ts.map +0 -1
- package/src/views/PostManager/PostActionsMenu.d.ts +0 -12
- package/src/views/PostManager/PostActionsMenu.d.ts.map +0 -1
- package/src/views/PostManager/PostCards.d.ts +0 -15
- package/src/views/PostManager/PostCards.d.ts.map +0 -1
- package/src/views/PostManager/PostFilters.d.ts +0 -16
- package/src/views/PostManager/PostFilters.d.ts.map +0 -1
- package/src/views/PostManager/PostManagerView.d.ts +0 -11
- package/src/views/PostManager/PostManagerView.d.ts.map +0 -1
- package/src/views/PostManager/PostStats.d.ts +0 -11
- package/src/views/PostManager/PostStats.d.ts.map +0 -1
- package/src/views/PostManager/PostTable.d.ts +0 -15
- package/src/views/PostManager/PostTable.d.ts.map +0 -1
- package/src/views/PostManager/index.d.ts +0 -12
- package/src/views/PostManager/index.d.ts.map +0 -1
- package/src/views/Preview/PreviewBridgeView.d.ts +0 -12
- package/src/views/Preview/PreviewBridgeView.d.ts.map +0 -1
- package/src/views/Preview/index.d.ts +0 -6
- package/src/views/Preview/index.d.ts.map +0 -1
- package/src/views/Settings/SettingsView.d.ts +0 -10
- package/src/views/Settings/SettingsView.d.ts.map +0 -1
- package/src/views/Settings/index.d.ts +0 -6
- package/src/views/Settings/index.d.ts.map +0 -1
- package/src/views/SlugSEO/SlugSEOManagerView.d.ts +0 -12
- package/src/views/SlugSEO/SlugSEOManagerView.d.ts.map +0 -1
- package/src/views/SlugSEO/index.d.ts +0 -6
- package/src/views/SlugSEO/index.d.ts.map +0 -1
|
@@ -1,215 +1,165 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Editor Context
|
|
3
|
-
*
|
|
4
|
-
* Multi-Tenant: Accepts custom blocks from client applications
|
|
3
|
+
* Enhanced with language management and simplified state handling
|
|
5
4
|
*/
|
|
6
5
|
'use client';
|
|
7
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
import { createContext, useContext, useReducer,
|
|
7
|
+
import { createContext, useContext, useReducer, useMemo, useEffect, useRef, useState } from 'react';
|
|
9
8
|
import { editorReducer } from './reducer';
|
|
10
9
|
import { initialEditorState } from './types';
|
|
10
|
+
import { apiToBlogPost } from '../lib/mappers/apiMapper';
|
|
11
11
|
import { blockRegistry } from '../registry/BlockRegistry';
|
|
12
12
|
import { registerLayoutBlocks } from '../lib/layouts/registerLayoutBlocks';
|
|
13
|
-
|
|
13
|
+
const API_BASE_URL = process.env.NEXT_PUBLIC_DASHBOARD_URL || 'http://localhost:3001';
|
|
14
14
|
const EditorContext = createContext(null);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
export function EditorProvider({ children, initialState, onSave, customBlocks = [], darkMode = true, backgroundColors }) {
|
|
21
|
-
// Register core layout blocks on mount
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
registerLayoutBlocks();
|
|
24
|
-
}, []);
|
|
25
|
-
// Register client blocks on mount
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (customBlocks && customBlocks.length > 0) {
|
|
28
|
-
try {
|
|
29
|
-
blockRegistry.registerClientBlocks(customBlocks);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.error('[EditorContext] Failed to register custom blocks:', error);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}, [customBlocks]);
|
|
15
|
+
export function EditorProvider({ children, initialState, onSave, customBlocks = [], darkMode = false, backgroundColors, translations }) {
|
|
16
|
+
useEffect(() => { registerLayoutBlocks(); }, []);
|
|
17
|
+
useEffect(() => { if (customBlocks?.length)
|
|
18
|
+
blockRegistry.registerClientBlocks(customBlocks); }, [customBlocks]);
|
|
36
19
|
const [state, dispatch] = useReducer(editorReducer, { ...initialEditorState, ...initialState });
|
|
37
|
-
|
|
20
|
+
const [user, setUser] = useState(null);
|
|
38
21
|
const stateRef = useRef(state);
|
|
39
22
|
stateRef.current = state;
|
|
40
|
-
//
|
|
23
|
+
// Language Management
|
|
24
|
+
const [availableLanguages, setAvailableLanguages] = useState([]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const fetchUser = async () => {
|
|
27
|
+
try {
|
|
28
|
+
const res = await fetch(`${API_BASE_URL}/api/me`);
|
|
29
|
+
if (res.ok) {
|
|
30
|
+
const data = await res.json();
|
|
31
|
+
if (data.user)
|
|
32
|
+
setUser(data.user);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) { }
|
|
36
|
+
};
|
|
37
|
+
fetchUser();
|
|
38
|
+
}, []);
|
|
39
|
+
// History logic (Simplified)
|
|
41
40
|
const [history, setHistory] = useState([]);
|
|
42
41
|
const [historyIndex, setHistoryIndex] = useState(-1);
|
|
43
42
|
const isRestoringRef = useRef(false);
|
|
44
|
-
const MAX_HISTORY = 50; // Limit history to prevent memory issues
|
|
45
|
-
// Save current state to history after state changes (but not during undo/redo)
|
|
46
|
-
// Debounce history updates to avoid excessive re-renders
|
|
47
|
-
const historyTimeoutRef = useRef(null);
|
|
48
43
|
useEffect(() => {
|
|
49
44
|
if (isRestoringRef.current) {
|
|
50
45
|
isRestoringRef.current = false;
|
|
51
46
|
return;
|
|
52
47
|
}
|
|
53
|
-
|
|
54
|
-
if (historyTimeoutRef.current) {
|
|
55
|
-
clearTimeout(historyTimeoutRef.current);
|
|
56
|
-
}
|
|
57
|
-
// Debounce history updates to reduce re-renders
|
|
58
|
-
historyTimeoutRef.current = setTimeout(() => {
|
|
59
|
-
// Save current state to history
|
|
48
|
+
const timer = setTimeout(() => {
|
|
60
49
|
setHistory(prev => {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
newHistory.splice(historyIndex + 1);
|
|
65
|
-
}
|
|
66
|
-
// Add current state
|
|
67
|
-
newHistory.push({ ...state });
|
|
68
|
-
// Limit history size
|
|
69
|
-
if (newHistory.length > MAX_HISTORY) {
|
|
70
|
-
newHistory.shift();
|
|
71
|
-
return newHistory;
|
|
72
|
-
}
|
|
73
|
-
return newHistory;
|
|
50
|
+
const next = prev.slice(0, historyIndex + 1);
|
|
51
|
+
next.push({ ...state });
|
|
52
|
+
return next.slice(-50);
|
|
74
53
|
});
|
|
75
|
-
setHistoryIndex(prev =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
54
|
+
setHistoryIndex(prev => Math.min(prev + 1, 49));
|
|
55
|
+
}, 300);
|
|
56
|
+
return () => clearTimeout(timer);
|
|
57
|
+
}, [state.blocks, state.title, state.slug]);
|
|
58
|
+
const helpers = useMemo(() => ({
|
|
59
|
+
addBlock: (type, index, containerId) => {
|
|
60
|
+
const def = blockRegistry.get(type);
|
|
61
|
+
const block = {
|
|
62
|
+
id: `block-${Date.now()}`,
|
|
63
|
+
type,
|
|
64
|
+
data: { ...(def?.defaultData || {}) }
|
|
65
|
+
};
|
|
66
|
+
dispatch({ type: 'ADD_BLOCK', payload: { block, index, containerId } });
|
|
67
|
+
},
|
|
68
|
+
updateBlock: (id, data) => dispatch({ type: 'UPDATE_BLOCK', payload: { id, data } }),
|
|
69
|
+
deleteBlock: (id) => dispatch({ type: 'DELETE_BLOCK', payload: { id } }),
|
|
70
|
+
duplicateBlock: (id) => dispatch({ type: 'DUPLICATE_BLOCK', payload: { id } }),
|
|
71
|
+
moveBlock: (id, newIndex, containerId) => dispatch({ type: 'MOVE_BLOCK', payload: { id, newIndex, containerId } }),
|
|
72
|
+
loadPost: (post) => {
|
|
73
|
+
dispatch({ type: 'LOAD_POST', payload: post });
|
|
74
|
+
// 1. Collect all unique language keys from the post data
|
|
75
|
+
const createdLangs = new Set();
|
|
76
|
+
// From availableLanguages array (source of truth from API)
|
|
77
|
+
if (post.availableLanguages) {
|
|
78
|
+
post.availableLanguages.forEach(l => createdLangs.add(l));
|
|
83
79
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}, []);
|
|
104
|
-
// Helper: Delete a block
|
|
105
|
-
const deleteBlock = useCallback((id) => {
|
|
106
|
-
dispatch({ type: 'DELETE_BLOCK', payload: { id } });
|
|
107
|
-
}, []);
|
|
108
|
-
// Helper: Duplicate a block
|
|
109
|
-
const duplicateBlock = useCallback((id) => {
|
|
110
|
-
dispatch({ type: 'DUPLICATE_BLOCK', payload: { id } });
|
|
111
|
-
}, []);
|
|
112
|
-
// Helper: Move a block (supports nested containers)
|
|
113
|
-
const moveBlock = useCallback((id, newIndex, containerId) => {
|
|
114
|
-
dispatch({ type: 'MOVE_BLOCK', payload: { id, newIndex, containerId } });
|
|
115
|
-
}, []);
|
|
116
|
-
// Helper: Load a post
|
|
117
|
-
const loadPost = useCallback((post) => {
|
|
118
|
-
dispatch({ type: 'LOAD_POST', payload: post });
|
|
119
|
-
}, []);
|
|
120
|
-
// Helper: Reset editor
|
|
121
|
-
const resetEditor = useCallback(() => {
|
|
122
|
-
dispatch({ type: 'RESET_EDITOR' });
|
|
123
|
-
}, []);
|
|
124
|
-
// Helper: Save
|
|
125
|
-
// Uses stateRef to always get the latest state, avoiding stale closure issues
|
|
126
|
-
const save = useCallback(async (heroBlock) => {
|
|
127
|
-
if (onSave) {
|
|
128
|
-
// Use stateRef.current to get the absolute latest state
|
|
129
|
-
// This ensures we don't have stale closure issues with React state updates
|
|
130
|
-
await onSave(stateRef.current, heroBlock);
|
|
131
|
-
dispatch({ type: 'MARK_CLEAN' });
|
|
132
|
-
}
|
|
133
|
-
}, [onSave]);
|
|
134
|
-
// Helper: Undo
|
|
135
|
-
const undo = useCallback(() => {
|
|
136
|
-
if (historyIndex > 0 && history.length > 0) {
|
|
137
|
-
const previousState = history[historyIndex - 1];
|
|
138
|
-
if (previousState) {
|
|
80
|
+
// From languages summary keys (backup)
|
|
81
|
+
if (post.languages) {
|
|
82
|
+
Object.keys(post.languages).forEach(l => createdLangs.add(l));
|
|
83
|
+
}
|
|
84
|
+
// 2. Update state with the consolidated list
|
|
85
|
+
setAvailableLanguages(Array.from(createdLangs));
|
|
86
|
+
},
|
|
87
|
+
resetEditor: () => dispatch({ type: 'RESET_EDITOR' }),
|
|
88
|
+
save: async (heroBlock, statusOverride) => {
|
|
89
|
+
if (onSave) {
|
|
90
|
+
const currentState = { ...stateRef.current };
|
|
91
|
+
if (statusOverride)
|
|
92
|
+
currentState.status = statusOverride;
|
|
93
|
+
await onSave(currentState, heroBlock);
|
|
94
|
+
dispatch({ type: 'MARK_CLEAN' });
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
undo: () => {
|
|
98
|
+
if (historyIndex > 0) {
|
|
139
99
|
isRestoringRef.current = true;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
title: previousState.title,
|
|
144
|
-
slug: previousState.slug,
|
|
145
|
-
blocks: previousState.blocks,
|
|
146
|
-
seo: previousState.seo,
|
|
147
|
-
publication: {
|
|
148
|
-
status: previousState.status,
|
|
149
|
-
authorId: undefined,
|
|
150
|
-
},
|
|
151
|
-
metadata: previousState.metadata,
|
|
152
|
-
createdAt: new Date().toISOString(),
|
|
153
|
-
updatedAt: new Date().toISOString(),
|
|
154
|
-
} });
|
|
100
|
+
const prev = history[historyIndex - 1];
|
|
101
|
+
setHistoryIndex(i => i - 1);
|
|
102
|
+
dispatch({ type: 'LOAD_POST', payload: prev });
|
|
155
103
|
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const redo = useCallback(() => {
|
|
160
|
-
if (historyIndex < history.length - 1) {
|
|
161
|
-
const nextState = history[historyIndex + 1];
|
|
162
|
-
if (nextState) {
|
|
104
|
+
},
|
|
105
|
+
redo: () => {
|
|
106
|
+
if (historyIndex < history.length - 1) {
|
|
163
107
|
isRestoringRef.current = true;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
108
|
+
const next = history[historyIndex + 1];
|
|
109
|
+
setHistoryIndex(i => i + 1);
|
|
110
|
+
dispatch({ type: 'LOAD_POST', payload: next });
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
switchLanguage: async (newLang, postId) => {
|
|
114
|
+
// 1. Always update the current language in state first to show immediate UI feedback
|
|
115
|
+
dispatch({ type: 'SET_CURRENT_LANGUAGE', payload: newLang });
|
|
116
|
+
if (!postId) {
|
|
117
|
+
dispatch({ type: 'SET_STATUS', payload: 'draft' });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// 2. Fetch the language version from the API
|
|
121
|
+
const fetchUrl = `${API_BASE_URL}/api/plugin-blog/${postId}?language=${newLang}&admin=true`;
|
|
122
|
+
const res = await fetch(fetchUrl);
|
|
123
|
+
if (res.ok) {
|
|
124
|
+
const data = await res.json();
|
|
125
|
+
const blogPost = apiToBlogPost(data);
|
|
126
|
+
// Update the available languages list from the source of truth
|
|
127
|
+
if (data.availableLanguages) {
|
|
128
|
+
setAvailableLanguages(data.availableLanguages);
|
|
129
|
+
}
|
|
130
|
+
// If this is a NEW translation (missing in the document),
|
|
131
|
+
// customize it so it's not a perfect clone of the primary language
|
|
132
|
+
if (data.isMissingTranslation) {
|
|
133
|
+
blogPost.publication.status = 'draft';
|
|
134
|
+
blogPost.title = `${blogPost.title} - ${newLang.toUpperCase()}`;
|
|
135
|
+
// Important: Mark as dirty so it can be saved as a new version
|
|
136
|
+
dispatch({ type: 'LOAD_POST', payload: blogPost });
|
|
137
|
+
dispatch({ type: 'MARK_DIRTY' });
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
dispatch({ type: 'LOAD_POST', payload: blogPost });
|
|
141
|
+
dispatch({ type: 'MARK_CLEAN' });
|
|
142
|
+
}
|
|
179
143
|
}
|
|
180
144
|
}
|
|
181
|
-
}, [history, historyIndex,
|
|
182
|
-
// Memoize the context value
|
|
145
|
+
}), [onSave, history, historyIndex, state.postId]);
|
|
183
146
|
const value = useMemo(() => ({
|
|
184
147
|
state,
|
|
185
148
|
dispatch,
|
|
186
149
|
darkMode,
|
|
187
150
|
backgroundColors,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
moveBlock,
|
|
194
|
-
loadPost,
|
|
195
|
-
resetEditor,
|
|
196
|
-
save,
|
|
197
|
-
undo,
|
|
198
|
-
redo,
|
|
199
|
-
},
|
|
200
|
-
canUndo: historyIndex > 0 && history.length > 0,
|
|
151
|
+
translations,
|
|
152
|
+
user,
|
|
153
|
+
helpers,
|
|
154
|
+
availableLanguages,
|
|
155
|
+
canUndo: historyIndex > 0,
|
|
201
156
|
canRedo: historyIndex < history.length - 1,
|
|
202
|
-
}), [state,
|
|
157
|
+
}), [state, darkMode, backgroundColors, user, helpers, historyIndex, history.length, availableLanguages]);
|
|
203
158
|
return _jsx(EditorContext.Provider, { value: value, children: children });
|
|
204
159
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Hook to access editor context
|
|
207
|
-
* @throws Error if used outside EditorProvider
|
|
208
|
-
*/
|
|
209
160
|
export function useEditor() {
|
|
210
161
|
const context = useContext(EditorContext);
|
|
211
|
-
if (!context)
|
|
212
|
-
throw new Error('useEditor must be used within
|
|
213
|
-
}
|
|
162
|
+
if (!context)
|
|
163
|
+
throw new Error('useEditor must be used within EditorProvider');
|
|
214
164
|
return context;
|
|
215
165
|
}
|
package/dist/state/reducer.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Editor Reducer
|
|
3
|
-
* Pure function that handles state transitions
|
|
3
|
+
* Pure function that handles state transitions using tree utilities
|
|
4
4
|
*/
|
|
5
5
|
import { EditorState, EditorAction } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* Editor Reducer
|
|
8
|
-
* Handles all state transitions for the editor
|
|
9
|
-
*/
|
|
10
6
|
export declare function editorReducer(state: EditorState, action: EditorAction): EditorState;
|
|
11
7
|
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/state/reducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAsB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/state/reducer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAsB,MAAM,SAAS,CAAC;AA+BxE,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,GAAG,WAAW,CAsMnF"}
|