@jhits/plugin-blog 0.0.10 → 0.0.11

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 (276) hide show
  1. package/package.json +4 -5
  2. package/src/api/categories.ts +0 -43
  3. package/src/api/check-title.ts +0 -60
  4. package/src/api/config-handler.ts +0 -76
  5. package/src/api/handler.ts +0 -418
  6. package/src/api/index.ts +0 -33
  7. package/src/api/route.ts +0 -116
  8. package/src/api/router.ts +0 -128
  9. package/src/api-server.ts +0 -11
  10. package/src/config.ts +0 -161
  11. package/src/hooks/index.d.ts +0 -8
  12. package/src/hooks/index.d.ts.map +0 -1
  13. package/src/hooks/index.js +0 -7
  14. package/src/hooks/index.ts +0 -9
  15. package/src/hooks/useBlog.d.ts +0 -31
  16. package/src/hooks/useBlog.d.ts.map +0 -1
  17. package/src/hooks/useBlog.js +0 -57
  18. package/src/hooks/useBlog.ts +0 -85
  19. package/src/hooks/useBlogs.d.ts +0 -39
  20. package/src/hooks/useBlogs.d.ts.map +0 -1
  21. package/src/hooks/useBlogs.js +0 -82
  22. package/src/hooks/useBlogs.ts +0 -123
  23. package/src/hooks/useCategories.d.ts +0 -9
  24. package/src/hooks/useCategories.d.ts.map +0 -1
  25. package/src/hooks/useCategories.js +0 -70
  26. package/src/hooks/useCategories.ts +0 -76
  27. package/src/index.d.ts +0 -55
  28. package/src/index.d.ts.map +0 -1
  29. package/src/index.js +0 -228
  30. package/src/index.server.ts +0 -14
  31. package/src/index.tsx +0 -335
  32. package/src/init.d.ts +0 -40
  33. package/src/init.d.ts.map +0 -1
  34. package/src/init.js +0 -41
  35. package/src/init.tsx +0 -63
  36. package/src/lib/blocks/BlockRenderer.d.ts +0 -54
  37. package/src/lib/blocks/BlockRenderer.d.ts.map +0 -1
  38. package/src/lib/blocks/BlockRenderer.js +0 -54
  39. package/src/lib/blocks/BlockRenderer.tsx +0 -141
  40. package/src/lib/blocks/index.ts +0 -6
  41. package/src/lib/config-storage.d.ts +0 -30
  42. package/src/lib/config-storage.d.ts.map +0 -1
  43. package/src/lib/config-storage.js +0 -31
  44. package/src/lib/config-storage.ts +0 -65
  45. package/src/lib/index.ts +0 -9
  46. package/src/lib/layouts/blocks/ColumnsBlock.d.ts +0 -25
  47. package/src/lib/layouts/blocks/ColumnsBlock.d.ts.map +0 -1
  48. package/src/lib/layouts/blocks/ColumnsBlock.js +0 -182
  49. package/src/lib/layouts/blocks/ColumnsBlock.tsx +0 -298
  50. package/src/lib/layouts/blocks/ColumnsBlock.tsx.tmp +0 -81
  51. package/src/lib/layouts/blocks/SectionBlock.d.ts +0 -25
  52. package/src/lib/layouts/blocks/SectionBlock.d.ts.map +0 -1
  53. package/src/lib/layouts/blocks/SectionBlock.js +0 -44
  54. package/src/lib/layouts/blocks/SectionBlock.tsx +0 -104
  55. package/src/lib/layouts/blocks/index.ts +0 -8
  56. package/src/lib/layouts/index.d.ts +0 -23
  57. package/src/lib/layouts/index.d.ts.map +0 -1
  58. package/src/lib/layouts/index.js +0 -45
  59. package/src/lib/layouts/index.ts +0 -52
  60. package/src/lib/layouts/registerLayoutBlocks.d.ts +0 -9
  61. package/src/lib/layouts/registerLayoutBlocks.d.ts.map +0 -1
  62. package/src/lib/layouts/registerLayoutBlocks.js +0 -60
  63. package/src/lib/layouts/registerLayoutBlocks.ts +0 -64
  64. package/src/lib/mappers/apiMapper.d.ts +0 -66
  65. package/src/lib/mappers/apiMapper.d.ts.map +0 -1
  66. package/src/lib/mappers/apiMapper.js +0 -191
  67. package/src/lib/mappers/apiMapper.ts +0 -254
  68. package/src/lib/migration/index.ts +0 -6
  69. package/src/lib/migration/mapper.ts +0 -140
  70. package/src/lib/rich-text/RichTextEditor.d.ts +0 -45
  71. package/src/lib/rich-text/RichTextEditor.d.ts.map +0 -1
  72. package/src/lib/rich-text/RichTextEditor.js +0 -564
  73. package/src/lib/rich-text/RichTextEditor.tsx +0 -826
  74. package/src/lib/rich-text/RichTextPreview.d.ts +0 -16
  75. package/src/lib/rich-text/RichTextPreview.d.ts.map +0 -1
  76. package/src/lib/rich-text/RichTextPreview.js +0 -144
  77. package/src/lib/rich-text/RichTextPreview.tsx +0 -210
  78. package/src/lib/rich-text/index.d.ts +0 -9
  79. package/src/lib/rich-text/index.d.ts.map +0 -1
  80. package/src/lib/rich-text/index.js +0 -6
  81. package/src/lib/rich-text/index.ts +0 -10
  82. package/src/lib/utils/blockHelpers.d.ts +0 -23
  83. package/src/lib/utils/blockHelpers.d.ts.map +0 -1
  84. package/src/lib/utils/blockHelpers.js +0 -65
  85. package/src/lib/utils/blockHelpers.ts +0 -72
  86. package/src/lib/utils/configValidation.d.ts +0 -23
  87. package/src/lib/utils/configValidation.d.ts.map +0 -1
  88. package/src/lib/utils/configValidation.js +0 -113
  89. package/src/lib/utils/configValidation.ts +0 -137
  90. package/src/lib/utils/index.ts +0 -8
  91. package/src/lib/utils/slugify.ts +0 -79
  92. package/src/registry/BlockRegistry.d.ts +0 -62
  93. package/src/registry/BlockRegistry.d.ts.map +0 -1
  94. package/src/registry/BlockRegistry.js +0 -112
  95. package/src/registry/BlockRegistry.ts +0 -139
  96. package/src/registry/index.d.ts +0 -6
  97. package/src/registry/index.d.ts.map +0 -1
  98. package/src/registry/index.js +0 -4
  99. package/src/registry/index.ts +0 -11
  100. package/src/state/EditorContext.d.ts +0 -45
  101. package/src/state/EditorContext.d.ts.map +0 -1
  102. package/src/state/EditorContext.js +0 -215
  103. package/src/state/EditorContext.tsx +0 -283
  104. package/src/state/index.d.ts +0 -7
  105. package/src/state/index.d.ts.map +0 -1
  106. package/src/state/index.js +0 -6
  107. package/src/state/index.ts +0 -8
  108. package/src/state/reducer.d.ts +0 -11
  109. package/src/state/reducer.d.ts.map +0 -1
  110. package/src/state/reducer.js +0 -443
  111. package/src/state/reducer.ts +0 -694
  112. package/src/state/types.d.ts +0 -162
  113. package/src/state/types.d.ts.map +0 -1
  114. package/src/state/types.js +0 -27
  115. package/src/state/types.ts +0 -160
  116. package/src/types/block.d.ts +0 -221
  117. package/src/types/block.d.ts.map +0 -1
  118. package/src/types/block.js +0 -6
  119. package/src/types/block.ts +0 -269
  120. package/src/types/index.d.ts +0 -8
  121. package/src/types/index.d.ts.map +0 -1
  122. package/src/types/index.js +0 -5
  123. package/src/types/index.ts +0 -17
  124. package/src/types/post.d.ts +0 -136
  125. package/src/types/post.d.ts.map +0 -1
  126. package/src/types/post.js +0 -5
  127. package/src/types/post.ts +0 -169
  128. package/src/utils/client.d.ts +0 -48
  129. package/src/utils/client.d.ts.map +0 -1
  130. package/src/utils/client.js +0 -77
  131. package/src/utils/client.ts +0 -122
  132. package/src/utils/index.ts +0 -7
  133. package/src/views/CanvasEditor/BlockWrapper.d.ts +0 -16
  134. package/src/views/CanvasEditor/BlockWrapper.d.ts.map +0 -1
  135. package/src/views/CanvasEditor/BlockWrapper.js +0 -276
  136. package/src/views/CanvasEditor/BlockWrapper.tsx +0 -522
  137. package/src/views/CanvasEditor/CanvasEditorView.d.ts +0 -14
  138. package/src/views/CanvasEditor/CanvasEditorView.d.ts.map +0 -1
  139. package/src/views/CanvasEditor/CanvasEditorView.js +0 -209
  140. package/src/views/CanvasEditor/CanvasEditorView.tsx +0 -337
  141. package/src/views/CanvasEditor/EditorBody.d.ts +0 -22
  142. package/src/views/CanvasEditor/EditorBody.d.ts.map +0 -1
  143. package/src/views/CanvasEditor/EditorBody.js +0 -505
  144. package/src/views/CanvasEditor/EditorBody.tsx +0 -665
  145. package/src/views/CanvasEditor/EditorHeader.d.ts +0 -18
  146. package/src/views/CanvasEditor/EditorHeader.d.ts.map +0 -1
  147. package/src/views/CanvasEditor/EditorHeader.js +0 -101
  148. package/src/views/CanvasEditor/EditorHeader.tsx +0 -268
  149. package/src/views/CanvasEditor/LayoutContainer.d.ts +0 -17
  150. package/src/views/CanvasEditor/LayoutContainer.d.ts.map +0 -1
  151. package/src/views/CanvasEditor/LayoutContainer.js +0 -222
  152. package/src/views/CanvasEditor/LayoutContainer.tsx +0 -322
  153. package/src/views/CanvasEditor/SaveConfirmationModal.d.ts +0 -13
  154. package/src/views/CanvasEditor/SaveConfirmationModal.d.ts.map +0 -1
  155. package/src/views/CanvasEditor/SaveConfirmationModal.js +0 -78
  156. package/src/views/CanvasEditor/SaveConfirmationModal.tsx +0 -233
  157. package/src/views/CanvasEditor/components/CustomBlockItem.d.ts +0 -14
  158. package/src/views/CanvasEditor/components/CustomBlockItem.d.ts.map +0 -1
  159. package/src/views/CanvasEditor/components/CustomBlockItem.js +0 -44
  160. package/src/views/CanvasEditor/components/CustomBlockItem.tsx +0 -92
  161. package/src/views/CanvasEditor/components/EditorCanvas.d.ts +0 -29
  162. package/src/views/CanvasEditor/components/EditorCanvas.d.ts.map +0 -1
  163. package/src/views/CanvasEditor/components/EditorCanvas.js +0 -32
  164. package/src/views/CanvasEditor/components/EditorCanvas.tsx +0 -160
  165. package/src/views/CanvasEditor/components/EditorLibrary.d.ts +0 -7
  166. package/src/views/CanvasEditor/components/EditorLibrary.d.ts.map +0 -1
  167. package/src/views/CanvasEditor/components/EditorLibrary.js +0 -25
  168. package/src/views/CanvasEditor/components/EditorLibrary.tsx +0 -122
  169. package/src/views/CanvasEditor/components/EditorSidebar.d.ts +0 -13
  170. package/src/views/CanvasEditor/components/EditorSidebar.d.ts.map +0 -1
  171. package/src/views/CanvasEditor/components/EditorSidebar.js +0 -20
  172. package/src/views/CanvasEditor/components/EditorSidebar.tsx +0 -181
  173. package/src/views/CanvasEditor/components/ErrorBanner.d.ts +0 -6
  174. package/src/views/CanvasEditor/components/ErrorBanner.d.ts.map +0 -1
  175. package/src/views/CanvasEditor/components/ErrorBanner.js +0 -8
  176. package/src/views/CanvasEditor/components/ErrorBanner.tsx +0 -31
  177. package/src/views/CanvasEditor/components/FeaturedMediaSection.d.ts +0 -25
  178. package/src/views/CanvasEditor/components/FeaturedMediaSection.d.ts.map +0 -1
  179. package/src/views/CanvasEditor/components/FeaturedMediaSection.js +0 -182
  180. package/src/views/CanvasEditor/components/FeaturedMediaSection.tsx +0 -341
  181. package/src/views/CanvasEditor/components/LibraryItem.d.ts +0 -14
  182. package/src/views/CanvasEditor/components/LibraryItem.d.ts.map +0 -1
  183. package/src/views/CanvasEditor/components/LibraryItem.js +0 -43
  184. package/src/views/CanvasEditor/components/LibraryItem.tsx +0 -80
  185. package/src/views/CanvasEditor/components/PrivacySettingsSection.d.ts +0 -15
  186. package/src/views/CanvasEditor/components/PrivacySettingsSection.d.ts.map +0 -1
  187. package/src/views/CanvasEditor/components/PrivacySettingsSection.js +0 -63
  188. package/src/views/CanvasEditor/components/PrivacySettingsSection.tsx +0 -212
  189. package/src/views/CanvasEditor/components/index.d.ts +0 -21
  190. package/src/views/CanvasEditor/components/index.d.ts.map +0 -1
  191. package/src/views/CanvasEditor/components/index.js +0 -12
  192. package/src/views/CanvasEditor/components/index.ts +0 -28
  193. package/src/views/CanvasEditor/hooks/index.d.ts +0 -10
  194. package/src/views/CanvasEditor/hooks/index.d.ts.map +0 -1
  195. package/src/views/CanvasEditor/hooks/index.js +0 -9
  196. package/src/views/CanvasEditor/hooks/index.ts +0 -10
  197. package/src/views/CanvasEditor/hooks/useHeroBlock.d.ts +0 -8
  198. package/src/views/CanvasEditor/hooks/useHeroBlock.d.ts.map +0 -1
  199. package/src/views/CanvasEditor/hooks/useHeroBlock.js +0 -79
  200. package/src/views/CanvasEditor/hooks/useHeroBlock.ts +0 -103
  201. package/src/views/CanvasEditor/hooks/useKeyboardShortcuts.d.ts +0 -3
  202. package/src/views/CanvasEditor/hooks/useKeyboardShortcuts.d.ts.map +0 -1
  203. package/src/views/CanvasEditor/hooks/useKeyboardShortcuts.js +0 -114
  204. package/src/views/CanvasEditor/hooks/useKeyboardShortcuts.ts +0 -142
  205. package/src/views/CanvasEditor/hooks/usePostLoader.d.ts +0 -5
  206. package/src/views/CanvasEditor/hooks/usePostLoader.d.ts.map +0 -1
  207. package/src/views/CanvasEditor/hooks/usePostLoader.js +0 -32
  208. package/src/views/CanvasEditor/hooks/usePostLoader.ts +0 -39
  209. package/src/views/CanvasEditor/hooks/useRegisteredBlocks.d.ts +0 -2
  210. package/src/views/CanvasEditor/hooks/useRegisteredBlocks.d.ts.map +0 -1
  211. package/src/views/CanvasEditor/hooks/useRegisteredBlocks.js +0 -47
  212. package/src/views/CanvasEditor/hooks/useRegisteredBlocks.ts +0 -55
  213. package/src/views/CanvasEditor/hooks/useUnsavedChanges.d.ts +0 -25
  214. package/src/views/CanvasEditor/hooks/useUnsavedChanges.d.ts.map +0 -1
  215. package/src/views/CanvasEditor/hooks/useUnsavedChanges.js +0 -285
  216. package/src/views/CanvasEditor/hooks/useUnsavedChanges.ts +0 -339
  217. package/src/views/CanvasEditor/index.d.ts +0 -16
  218. package/src/views/CanvasEditor/index.d.ts.map +0 -1
  219. package/src/views/CanvasEditor/index.js +0 -9
  220. package/src/views/CanvasEditor/index.ts +0 -16
  221. package/src/views/PostManager/EmptyState.d.ts +0 -10
  222. package/src/views/PostManager/EmptyState.d.ts.map +0 -1
  223. package/src/views/PostManager/EmptyState.js +0 -12
  224. package/src/views/PostManager/EmptyState.tsx +0 -42
  225. package/src/views/PostManager/PostActionsMenu.d.ts +0 -12
  226. package/src/views/PostManager/PostActionsMenu.d.ts.map +0 -1
  227. package/src/views/PostManager/PostActionsMenu.js +0 -58
  228. package/src/views/PostManager/PostActionsMenu.tsx +0 -112
  229. package/src/views/PostManager/PostCards.d.ts +0 -15
  230. package/src/views/PostManager/PostCards.d.ts.map +0 -1
  231. package/src/views/PostManager/PostCards.js +0 -79
  232. package/src/views/PostManager/PostCards.tsx +0 -197
  233. package/src/views/PostManager/PostFilters.d.ts +0 -16
  234. package/src/views/PostManager/PostFilters.d.ts.map +0 -1
  235. package/src/views/PostManager/PostFilters.js +0 -10
  236. package/src/views/PostManager/PostFilters.tsx +0 -95
  237. package/src/views/PostManager/PostManagerView.d.ts +0 -11
  238. package/src/views/PostManager/PostManagerView.d.ts.map +0 -1
  239. package/src/views/PostManager/PostManagerView.js +0 -174
  240. package/src/views/PostManager/PostManagerView.tsx +0 -289
  241. package/src/views/PostManager/PostStats.d.ts +0 -11
  242. package/src/views/PostManager/PostStats.d.ts.map +0 -1
  243. package/src/views/PostManager/PostStats.js +0 -46
  244. package/src/views/PostManager/PostStats.tsx +0 -81
  245. package/src/views/PostManager/PostTable.d.ts +0 -15
  246. package/src/views/PostManager/PostTable.d.ts.map +0 -1
  247. package/src/views/PostManager/PostTable.js +0 -79
  248. package/src/views/PostManager/PostTable.tsx +0 -230
  249. package/src/views/PostManager/index.d.ts +0 -12
  250. package/src/views/PostManager/index.d.ts.map +0 -1
  251. package/src/views/PostManager/index.js +0 -11
  252. package/src/views/PostManager/index.ts +0 -15
  253. package/src/views/Preview/PreviewBridgeView.d.ts +0 -12
  254. package/src/views/Preview/PreviewBridgeView.d.ts.map +0 -1
  255. package/src/views/Preview/PreviewBridgeView.js +0 -11
  256. package/src/views/Preview/PreviewBridgeView.tsx +0 -64
  257. package/src/views/Preview/index.d.ts +0 -6
  258. package/src/views/Preview/index.d.ts.map +0 -1
  259. package/src/views/Preview/index.js +0 -4
  260. package/src/views/Preview/index.ts +0 -7
  261. package/src/views/Settings/SettingsView.d.ts +0 -10
  262. package/src/views/Settings/SettingsView.d.ts.map +0 -1
  263. package/src/views/Settings/SettingsView.js +0 -111
  264. package/src/views/Settings/SettingsView.tsx +0 -298
  265. package/src/views/Settings/index.d.ts +0 -6
  266. package/src/views/Settings/index.d.ts.map +0 -1
  267. package/src/views/Settings/index.js +0 -4
  268. package/src/views/Settings/index.ts +0 -7
  269. package/src/views/SlugSEO/SlugSEOManagerView.d.ts +0 -12
  270. package/src/views/SlugSEO/SlugSEOManagerView.d.ts.map +0 -1
  271. package/src/views/SlugSEO/SlugSEOManagerView.js +0 -11
  272. package/src/views/SlugSEO/SlugSEOManagerView.tsx +0 -94
  273. package/src/views/SlugSEO/index.d.ts +0 -6
  274. package/src/views/SlugSEO/index.d.ts.map +0 -1
  275. package/src/views/SlugSEO/index.js +0 -4
  276. package/src/views/SlugSEO/index.ts +0 -7
