@jhits/plugin-blog 0.0.9 → 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 +58 -59
  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,142 +0,0 @@
1
- import { useEffect } from 'react';
2
- import type { Block } from '../../../types/block';
3
- import type { EditorState } from '../../../state/types';
4
-
5
- // Generate a unique block ID
6
- function generateBlockId(): string {
7
- if (typeof crypto !== 'undefined' && crypto.randomUUID) {
8
- return crypto.randomUUID();
9
- }
10
- return `block-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
11
- }
12
-
13
- export function useKeyboardShortcuts(
14
- state: EditorState,
15
- dispatch: (action: any) => void,
16
- canUndo: boolean,
17
- canRedo: boolean,
18
- undo: () => void,
19
- redo: () => void
20
- ) {
21
- useEffect(() => {
22
- const handleKeyDown = (e: KeyboardEvent) => {
23
- // Don't handle shortcuts if user is typing in an input/textarea/contentEditable
24
- const target = e.target as HTMLElement;
25
- const isEditableElement = target.tagName === 'INPUT' ||
26
- target.tagName === 'TEXTAREA' ||
27
- target.isContentEditable ||
28
- target.closest('input, textarea, [contenteditable="true"]');
29
-
30
- // Check for Ctrl+Z / Cmd+Z (Undo)
31
- if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {
32
- if (!isEditableElement) {
33
- e.preventDefault();
34
- e.stopPropagation();
35
- if (canUndo) {
36
- undo();
37
- }
38
- return;
39
- }
40
- }
41
-
42
- // Check for Ctrl+Shift+Z / Cmd+Shift+Z or Ctrl+Y / Cmd+Y (Redo)
43
- if (((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'z') || ((e.ctrlKey || e.metaKey) && e.key === 'y')) {
44
- if (!isEditableElement) {
45
- e.preventDefault();
46
- e.stopPropagation();
47
- if (canRedo) {
48
- redo();
49
- }
50
- return;
51
- }
52
- }
53
-
54
- // Check for Ctrl+V (Windows/Linux) or Cmd+V (Mac)
55
- if ((e.ctrlKey || e.metaKey) && e.key === 'v') {
56
- // Don't paste if user is typing in an input/textarea/contentEditable
57
- const target = e.target as HTMLElement;
58
- const isEditableElement = target.tagName === 'INPUT' ||
59
- target.tagName === 'TEXTAREA' ||
60
- target.isContentEditable ||
61
- target.closest('input, textarea, [contenteditable="true"]');
62
-
63
- if (isEditableElement) {
64
- return; // Let the browser handle paste in editable elements
65
- }
66
-
67
- // Check if there's a copied block
68
- if (typeof window !== 'undefined') {
69
- const copiedBlockJson = localStorage.getItem('__BLOG_EDITOR_COPIED_BLOCK__');
70
- if (copiedBlockJson) {
71
- try {
72
- e.preventDefault();
73
- e.stopPropagation();
74
-
75
- const copiedBlock = JSON.parse(copiedBlockJson) as Block;
76
-
77
- // Clone a block with new IDs (recursive for nested blocks)
78
- const cloneBlock = (blockToClone: Block): Block => {
79
- const cloned: Block = {
80
- ...blockToClone,
81
- id: generateBlockId(),
82
- data: { ...blockToClone.data },
83
- meta: blockToClone.meta ? { ...blockToClone.meta } : undefined,
84
- };
85
-
86
- // Handle children if they exist
87
- if (blockToClone.children) {
88
- if (Array.isArray(blockToClone.children) && blockToClone.children.length > 0) {
89
- if (typeof blockToClone.children[0] === 'object') {
90
- cloned.children = (blockToClone.children as Block[]).map(cloneBlock);
91
- } else {
92
- // If children are IDs, find and clone the actual blocks
93
- const allBlocks = state.blocks;
94
- const childIds = blockToClone.children as string[];
95
- const childBlocks = childIds
96
- .map((childId: string) => allBlocks.find(b => b.id === childId))
97
- .filter((b): b is Block => b !== undefined);
98
- cloned.children = childBlocks.map(cloneBlock);
99
- }
100
- }
101
- }
102
-
103
- return cloned;
104
- };
105
-
106
- const pastedBlock = cloneBlock(copiedBlock);
107
-
108
- // Find where to paste - use hovered block or selected block, or paste at end
109
- const hoveredBlockId = (window as any).__BLOG_EDITOR_HOVERED_BLOCK_ID__;
110
- const targetBlockId = hoveredBlockId || state.selectedBlockId;
111
-
112
- let pasteIndex: number | undefined;
113
- if (targetBlockId) {
114
- const targetIndex = state.blocks.findIndex(b => b.id === targetBlockId);
115
- if (targetIndex !== -1) {
116
- pasteIndex = targetIndex + 1;
117
- }
118
- }
119
-
120
- // Dispatch ADD_BLOCK with the full block structure
121
- dispatch({
122
- type: 'ADD_BLOCK',
123
- payload: {
124
- block: pastedBlock,
125
- index: pasteIndex,
126
- containerId: undefined
127
- }
128
- });
129
- } catch (error) {
130
- console.error('Failed to paste block:', error);
131
- }
132
- }
133
- }
134
- }
135
- };
136
-
137
- window.addEventListener('keydown', handleKeyDown);
138
- return () => {
139
- window.removeEventListener('keydown', handleKeyDown);
140
- };
141
- }, [state.blocks, state.selectedBlockId, dispatch, canUndo, canRedo, undo, redo]);
142
- }
@@ -1,5 +0,0 @@
1
- import type { BlogPost } from '../../../types/post';
2
- export declare function usePostLoader(postId: string | undefined, currentPostId: string | null, loadPost: (post: BlogPost) => void, resetHeroBlock: () => void): {
3
- isLoadingPost: boolean;
4
- };
5
- //# sourceMappingURL=usePostLoader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePostLoader.d.ts","sourceRoot":"","sources":["usePostLoader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,aAAa,EAAE,MAAM,GAAG,IAAI,EAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,EAClC,cAAc,EAAE,MAAM,IAAI;;EA8B7B"}
@@ -1,32 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { apiToBlogPost } from '../../../lib/mappers/apiMapper';
3
- export function usePostLoader(postId, currentPostId, loadPost, resetHeroBlock) {
4
- const [isLoadingPost, setIsLoadingPost] = useState(false);
5
- useEffect(() => {
6
- if (postId && !currentPostId) {
7
- const loadPostData = async () => {
8
- try {
9
- setIsLoadingPost(true);
10
- // Reset hero block before loading new post so it gets re-initialized from the new post's blocks
11
- resetHeroBlock();
12
- const response = await fetch(`/api/plugin-blog/${postId}`);
13
- if (!response.ok) {
14
- throw new Error('Failed to load post');
15
- }
16
- const apiDoc = await response.json();
17
- const blogPost = apiToBlogPost(apiDoc);
18
- loadPost(blogPost);
19
- }
20
- catch (error) {
21
- console.error('Failed to load post:', error);
22
- alert('Failed to load post. Please try again.');
23
- }
24
- finally {
25
- setIsLoadingPost(false);
26
- }
27
- };
28
- loadPostData();
29
- }
30
- }, [postId, currentPostId, loadPost, resetHeroBlock]);
31
- return { isLoadingPost };
32
- }
@@ -1,39 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { apiToBlogPost, type APIBlogDocument } from '../../../lib/mappers/apiMapper';
3
- import type { BlogPost } from '../../../types/post';
4
-
5
- export function usePostLoader(
6
- postId: string | undefined,
7
- currentPostId: string | null,
8
- loadPost: (post: BlogPost) => void,
9
- resetHeroBlock: () => void
10
- ) {
11
- const [isLoadingPost, setIsLoadingPost] = useState(false);
12
-
13
- useEffect(() => {
14
- if (postId && !currentPostId) {
15
- const loadPostData = async () => {
16
- try {
17
- setIsLoadingPost(true);
18
- // Reset hero block before loading new post so it gets re-initialized from the new post's blocks
19
- resetHeroBlock();
20
- const response = await fetch(`/api/plugin-blog/${postId}`);
21
- if (!response.ok) {
22
- throw new Error('Failed to load post');
23
- }
24
- const apiDoc: APIBlogDocument = await response.json();
25
- const blogPost = apiToBlogPost(apiDoc);
26
- loadPost(blogPost);
27
- } catch (error) {
28
- console.error('Failed to load post:', error);
29
- alert('Failed to load post. Please try again.');
30
- } finally {
31
- setIsLoadingPost(false);
32
- }
33
- };
34
- loadPostData();
35
- }
36
- }, [postId, currentPostId, loadPost, resetHeroBlock]);
37
-
38
- return { isLoadingPost };
39
- }
@@ -1,2 +0,0 @@
1
- export declare function useRegisteredBlocks(): import("../../..").BlockTypeDefinition[];
2
- //# sourceMappingURL=useRegisteredBlocks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRegisteredBlocks.d.ts","sourceRoot":"","sources":["useRegisteredBlocks.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB,6CAmDlC"}
@@ -1,47 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import { blockRegistry } from '../../../registry/BlockRegistry';
3
- export function useRegisteredBlocks() {
4
- const [registeredBlocks, setRegisteredBlocks] = useState(() => {
5
- const initial = blockRegistry.getAll();
6
- return initial;
7
- });
8
- // Watch for registry changes and update state
9
- useEffect(() => {
10
- // Check immediately
11
- const checkBlocks = () => {
12
- const currentBlocks = blockRegistry.getAll();
13
- const hasChanged = currentBlocks.length !== registeredBlocks.length ||
14
- currentBlocks.some((b, i) => { var _a; return b.type !== ((_a = registeredBlocks[i]) === null || _a === void 0 ? void 0 : _a.type); }) ||
15
- registeredBlocks.some((b, i) => { var _a; return b.type !== ((_a = currentBlocks[i]) === null || _a === void 0 ? void 0 : _a.type); });
16
- if (hasChanged) {
17
- setRegisteredBlocks([...currentBlocks]);
18
- }
19
- };
20
- // Initial check
21
- checkBlocks();
22
- // Poll for registry changes (blocks are registered asynchronously in useEffect)
23
- // Use a shorter interval initially, then longer
24
- let pollCount = 0;
25
- const interval = setInterval(() => {
26
- pollCount++;
27
- checkBlocks();
28
- // Stop polling after 5 seconds (25 checks at 200ms)
29
- if (pollCount > 25) {
30
- clearInterval(interval);
31
- }
32
- }, 200);
33
- // Also check after delays to catch initial registrations
34
- const timeouts = [
35
- setTimeout(checkBlocks, 50),
36
- setTimeout(checkBlocks, 100),
37
- setTimeout(checkBlocks, 300),
38
- setTimeout(checkBlocks, 500),
39
- setTimeout(checkBlocks, 1000),
40
- ];
41
- return () => {
42
- clearInterval(interval);
43
- timeouts.forEach(clearTimeout);
44
- };
45
- }, [registeredBlocks.length]);
46
- return registeredBlocks;
47
- }
@@ -1,55 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import { blockRegistry } from '../../../registry/BlockRegistry';
3
-
4
- export function useRegisteredBlocks() {
5
- const [registeredBlocks, setRegisteredBlocks] = useState(() => {
6
- const initial = blockRegistry.getAll();
7
- return initial;
8
- });
9
-
10
- // Watch for registry changes and update state
11
- useEffect(() => {
12
- // Check immediately
13
- const checkBlocks = () => {
14
- const currentBlocks = blockRegistry.getAll();
15
- const hasChanged = currentBlocks.length !== registeredBlocks.length ||
16
- currentBlocks.some((b, i) => b.type !== registeredBlocks[i]?.type) ||
17
- registeredBlocks.some((b, i) => b.type !== currentBlocks[i]?.type);
18
-
19
- if (hasChanged) {
20
- setRegisteredBlocks([...currentBlocks]);
21
- }
22
- };
23
-
24
- // Initial check
25
- checkBlocks();
26
-
27
- // Poll for registry changes (blocks are registered asynchronously in useEffect)
28
- // Use a shorter interval initially, then longer
29
- let pollCount = 0;
30
- const interval = setInterval(() => {
31
- pollCount++;
32
- checkBlocks();
33
- // Stop polling after 5 seconds (25 checks at 200ms)
34
- if (pollCount > 25) {
35
- clearInterval(interval);
36
- }
37
- }, 200);
38
-
39
- // Also check after delays to catch initial registrations
40
- const timeouts = [
41
- setTimeout(checkBlocks, 50),
42
- setTimeout(checkBlocks, 100),
43
- setTimeout(checkBlocks, 300),
44
- setTimeout(checkBlocks, 500),
45
- setTimeout(checkBlocks, 1000),
46
- ];
47
-
48
- return () => {
49
- clearInterval(interval);
50
- timeouts.forEach(clearTimeout);
51
- };
52
- }, [registeredBlocks.length]);
53
-
54
- return registeredBlocks;
55
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Hook for managing unsaved changes warnings and auto-save
3
- */
4
- import type { EditorState } from '../../../state/types';
5
- import type { Block } from '../../../types/block';
6
- interface UseUnsavedChangesOptions {
7
- state: EditorState;
8
- isDirty: boolean;
9
- onSave: (heroBlock?: Block | null) => Promise<void>;
10
- heroBlock?: Block | null;
11
- autoSaveEnabled?: boolean;
12
- autoSaveDelay?: number;
13
- postId?: string | null;
14
- }
15
- /**
16
- * Hook to manage unsaved changes warnings and auto-save
17
- */
18
- export declare function useUnsavedChanges({ state, isDirty, onSave, heroBlock, autoSaveEnabled: propAutoSaveEnabled, autoSaveDelay, postId, }: UseUnsavedChangesOptions): {
19
- autoSaveEnabled: boolean;
20
- setAutoSaveEnabled: (enabled: boolean) => void;
21
- countdown: number | null;
22
- saveStatus: "error" | "idle" | "saving" | "saved";
23
- };
24
- export {};
25
- //# sourceMappingURL=useUnsavedChanges.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useUnsavedChanges.d.ts","sourceRoot":"","sources":["useUnsavedChanges.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,UAAU,wBAAwB;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,SAAS,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAKD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAC9B,KAAK,EACL,OAAO,EACP,MAAM,EACN,SAAS,EACT,eAAe,EAAE,mBAAmB,EACpC,aAAuC,EACvC,MAAM,GACT,EAAE,wBAAwB;;kCAoD6B,OAAO;;;EA4P9D"}
@@ -1,285 +0,0 @@
1
- /**
2
- * Hook for managing unsaved changes warnings and auto-save
3
- */
4
- 'use client';
5
- import { useEffect, useRef, useCallback, useState } from 'react';
6
- const AUTO_SAVE_STORAGE_KEY = 'blog-editor-autosave-enabled';
7
- const DEFAULT_AUTO_SAVE_DELAY = 10000; // 10 seconds
8
- /**
9
- * Hook to manage unsaved changes warnings and auto-save
10
- */
11
- export function useUnsavedChanges({ state, isDirty, onSave, heroBlock, autoSaveEnabled: propAutoSaveEnabled, autoSaveDelay = DEFAULT_AUTO_SAVE_DELAY, postId, }) {
12
- const autoSaveTimeoutRef = useRef(null);
13
- const isSavingRef = useRef(false);
14
- const lastSavedStateRef = useRef('');
15
- const countdownIntervalRef = useRef(null);
16
- const [countdown, setCountdown] = useState(null);
17
- const [saveStatus, setSaveStatus] = useState('idle');
18
- const saveStatusTimeoutRef = useRef(null);
19
- const previousIsDirtyRef = useRef(false);
20
- const countdownStartTimeRef = useRef(null);
21
- const performAutoSaveRef = useRef(null);
22
- // Get auto-save preference from localStorage
23
- const getAutoSavePreference = useCallback(() => {
24
- if (typeof window === 'undefined')
25
- return false;
26
- try {
27
- const stored = localStorage.getItem(AUTO_SAVE_STORAGE_KEY);
28
- if (stored !== null) {
29
- return stored === 'true';
30
- }
31
- }
32
- catch (error) {
33
- console.error('[useUnsavedChanges] Failed to read auto-save preference:', error);
34
- }
35
- // Default to false if not set
36
- return false;
37
- }, []);
38
- // State to track auto-save enabled status (reactive)
39
- const [autoSaveEnabledState, setAutoSaveEnabledState] = useState(() => {
40
- // Initialize from prop or localStorage
41
- if (propAutoSaveEnabled !== undefined) {
42
- return propAutoSaveEnabled;
43
- }
44
- return getAutoSavePreference();
45
- });
46
- // Sync with prop changes
47
- useEffect(() => {
48
- if (propAutoSaveEnabled !== undefined) {
49
- setAutoSaveEnabledState(propAutoSaveEnabled);
50
- }
51
- }, [propAutoSaveEnabled]);
52
- // Initialize from localStorage on mount (if no prop provided)
53
- useEffect(() => {
54
- if (propAutoSaveEnabled === undefined && typeof window !== 'undefined') {
55
- const stored = getAutoSavePreference();
56
- setAutoSaveEnabledState(stored);
57
- }
58
- }, []); // Only run on mount
59
- // Set auto-save preference in localStorage and state
60
- const setAutoSavePreference = useCallback((enabled) => {
61
- if (typeof window === 'undefined')
62
- return;
63
- try {
64
- localStorage.setItem(AUTO_SAVE_STORAGE_KEY, enabled.toString());
65
- setAutoSaveEnabledState(enabled);
66
- console.log('[useUnsavedChanges] Auto-save preference updated:', enabled);
67
- }
68
- catch (error) {
69
- console.error('[useUnsavedChanges] Failed to save auto-save preference:', error);
70
- }
71
- }, []);
72
- // Determine if auto-save is enabled (prop takes precedence over state)
73
- const autoSaveEnabled = propAutoSaveEnabled !== undefined
74
- ? propAutoSaveEnabled
75
- : autoSaveEnabledState;
76
- // Create a stable reference of the current state for comparison
77
- const getStateSnapshot = useCallback(() => {
78
- return JSON.stringify({
79
- title: state.title,
80
- slug: state.slug,
81
- blocks: state.blocks,
82
- seo: state.seo,
83
- metadata: state.metadata,
84
- status: state.status,
85
- });
86
- }, [state]);
87
- // Initialize lastSavedStateRef when a post is loaded and marked as clean
88
- useEffect(() => {
89
- // When a post is loaded (postId exists) and isDirty is false, update the saved state reference
90
- if (postId && !isDirty && lastSavedStateRef.current === '') {
91
- lastSavedStateRef.current = getStateSnapshot();
92
- console.log('[useUnsavedChanges] Initialized saved state reference after post load');
93
- }
94
- // Also update if isDirty becomes false after being true (e.g., after save or MARK_CLEAN)
95
- if (!isDirty && lastSavedStateRef.current !== getStateSnapshot()) {
96
- lastSavedStateRef.current = getStateSnapshot();
97
- }
98
- }, [postId, isDirty, getStateSnapshot]);
99
- // Auto-save function
100
- const performAutoSave = useCallback(async () => {
101
- if (isSavingRef.current || !isDirty) {
102
- return;
103
- }
104
- try {
105
- isSavingRef.current = true;
106
- setSaveStatus('saving');
107
- setCountdown(null);
108
- countdownStartTimeRef.current = null;
109
- console.log('[useUnsavedChanges] Auto-saving...');
110
- await onSave(heroBlock);
111
- lastSavedStateRef.current = getStateSnapshot();
112
- setSaveStatus('saved');
113
- console.log('[useUnsavedChanges] Auto-save completed');
114
- // Clear save status after 2 seconds
115
- if (saveStatusTimeoutRef.current) {
116
- clearTimeout(saveStatusTimeoutRef.current);
117
- }
118
- saveStatusTimeoutRef.current = setTimeout(() => {
119
- setSaveStatus('idle');
120
- }, 2000);
121
- }
122
- catch (error) {
123
- console.error('[useUnsavedChanges] Auto-save failed:', error);
124
- setSaveStatus('error');
125
- // Clear error status after 3 seconds
126
- if (saveStatusTimeoutRef.current) {
127
- clearTimeout(saveStatusTimeoutRef.current);
128
- }
129
- saveStatusTimeoutRef.current = setTimeout(() => {
130
- setSaveStatus('idle');
131
- }, 3000);
132
- }
133
- finally {
134
- isSavingRef.current = false;
135
- }
136
- }, [isDirty, onSave, heroBlock, getStateSnapshot]);
137
- // Keep ref updated with latest function
138
- useEffect(() => {
139
- performAutoSaveRef.current = performAutoSave;
140
- }, [performAutoSave]);
141
- // Set up auto-save timer and countdown when state changes
142
- useEffect(() => {
143
- // Only reset countdown if isDirty changed from false to true, or if auto-save was just disabled
144
- const isDirtyChanged = previousIsDirtyRef.current !== isDirty;
145
- const becameDirty = !previousIsDirtyRef.current && isDirty;
146
- // Update previous isDirty ref
147
- previousIsDirtyRef.current = isDirty;
148
- // Clear existing countdown interval
149
- if (countdownIntervalRef.current) {
150
- clearInterval(countdownIntervalRef.current);
151
- countdownIntervalRef.current = null;
152
- }
153
- if (!autoSaveEnabled || !isDirty || isSavingRef.current) {
154
- setCountdown(null);
155
- countdownStartTimeRef.current = null;
156
- // Clear timeout if auto-save is disabled or not dirty
157
- if (autoSaveTimeoutRef.current) {
158
- clearTimeout(autoSaveTimeoutRef.current);
159
- autoSaveTimeoutRef.current = null;
160
- }
161
- return;
162
- }
163
- // Only reset countdown if:
164
- // 1. isDirty just became true (new changes)
165
- // 2. Or if there's no active countdown
166
- const shouldResetCountdown = becameDirty || countdownStartTimeRef.current === null;
167
- if (shouldResetCountdown) {
168
- // Clear existing timeout
169
- if (autoSaveTimeoutRef.current) {
170
- clearTimeout(autoSaveTimeoutRef.current);
171
- }
172
- // Initialize countdown
173
- const secondsRemaining = Math.ceil(autoSaveDelay / 1000);
174
- setCountdown(secondsRemaining);
175
- countdownStartTimeRef.current = Date.now();
176
- // Set new timeout for auto-save
177
- autoSaveTimeoutRef.current = setTimeout(() => {
178
- if (performAutoSaveRef.current) {
179
- performAutoSaveRef.current();
180
- }
181
- }, autoSaveDelay);
182
- }
183
- else {
184
- // Countdown is already running, just update it based on elapsed time
185
- if (countdownStartTimeRef.current && autoSaveTimeoutRef.current) {
186
- const elapsed = Date.now() - countdownStartTimeRef.current;
187
- const remaining = Math.max(0, autoSaveDelay - elapsed);
188
- const secondsRemaining = Math.ceil(remaining / 1000);
189
- setCountdown(secondsRemaining);
190
- }
191
- }
192
- // Update countdown every second (only if we have an active countdown)
193
- if (shouldResetCountdown || countdownIntervalRef.current === null) {
194
- countdownIntervalRef.current = setInterval(() => {
195
- if (countdownStartTimeRef.current && autoSaveTimeoutRef.current) {
196
- const elapsed = Date.now() - countdownStartTimeRef.current;
197
- const remaining = Math.max(0, autoSaveDelay - elapsed);
198
- const secondsRemaining = Math.ceil(remaining / 1000);
199
- if (secondsRemaining <= 0) {
200
- setCountdown(null);
201
- if (countdownIntervalRef.current) {
202
- clearInterval(countdownIntervalRef.current);
203
- countdownIntervalRef.current = null;
204
- }
205
- }
206
- else {
207
- setCountdown(secondsRemaining);
208
- }
209
- }
210
- }, 1000);
211
- }
212
- return () => {
213
- if (autoSaveTimeoutRef.current) {
214
- clearTimeout(autoSaveTimeoutRef.current);
215
- }
216
- if (countdownIntervalRef.current) {
217
- clearInterval(countdownIntervalRef.current);
218
- }
219
- };
220
- }, [autoSaveEnabled, isDirty, autoSaveDelay]);
221
- // Handle browser beforeunload event (page refresh/close)
222
- useEffect(() => {
223
- if (!isDirty) {
224
- return;
225
- }
226
- const handleBeforeUnload = (e) => {
227
- e.preventDefault();
228
- // Modern browsers ignore custom messages, but we still need to set returnValue
229
- e.returnValue = '';
230
- return '';
231
- };
232
- window.addEventListener('beforeunload', handleBeforeUnload);
233
- return () => {
234
- window.removeEventListener('beforeunload', handleBeforeUnload);
235
- };
236
- }, [isDirty]);
237
- // Handle link clicks (for Next.js App Router)
238
- useEffect(() => {
239
- if (!isDirty) {
240
- return;
241
- }
242
- const handleLinkClick = (e) => {
243
- const target = e.target;
244
- const link = target.closest('a');
245
- if (link && link.href) {
246
- const url = new URL(link.href);
247
- const currentPath = window.location.pathname;
248
- // Check if navigating away from editor
249
- if (!url.pathname.includes('/blog/editor') && !url.pathname.includes('/blog/new')) {
250
- const confirmed = window.confirm('You have unsaved changes. Are you sure you want to leave? Your changes will be lost.');
251
- if (!confirmed) {
252
- e.preventDefault();
253
- e.stopPropagation();
254
- return false;
255
- }
256
- }
257
- }
258
- };
259
- // Listen for clicks on links
260
- document.addEventListener('click', handleLinkClick, true);
261
- return () => {
262
- document.removeEventListener('click', handleLinkClick, true);
263
- };
264
- }, [isDirty]);
265
- // Cleanup on unmount
266
- useEffect(() => {
267
- return () => {
268
- if (autoSaveTimeoutRef.current) {
269
- clearTimeout(autoSaveTimeoutRef.current);
270
- }
271
- if (countdownIntervalRef.current) {
272
- clearInterval(countdownIntervalRef.current);
273
- }
274
- if (saveStatusTimeoutRef.current) {
275
- clearTimeout(saveStatusTimeoutRef.current);
276
- }
277
- };
278
- }, []);
279
- return {
280
- autoSaveEnabled,
281
- setAutoSaveEnabled: setAutoSavePreference,
282
- countdown,
283
- saveStatus,
284
- };
285
- }