@@ -1,443 +0,0 @@
1
- /**
2
- * Editor Reducer
3
- * Pure function that handles state transitions
4
- */
5
- import { initialEditorState } from './types';
6
- /**
7
- * Generate a unique block ID
8
- */
9
- function generateBlockId() {
10
- // Use crypto.randomUUID if available, otherwise fallback to timestamp-based
11
- if (typeof crypto !== 'undefined' && crypto.randomUUID) {
12
- return crypto.randomUUID();
13
- }
14
- return `block-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
15
- }
16
- /**
17
- * Clone a block with a new ID
18
- */
19
- function cloneBlock(block) {
20
- return Object.assign(Object.assign({}, block), { id: generateBlockId(), data: Object.assign({}, block.data), meta: block.meta ? Object.assign({}, block.meta) : undefined, children: block.children ? (Array.isArray(block.children[0])
21
- ? block.children.map(cloneBlock)
22
- : [...block.children]) : undefined });
23
- }
24
- /**
25
- * Find a block by ID recursively (including nested blocks)
26
- */
27
- function findBlockById(blocks, id) {
28
- for (const block of blocks) {
29
- if (block.id === id) {
30
- return block;
31
- }
32
- if (block.children && Array.isArray(block.children) && block.children.length > 0) {
33
- // Check if children are Block objects or IDs
34
- if (typeof block.children[0] === 'object') {
35
- const found = findBlockById(block.children, id);
36
- if (found)
37
- return found;
38
- }
39
- }
40
- }
41
- return null;
42
- }
43
- /**
44
- * Update blocks recursively to add a block to a container
45
- */
46
- function addBlockToContainer(blocks, containerId, newBlock, index) {
47
- return blocks.map(block => {
48
- // Check if this is the container (exact match or column container like "block-123-col-0")
49
- const isContainer = block.id === containerId;
50
- const isColumnContainer = containerId.startsWith(`${block.id}-col-`);
51
- if (isContainer) {
52
- // Direct container match
53
- const currentChildren = Array.isArray(block.children)
54
- ? (typeof block.children[0] === 'object'
55
- ? block.children
56
- : [])
57
- : [];
58
- const updatedChildren = [...currentChildren];
59
- if (index !== undefined && index >= 0 && index <= updatedChildren.length) {
60
- updatedChildren.splice(index, 0, newBlock);
61
- }
62
- else {
63
- updatedChildren.push(newBlock);
64
- }
65
- return Object.assign(Object.assign({}, block), { children: updatedChildren });
66
- }
67
- else if (isColumnContainer) {
68
- // Column container - extract column index and store in block meta
69
- const columnIndex = parseInt(containerId.split('-col-')[1] || '0', 10);
70
- newBlock.meta = Object.assign(Object.assign({}, newBlock.meta), { columnIndex });
71
- const currentChildren = Array.isArray(block.children)
72
- ? (typeof block.children[0] === 'object'
73
- ? block.children
74
- : [])
75
- : [];
76
- const updatedChildren = [...currentChildren];
77
- if (index !== undefined && index >= 0 && index <= updatedChildren.length) {
78
- updatedChildren.splice(index, 0, newBlock);
79
- }
80
- else {
81
- updatedChildren.push(newBlock);
82
- }
83
- return Object.assign(Object.assign({}, block), { children: updatedChildren });
84
- }
85
- // Recursively search nested blocks
86
- if (block.children && Array.isArray(block.children) && block.children.length > 0) {
87
- if (typeof block.children[0] === 'object') {
88
- return Object.assign(Object.assign({}, block), { children: addBlockToContainer(block.children, containerId, newBlock, index) });
89
- }
90
- }
91
- return block;
92
- });
93
- }
94
- /**
95
- * Update blocks recursively to update a nested block
96
- */
97
- function updateNestedBlock(blocks, id, data) {
98
- return blocks.map(block => {
99
- if (block.id === id) {
100
- return Object.assign(Object.assign({}, block), { data: Object.assign(Object.assign({}, block.data), data) });
101
- }
102
- if (block.children && Array.isArray(block.children) && block.children.length > 0) {
103
- if (typeof block.children[0] === 'object') {
104
- return Object.assign(Object.assign({}, block), { children: updateNestedBlock(block.children, id, data) });
105
- }
106
- }
107
- return block;
108
- });
109
- }
110
- /**
111
- * Update blocks recursively to delete a nested block
112
- */
113
- function deleteNestedBlock(blocks, id) {
114
- return blocks
115
- .filter(block => block.id !== id)
116
- .map(block => {
117
- if (block.children && Array.isArray(block.children) && block.children.length > 0) {
118
- if (typeof block.children[0] === 'object') {
119
- return Object.assign(Object.assign({}, block), { children: deleteNestedBlock(block.children, id) });
120
- }
121
- }
122
- return block;
123
- });
124
- }
125
- /**
126
- * Find and remove a block from wherever it is (root or nested)
127
- */
128
- function removeBlockFromTree(blocks, blockId) {
129
- let removedBlock = null;
130
- console.log('[removeBlockFromTree] Searching for block:', {
131
- blockId,
132
- rootBlocks: blocks.map(b => ({ id: b.id, type: b.type })),
133
- });
134
- // First check root level
135
- const rootIndex = blocks.findIndex(b => b.id === blockId);
136
- if (rootIndex !== -1) {
137
- removedBlock = blocks[rootIndex];
138
- console.log('[removeBlockFromTree] Found at root level:', {
139
- blockId,
140
- index: rootIndex,
141
- block: { id: removedBlock.id, type: removedBlock.type },
142
- });
143
- return {
144
- updatedBlocks: blocks.filter((_, i) => i !== rootIndex),
145
- removedBlock,
146
- };
147
- }
148
- // Then check nested blocks
149
- const updatedBlocks = blocks.map(block => {
150
- if (block.children && Array.isArray(block.children) && block.children.length > 0) {
151
- if (typeof block.children[0] === 'object') {
152
- const children = block.children;
153
- const childIndex = children.findIndex(b => b.id === blockId);
154
- if (childIndex !== -1) {
155
- removedBlock = children[childIndex];
156
- console.log('[removeBlockFromTree] Found in nested container:', {
157
- blockId,
158
- containerId: block.id,
159
- containerType: block.type,
160
- childIndex,
161
- block: { id: removedBlock.id, type: removedBlock.type },
162
- });
163
- return Object.assign(Object.assign({}, block), { children: children.filter((_, i) => i !== childIndex) });
164
- }
165
- // Recursively search nested children
166
- const { updatedBlocks: updatedChildren, removedBlock: foundBlock } = removeBlockFromTree(children, blockId);
167
- if (foundBlock) {
168
- removedBlock = foundBlock;
169
- console.log('[removeBlockFromTree] Found in deeper nesting:', {
170
- blockId,
171
- containerId: block.id,
172
- block: { id: removedBlock.id, type: removedBlock.type },
173
- });
174
- return Object.assign(Object.assign({}, block), { children: updatedChildren });
175
- }
176
- }
177
- }
178
- return block;
179
- });
180
- if (!removedBlock) {
181
- console.warn('[removeBlockFromTree] Block not found in tree:', { blockId });
182
- }
183
- return { updatedBlocks, removedBlock };
184
- }
185
- /**
186
- * Update blocks recursively to move a nested block within the same container
187
- */
188
- function moveNestedBlock(blocks, containerId, blockId, newIndex) {
189
- return blocks.map(block => {
190
- if (block.id === containerId && block.children && Array.isArray(block.children)) {
191
- const children = typeof block.children[0] === 'object'
192
- ? block.children
193
- : [];
194
- const currentIndex = children.findIndex(b => b.id === blockId);
195
- if (currentIndex !== -1 && newIndex >= 0 && newIndex < children.length) {
196
- const updatedChildren = [...children];
197
- const [movedBlock] = updatedChildren.splice(currentIndex, 1);
198
- updatedChildren.splice(newIndex, 0, movedBlock);
199
- return Object.assign(Object.assign({}, block), { children: updatedChildren });
200
- }
201
- }
202
- if (block.children && Array.isArray(block.children) && block.children.length > 0) {
203
- if (typeof block.children[0] === 'object') {
204
- return Object.assign(Object.assign({}, block), { children: moveNestedBlock(block.children, containerId, blockId, newIndex) });
205
- }
206
- }
207
- return block;
208
- });
209
- }
210
- /**
211
- * Move a block to a container (handles cross-container moves)
212
- */
213
- function moveBlockToContainer(blocks, blockId, containerId, newIndex) {
214
- console.log('[moveBlockToContainer] Starting move:', {
215
- blockId,
216
- containerId,
217
- newIndex,
218
- });
219
- // First, find and remove the block from wherever it is
220
- const { updatedBlocks, removedBlock } = removeBlockFromTree(blocks, blockId);
221
- if (!removedBlock) {
222
- // Block not found, return unchanged
223
- console.warn('[moveBlockToContainer] Block not found, cannot move');
224
- return blocks;
225
- }
226
- console.log('[moveBlockToContainer] Block removed, now adding to container:', {
227
- removedBlock: { id: removedBlock.id, type: removedBlock.type },
228
- containerId,
229
- newIndex,
230
- });
231
- // Handle column containers
232
- const isColumnContainer = containerId.includes('-col-');
233
- if (isColumnContainer) {
234
- const [parentId, columnPart] = containerId.split('-col-');
235
- const columnIndex = parseInt(columnPart || '0', 10);
236
- removedBlock.meta = Object.assign(Object.assign({}, removedBlock.meta), { columnIndex });
237
- console.log('[moveBlockToContainer] Setting column index:', { columnIndex });
238
- }
239
- // Now add the block to the target container
240
- const result = addBlockToContainer(updatedBlocks, containerId, removedBlock, newIndex);
241
- console.log('[moveBlockToContainer] Move complete:', {
242
- resultBlocks: result.map(b => ({ id: b.id, type: b.type })),
243
- });
244
- return result;
245
- }
246
- /**
247
- * Editor Reducer
248
- * Handles all state transitions for the editor
249
- */
250
- export function editorReducer(state, action) {
251
- switch (action.type) {
252
- case 'SET_BLOCKS':
253
- return Object.assign(Object.assign({}, state), { blocks: action.payload, isDirty: true });
254
- case 'ADD_BLOCK': {
255
- const { block, index, containerId } = action.payload;
256
- const newBlock = Object.assign(Object.assign({}, block), { id: block.id || generateBlockId() });
257
- // If containerId is provided, add to container's children
258
- if (containerId) {
259
- const updatedBlocks = addBlockToContainer(state.blocks, containerId, newBlock, index);
260
- return Object.assign(Object.assign({}, state), { blocks: updatedBlocks, selectedBlockId: newBlock.id, isDirty: true });
261
- }
262
- // Otherwise, add to root level
263
- const newBlocks = [...state.blocks];
264
- if (index !== undefined && index >= 0 && index <= newBlocks.length) {
265
- newBlocks.splice(index, 0, newBlock);
266
- }
267
- else {
268
- newBlocks.push(newBlock);
269
- }
270
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, selectedBlockId: newBlock.id, isDirty: true });
271
- }
272
- case 'UPDATE_BLOCK': {
273
- const { id, data } = action.payload;
274
- // Check if block is at root level
275
- const rootBlock = state.blocks.find(block => block.id === id);
276
- if (rootBlock) {
277
- const newBlocks = state.blocks.map(block => block.id === id
278
- ? Object.assign(Object.assign({}, block), { data: Object.assign(Object.assign({}, block.data), data) }) : block);
279
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, isDirty: true });
280
- }
281
- // Otherwise, update nested block
282
- const newBlocks = updateNestedBlock(state.blocks, id, data);
283
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, isDirty: true });
284
- }
285
- case 'DELETE_BLOCK': {
286
- const { id } = action.payload;
287
- // Check if block is at root level
288
- const rootBlock = state.blocks.find(block => block.id === id);
289
- if (rootBlock) {
290
- const newBlocks = state.blocks.filter(block => block.id !== id);
291
- const wasSelected = state.selectedBlockId === id;
292
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, selectedBlockId: wasSelected ? null : state.selectedBlockId, isDirty: true });
293
- }
294
- // Otherwise, delete nested block
295
- const newBlocks = deleteNestedBlock(state.blocks, id);
296
- const wasSelected = state.selectedBlockId === id;
297
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, selectedBlockId: wasSelected ? null : state.selectedBlockId, isDirty: true });
298
- }
299
- case 'DUPLICATE_BLOCK': {
300
- const { id } = action.payload;
301
- const blockIndex = state.blocks.findIndex(block => block.id === id);
302
- if (blockIndex === -1) {
303
- return state;
304
- }
305
- const blockToDuplicate = state.blocks[blockIndex];
306
- const duplicatedBlock = cloneBlock(blockToDuplicate);
307
- const newBlocks = [...state.blocks];
308
- newBlocks.splice(blockIndex + 1, 0, duplicatedBlock);
309
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, selectedBlockId: duplicatedBlock.id, isDirty: true });
310
- }
311
- case 'MOVE_BLOCK': {
312
- const { id, newIndex, containerId: rawContainerId } = action.payload;
313
- // Normalize 'root' string to undefined
314
- const containerId = rawContainerId === 'root' || rawContainerId === undefined ? undefined : rawContainerId;
315
- console.log('[Reducer] MOVE_BLOCK action:', {
316
- blockId: id,
317
- newIndex,
318
- rawContainerId,
319
- normalizedContainerId: containerId || 'root',
320
- currentRootBlocks: state.blocks.map(b => ({ id: b.id, type: b.type, hasChildren: !!b.children })),
321
- });
322
- // If containerId is provided (and not 'root'), move to/within container
323
- if (containerId) {
324
- // First check if block is already in this container
325
- const containerBlock = findBlockById(state.blocks, containerId);
326
- console.log('[Reducer] Container lookup:', {
327
- containerId,
328
- found: !!containerBlock,
329
- hasChildren: (containerBlock === null || containerBlock === void 0 ? void 0 : containerBlock.children) ? Array.isArray(containerBlock.children) : false,
330
- });
331
- if (containerBlock && containerBlock.children && Array.isArray(containerBlock.children)) {
332
- const children = typeof containerBlock.children[0] === 'object'
333
- ? containerBlock.children
334
- : [];
335
- const currentIndex = children.findIndex(b => b.id === id);
336
- console.log('[Reducer] Block in container check:', {
337
- blockId: id,
338
- currentIndex,
339
- containerChildren: children.map(b => ({ id: b.id, type: b.type })),
340
- });
341
- if (currentIndex !== -1) {
342
- // Block is already in this container - move within container
343
- console.log('[Reducer] Moving within container');
344
- const newBlocks = moveNestedBlock(state.blocks, containerId, id, newIndex);
345
- console.log('[Reducer] After move within container:', {
346
- newRootBlocks: newBlocks.map(b => ({ id: b.id, type: b.type })),
347
- });
348
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, isDirty: true });
349
- }
350
- }
351
- // Block is not in this container - move it from wherever it is (root or nested)
352
- console.log('[Reducer] Moving block to container from elsewhere');
353
- const newBlocks = moveBlockToContainer(state.blocks, id, containerId, newIndex);
354
- console.log('[Reducer] After move to container:', {
355
- newRootBlocks: newBlocks.map(b => ({ id: b.id, type: b.type })),
356
- });
357
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, isDirty: true });
358
- }
359
- // Moving to root level (containerId is undefined)
360
- const currentIndex = state.blocks.findIndex(block => block.id === id);
361
- console.log('[Reducer] Moving to root level:', {
362
- blockId: id,
363
- currentIndex,
364
- isInRoot: currentIndex !== -1,
365
- newIndex,
366
- rootBlocksCount: state.blocks.length,
367
- });
368
- if (currentIndex !== -1) {
369
- // Block is already at root level - move within root
370
- if (newIndex < 0 || newIndex >= state.blocks.length) {
371
- console.warn('[Reducer] Invalid newIndex for root move:', { newIndex, blocksLength: state.blocks.length });
372
- return state;
373
- }
374
- console.log('[Reducer] Moving within root level');
375
- const newBlocks = [...state.blocks];
376
- const [movedBlock] = newBlocks.splice(currentIndex, 1);
377
- newBlocks.splice(newIndex, 0, movedBlock);
378
- console.log('[Reducer] After move within root:', {
379
- newRootBlocks: newBlocks.map(b => ({ id: b.id, type: b.type })),
380
- });
381
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, isDirty: true });
382
- }
383
- // Block is nested somewhere - move it to root level
384
- console.log('[Reducer] Block is nested, removing from tree and adding to root');
385
- const { updatedBlocks, removedBlock } = removeBlockFromTree(state.blocks, id);
386
- console.log('[Reducer] Block removal result:', {
387
- removedBlock: removedBlock ? { id: removedBlock.id, type: removedBlock.type } : null,
388
- updatedBlocksCount: updatedBlocks.length,
389
- });
390
- if (removedBlock) {
391
- // Clear any nested metadata (like columnIndex)
392
- const cleanedBlock = Object.assign(Object.assign({}, removedBlock), { meta: removedBlock.meta ? Object.assign(Object.assign({}, removedBlock.meta), { columnIndex: undefined }) : undefined });
393
- const newBlocks = [...updatedBlocks];
394
- if (newIndex >= 0 && newIndex <= newBlocks.length) {
395
- newBlocks.splice(newIndex, 0, cleanedBlock);
396
- }
397
- else {
398
- newBlocks.push(cleanedBlock);
399
- }
400
- console.log('[Reducer] After move nested to root:', {
401
- newRootBlocks: newBlocks.map(b => ({ id: b.id, type: b.type })),
402
- insertedAt: newIndex >= 0 && newIndex <= updatedBlocks.length ? newIndex : newBlocks.length - 1,
403
- });
404
- return Object.assign(Object.assign({}, state), { blocks: newBlocks, isDirty: true });
405
- }
406
- console.warn('[Reducer] Block not found in tree:', { blockId: id });
407
- return state;
408
- }
409
- case 'SET_TITLE':
410
- return Object.assign(Object.assign({}, state), { title: action.payload, isDirty: true });
411
- case 'SET_SLUG':
412
- return Object.assign(Object.assign({}, state), { slug: action.payload, isDirty: true });
413
- case 'SET_SEO':
414
- return Object.assign(Object.assign({}, state), { seo: Object.assign(Object.assign({}, state.seo), action.payload), isDirty: true });
415
- case 'SET_METADATA':
416
- return Object.assign(Object.assign({}, state), { metadata: Object.assign(Object.assign({}, state.metadata), action.payload), isDirty: true });
417
- case 'SET_STATUS':
418
- return Object.assign(Object.assign({}, state), { status: action.payload, isDirty: true });
419
- case 'SET_FOCUS_MODE':
420
- return Object.assign(Object.assign({}, state), { focusMode: action.payload });
421
- case 'SELECT_BLOCK':
422
- return Object.assign(Object.assign({}, state), { selectedBlockId: action.payload });
423
- case 'SET_DRAGGED_BLOCK':
424
- return Object.assign(Object.assign({}, state), { draggedBlockId: action.payload });
425
- case 'LOAD_POST': {
426
- const post = action.payload;
427
- return Object.assign(Object.assign({}, state), { blocks: post.blocks, title: post.title, slug: post.slug, seo: post.seo, metadata: post.metadata, status: post.publication.status, postId: post.id, isDirty: false, selectedBlockId: null });
428
- }
429
- case 'RESET_EDITOR':
430
- return Object.assign({}, initialEditorState);
431
- case 'MARK_CLEAN':
432
- return Object.assign(Object.assign({}, state), { isDirty: false });
433
- case 'MARK_DIRTY':
434
- return Object.assign(Object.assign({}, state), { isDirty: true });
435
- case 'UNDO':
436
- case 'REDO':
437
- case 'SAVE_HISTORY':
438
- // These are handled by the context, not the reducer
439
- return state;
440
- default:
441
- return state;
442
- }
443
- }