@jhits/plugin-blog 0.0.1
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/README.md +216 -0
- package/package.json +57 -0
- package/src/api/README.md +224 -0
- package/src/api/categories.ts +43 -0
- package/src/api/check-title.ts +60 -0
- package/src/api/handler.ts +419 -0
- package/src/api/index.ts +33 -0
- package/src/api/route.ts +116 -0
- package/src/api/router.ts +114 -0
- package/src/api-server.ts +11 -0
- package/src/config.ts +161 -0
- package/src/hooks/README.md +91 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useBlog.ts +85 -0
- package/src/hooks/useBlogs.ts +123 -0
- package/src/index.server.ts +12 -0
- package/src/index.tsx +354 -0
- package/src/init.tsx +72 -0
- package/src/lib/blocks/BlockRenderer.tsx +141 -0
- package/src/lib/blocks/index.ts +6 -0
- package/src/lib/index.ts +9 -0
- package/src/lib/layouts/blocks/ColumnsBlock.tsx +134 -0
- package/src/lib/layouts/blocks/SectionBlock.tsx +104 -0
- package/src/lib/layouts/blocks/index.ts +8 -0
- package/src/lib/layouts/index.ts +52 -0
- package/src/lib/layouts/registerLayoutBlocks.ts +59 -0
- package/src/lib/mappers/apiMapper.ts +223 -0
- package/src/lib/migration/index.ts +6 -0
- package/src/lib/migration/mapper.ts +140 -0
- package/src/lib/rich-text/RichTextEditor.tsx +826 -0
- package/src/lib/rich-text/RichTextPreview.tsx +210 -0
- package/src/lib/rich-text/index.ts +10 -0
- package/src/lib/utils/blockHelpers.ts +72 -0
- package/src/lib/utils/configValidation.ts +137 -0
- package/src/lib/utils/index.ts +8 -0
- package/src/lib/utils/slugify.ts +79 -0
- package/src/registry/BlockRegistry.ts +142 -0
- package/src/registry/index.ts +11 -0
- package/src/state/EditorContext.tsx +277 -0
- package/src/state/index.ts +8 -0
- package/src/state/reducer.ts +694 -0
- package/src/state/types.ts +160 -0
- package/src/types/block.ts +269 -0
- package/src/types/index.ts +15 -0
- package/src/types/post.ts +165 -0
- package/src/utils/README.md +75 -0
- package/src/utils/client.ts +122 -0
- package/src/utils/index.ts +9 -0
- package/src/views/CanvasEditor/BlockWrapper.tsx +459 -0
- package/src/views/CanvasEditor/CanvasEditorView.tsx +917 -0
- package/src/views/CanvasEditor/EditorBody.tsx +475 -0
- package/src/views/CanvasEditor/EditorHeader.tsx +179 -0
- package/src/views/CanvasEditor/LayoutContainer.tsx +494 -0
- package/src/views/CanvasEditor/SaveConfirmationModal.tsx +233 -0
- package/src/views/CanvasEditor/components/CustomBlockItem.tsx +92 -0
- package/src/views/CanvasEditor/components/FeaturedMediaSection.tsx +130 -0
- package/src/views/CanvasEditor/components/LibraryItem.tsx +80 -0
- package/src/views/CanvasEditor/components/PrivacySettingsSection.tsx +212 -0
- package/src/views/CanvasEditor/components/index.ts +17 -0
- package/src/views/CanvasEditor/index.ts +16 -0
- package/src/views/PostManager/EmptyState.tsx +42 -0
- package/src/views/PostManager/PostActionsMenu.tsx +112 -0
- package/src/views/PostManager/PostCards.tsx +192 -0
- package/src/views/PostManager/PostFilters.tsx +80 -0
- package/src/views/PostManager/PostManagerView.tsx +280 -0
- package/src/views/PostManager/PostStats.tsx +81 -0
- package/src/views/PostManager/PostTable.tsx +225 -0
- package/src/views/PostManager/index.ts +15 -0
- package/src/views/Preview/PreviewBridgeView.tsx +64 -0
- package/src/views/Preview/index.ts +7 -0
- package/src/views/README.md +82 -0
- package/src/views/Settings/SettingsView.tsx +298 -0
- package/src/views/Settings/index.ts +7 -0
- package/src/views/SlugSEO/SlugSEOManagerView.tsx +94 -0
- package/src/views/SlugSEO/index.ts +7 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Management Types
|
|
3
|
+
* Types for the editor state management system
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Block } from '../types/block';
|
|
7
|
+
import { BlogPost, PostStatus, SEOMetadata, PostMetadata } from '../types/post';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Editor State
|
|
11
|
+
* Represents the current state of the editor
|
|
12
|
+
*/
|
|
13
|
+
export interface EditorState {
|
|
14
|
+
/** Array of blocks in the editor */
|
|
15
|
+
blocks: Block[];
|
|
16
|
+
|
|
17
|
+
/** Post title */
|
|
18
|
+
title: string;
|
|
19
|
+
|
|
20
|
+
/** Post slug */
|
|
21
|
+
slug: string;
|
|
22
|
+
|
|
23
|
+
/** SEO metadata */
|
|
24
|
+
seo: SEOMetadata;
|
|
25
|
+
|
|
26
|
+
/** Post metadata */
|
|
27
|
+
metadata: PostMetadata;
|
|
28
|
+
|
|
29
|
+
/** Publication status */
|
|
30
|
+
status: PostStatus;
|
|
31
|
+
|
|
32
|
+
/** Whether the post has unsaved changes */
|
|
33
|
+
isDirty: boolean;
|
|
34
|
+
|
|
35
|
+
/** Whether the editor is in focus mode */
|
|
36
|
+
focusMode: boolean;
|
|
37
|
+
|
|
38
|
+
/** Currently selected block ID */
|
|
39
|
+
selectedBlockId: string | null;
|
|
40
|
+
|
|
41
|
+
/** Currently dragged block ID */
|
|
42
|
+
draggedBlockId: string | null;
|
|
43
|
+
|
|
44
|
+
/** Post ID (if editing existing post) */
|
|
45
|
+
postId: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Editor Actions
|
|
50
|
+
* Actions that can be dispatched to modify editor state
|
|
51
|
+
*/
|
|
52
|
+
export type EditorAction =
|
|
53
|
+
| { type: 'SET_BLOCKS'; payload: Block[] }
|
|
54
|
+
| { type: 'ADD_BLOCK'; payload: { block: Block; index?: number; containerId?: string } }
|
|
55
|
+
| { type: 'UPDATE_BLOCK'; payload: { id: string; data: Partial<Block['data']> } }
|
|
56
|
+
| { type: 'DELETE_BLOCK'; payload: { id: string } }
|
|
57
|
+
| { type: 'DUPLICATE_BLOCK'; payload: { id: string } }
|
|
58
|
+
| { type: 'MOVE_BLOCK'; payload: { id: string; newIndex: number; containerId?: string } }
|
|
59
|
+
| { type: 'SET_TITLE'; payload: string }
|
|
60
|
+
| { type: 'SET_SLUG'; payload: string }
|
|
61
|
+
| { type: 'SET_SEO'; payload: Partial<SEOMetadata> }
|
|
62
|
+
| { type: 'SET_METADATA'; payload: Partial<PostMetadata> }
|
|
63
|
+
| { type: 'SET_STATUS'; payload: PostStatus }
|
|
64
|
+
| { type: 'SET_FOCUS_MODE'; payload: boolean }
|
|
65
|
+
| { type: 'SELECT_BLOCK'; payload: string | null }
|
|
66
|
+
| { type: 'SET_DRAGGED_BLOCK'; payload: string | null }
|
|
67
|
+
| { type: 'LOAD_POST'; payload: BlogPost }
|
|
68
|
+
| { type: 'RESET_EDITOR' }
|
|
69
|
+
| { type: 'MARK_CLEAN' }
|
|
70
|
+
| { type: 'MARK_DIRTY' }
|
|
71
|
+
| { type: 'UNDO' }
|
|
72
|
+
| { type: 'REDO' }
|
|
73
|
+
| { type: 'SAVE_HISTORY' };
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Editor Context Value
|
|
77
|
+
* The value provided by the EditorContext
|
|
78
|
+
*/
|
|
79
|
+
export interface EditorContextValue {
|
|
80
|
+
/** Current editor state */
|
|
81
|
+
state: EditorState;
|
|
82
|
+
|
|
83
|
+
/** Dispatch an action to modify state */
|
|
84
|
+
dispatch: (action: EditorAction) => void;
|
|
85
|
+
|
|
86
|
+
/** Enable dark mode for content area and wrappers */
|
|
87
|
+
darkMode: boolean;
|
|
88
|
+
|
|
89
|
+
/** Background colors for the editor */
|
|
90
|
+
backgroundColors?: {
|
|
91
|
+
/** Background color for light mode (REQUIRED) */
|
|
92
|
+
light: string;
|
|
93
|
+
/** Background color for dark mode (optional) */
|
|
94
|
+
dark?: string;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** Helper functions for common operations */
|
|
98
|
+
helpers: {
|
|
99
|
+
/** Add a new block (supports nested containers via containerId) */
|
|
100
|
+
addBlock: (type: string, index?: number, containerId?: string) => void;
|
|
101
|
+
|
|
102
|
+
/** Update a block's data */
|
|
103
|
+
updateBlock: (id: string, data: Partial<Block['data']>) => void;
|
|
104
|
+
|
|
105
|
+
/** Delete a block */
|
|
106
|
+
deleteBlock: (id: string) => void;
|
|
107
|
+
|
|
108
|
+
/** Duplicate a block */
|
|
109
|
+
duplicateBlock: (id: string) => void;
|
|
110
|
+
|
|
111
|
+
/** Move a block to a new position (supports nested containers via containerId) */
|
|
112
|
+
moveBlock: (id: string, newIndex: number, containerId?: string) => void;
|
|
113
|
+
|
|
114
|
+
/** Load a post into the editor */
|
|
115
|
+
loadPost: (post: BlogPost) => void;
|
|
116
|
+
|
|
117
|
+
/** Reset editor to initial state */
|
|
118
|
+
resetEditor: () => void;
|
|
119
|
+
|
|
120
|
+
/** Save current state (triggers save callback) */
|
|
121
|
+
save: () => Promise<void>;
|
|
122
|
+
|
|
123
|
+
/** Undo last action */
|
|
124
|
+
undo: () => void;
|
|
125
|
+
|
|
126
|
+
/** Redo last undone action */
|
|
127
|
+
redo: () => void;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** Whether undo is available */
|
|
131
|
+
canUndo: boolean;
|
|
132
|
+
|
|
133
|
+
/** Whether redo is available */
|
|
134
|
+
canRedo: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Initial Editor State
|
|
139
|
+
*/
|
|
140
|
+
export const initialEditorState: EditorState = {
|
|
141
|
+
blocks: [],
|
|
142
|
+
title: '',
|
|
143
|
+
slug: '',
|
|
144
|
+
seo: {
|
|
145
|
+
title: '',
|
|
146
|
+
description: '',
|
|
147
|
+
},
|
|
148
|
+
metadata: {
|
|
149
|
+
categories: [],
|
|
150
|
+
tags: [],
|
|
151
|
+
excerpt: '',
|
|
152
|
+
},
|
|
153
|
+
status: 'draft',
|
|
154
|
+
isDirty: false,
|
|
155
|
+
focusMode: false,
|
|
156
|
+
selectedBlockId: null,
|
|
157
|
+
draggedBlockId: null,
|
|
158
|
+
postId: null,
|
|
159
|
+
};
|
|
160
|
+
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Block Types
|
|
3
|
+
* Foundation for the Block-Based Architecture
|
|
4
|
+
* Multi-Tenant Plugin Architecture - Blocks are provided by client applications
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Base Block Interface
|
|
11
|
+
* Every block in the system extends this structure
|
|
12
|
+
*/
|
|
13
|
+
export interface Block {
|
|
14
|
+
/** Unique identifier for the block */
|
|
15
|
+
id: string;
|
|
16
|
+
|
|
17
|
+
/** Block type identifier (e.g., 'heading', 'paragraph', 'image', 'plantSpec') */
|
|
18
|
+
type: string;
|
|
19
|
+
|
|
20
|
+
/** Block-specific data (varies by type) */
|
|
21
|
+
data: Record<string, unknown>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Child blocks (for container blocks like Section, Columns)
|
|
25
|
+
* Can be an array of Block IDs (for flat storage) or Block objects (for nested structure)
|
|
26
|
+
*/
|
|
27
|
+
children?: string[] | Block[];
|
|
28
|
+
|
|
29
|
+
/** Optional metadata for editor state, styling, etc. */
|
|
30
|
+
meta?: {
|
|
31
|
+
/** Visual order in the editor */
|
|
32
|
+
order?: number;
|
|
33
|
+
/** Whether block is collapsed in editor */
|
|
34
|
+
collapsed?: boolean;
|
|
35
|
+
/** Custom styling overrides */
|
|
36
|
+
style?: Record<string, string>;
|
|
37
|
+
/** Editor-specific flags */
|
|
38
|
+
flags?: string[];
|
|
39
|
+
/** Column index (for column container blocks) */
|
|
40
|
+
columnIndex?: number;
|
|
41
|
+
/** Additional custom metadata */
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Block Edit Component Props
|
|
48
|
+
* Props passed to the Edit component in the dashboard editor
|
|
49
|
+
*/
|
|
50
|
+
export interface BlockEditProps {
|
|
51
|
+
/** The block being edited */
|
|
52
|
+
block: Block;
|
|
53
|
+
|
|
54
|
+
/** Update handler - call this to update the block's data */
|
|
55
|
+
onUpdate: (data: Partial<Block['data']>) => void;
|
|
56
|
+
|
|
57
|
+
/** Delete handler - call this to remove the block */
|
|
58
|
+
onDelete?: () => void;
|
|
59
|
+
|
|
60
|
+
/** Duplicate handler - call this to duplicate the block */
|
|
61
|
+
onDuplicate?: () => void;
|
|
62
|
+
|
|
63
|
+
/** Whether the block is currently selected */
|
|
64
|
+
isSelected?: boolean;
|
|
65
|
+
|
|
66
|
+
/** Whether the block is currently being dragged */
|
|
67
|
+
isDragging?: boolean;
|
|
68
|
+
|
|
69
|
+
/** Focus mode state */
|
|
70
|
+
focusMode?: boolean;
|
|
71
|
+
|
|
72
|
+
/** Child blocks (for container blocks like Section, Columns) */
|
|
73
|
+
childBlocks?: Block[];
|
|
74
|
+
|
|
75
|
+
/** Add a child block (for container blocks) */
|
|
76
|
+
onChildBlockAdd?: (type: string, index?: number, containerId?: string) => void;
|
|
77
|
+
|
|
78
|
+
/** Update a child block (for container blocks) */
|
|
79
|
+
onChildBlockUpdate?: (id: string, data: Partial<Block['data']>, containerId?: string) => void;
|
|
80
|
+
|
|
81
|
+
/** Delete a child block (for container blocks) */
|
|
82
|
+
onChildBlockDelete?: (id: string, containerId?: string) => void;
|
|
83
|
+
|
|
84
|
+
/** Move a child block (for container blocks) */
|
|
85
|
+
onChildBlockMove?: (id: string, newIndex: number, containerId?: string) => void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Block Preview Component Props
|
|
90
|
+
* Props passed to the Preview component for headless rendering
|
|
91
|
+
*/
|
|
92
|
+
export interface BlockPreviewProps {
|
|
93
|
+
/** The block to render */
|
|
94
|
+
block: Block;
|
|
95
|
+
|
|
96
|
+
/** Additional rendering context */
|
|
97
|
+
context?: {
|
|
98
|
+
/** Site ID */
|
|
99
|
+
siteId?: string;
|
|
100
|
+
/** Locale */
|
|
101
|
+
locale?: string;
|
|
102
|
+
/** Custom render props */
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** Child blocks (for container blocks like Section, Columns) */
|
|
107
|
+
childBlocks?: Block[];
|
|
108
|
+
|
|
109
|
+
/** Render a child block (for container blocks) */
|
|
110
|
+
renderChild?: (childBlock: Block) => React.ReactElement;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Strict Block Component Interface
|
|
115
|
+
* Every client-provided block MUST implement this interface
|
|
116
|
+
*/
|
|
117
|
+
export interface IBlockComponent {
|
|
118
|
+
/**
|
|
119
|
+
* Edit Component - Rendered in the dashboard editor
|
|
120
|
+
* Must use dashboard design system (earth-tone palette, typography)
|
|
121
|
+
*/
|
|
122
|
+
Edit: React.ComponentType<BlockEditProps>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Preview Component - Rendered in headless/frontend context
|
|
126
|
+
* Can use client's own design system
|
|
127
|
+
*/
|
|
128
|
+
Preview: React.ComponentType<BlockPreviewProps>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Icon Component - Shown in block palette
|
|
132
|
+
* Should be a simple icon (lucide-react recommended)
|
|
133
|
+
*/
|
|
134
|
+
Icon?: React.ComponentType<{ className?: string }>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Block Type Definition
|
|
139
|
+
* Complete definition of a block type for the registry
|
|
140
|
+
*/
|
|
141
|
+
export interface BlockTypeDefinition {
|
|
142
|
+
/** Unique type identifier */
|
|
143
|
+
type: string;
|
|
144
|
+
|
|
145
|
+
/** Human-readable name */
|
|
146
|
+
name: string;
|
|
147
|
+
|
|
148
|
+
/** Description of the block (shown in tooltips) */
|
|
149
|
+
description: string;
|
|
150
|
+
|
|
151
|
+
/** Icon component (React component) - Optional, falls back to block component's Icon */
|
|
152
|
+
icon?: React.ComponentType<{ className?: string }>;
|
|
153
|
+
|
|
154
|
+
/** Default data structure for this block type */
|
|
155
|
+
defaultData: Record<string, unknown>;
|
|
156
|
+
|
|
157
|
+
/** Validation schema (optional, for runtime validation) */
|
|
158
|
+
validate?: (data: Record<string, unknown>) => boolean;
|
|
159
|
+
|
|
160
|
+
/** Whether this block can contain nested blocks */
|
|
161
|
+
isContainer?: boolean;
|
|
162
|
+
|
|
163
|
+
/** Allowed child block types (if container) */
|
|
164
|
+
allowedChildren?: string[];
|
|
165
|
+
|
|
166
|
+
/** Category for grouping in block palette */
|
|
167
|
+
category?: 'text' | 'media' | 'layout' | 'interactive' | 'custom';
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Block Components - REQUIRED for client-provided blocks
|
|
171
|
+
* Edit and Preview components must be provided
|
|
172
|
+
*/
|
|
173
|
+
components: IBlockComponent;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Rich Text Formatting Configuration
|
|
178
|
+
* Optional configuration for rich text formatting in text blocks
|
|
179
|
+
*/
|
|
180
|
+
export interface RichTextFormattingConfig {
|
|
181
|
+
/** Whether bold formatting is available */
|
|
182
|
+
bold?: boolean;
|
|
183
|
+
/** Whether italic formatting is available */
|
|
184
|
+
italic?: boolean;
|
|
185
|
+
/** Whether underline formatting is available */
|
|
186
|
+
underline?: boolean;
|
|
187
|
+
/** Whether links are available */
|
|
188
|
+
links?: boolean;
|
|
189
|
+
/** Available colors (array of color values or Tailwind classes) */
|
|
190
|
+
colors?: string[];
|
|
191
|
+
/** Custom CSS classes for formatted text */
|
|
192
|
+
styles?: {
|
|
193
|
+
bold?: string;
|
|
194
|
+
italic?: string;
|
|
195
|
+
underline?: string;
|
|
196
|
+
link?: string;
|
|
197
|
+
/** Color classes mapped by color value */
|
|
198
|
+
colorClasses?: Record<string, string>;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Client Block Definition
|
|
204
|
+
* Simplified interface for client apps to provide blocks
|
|
205
|
+
*/
|
|
206
|
+
export interface ClientBlockDefinition {
|
|
207
|
+
/** Unique type identifier */
|
|
208
|
+
type: string;
|
|
209
|
+
|
|
210
|
+
/** Human-readable name */
|
|
211
|
+
name: string;
|
|
212
|
+
|
|
213
|
+
/** Description of the block */
|
|
214
|
+
description: string;
|
|
215
|
+
|
|
216
|
+
/** Icon component (optional) */
|
|
217
|
+
icon?: React.ComponentType<{ className?: string }>;
|
|
218
|
+
|
|
219
|
+
/** Default data structure */
|
|
220
|
+
defaultData: Record<string, unknown>;
|
|
221
|
+
|
|
222
|
+
/** Validation function (optional) */
|
|
223
|
+
validate?: (data: Record<string, unknown>) => boolean;
|
|
224
|
+
|
|
225
|
+
/** Whether this block can contain nested blocks */
|
|
226
|
+
isContainer?: boolean;
|
|
227
|
+
|
|
228
|
+
/** Allowed child block types (if container) */
|
|
229
|
+
allowedChildren?: string[];
|
|
230
|
+
|
|
231
|
+
/** Category for grouping */
|
|
232
|
+
category?: 'text' | 'media' | 'layout' | 'interactive' | 'custom';
|
|
233
|
+
|
|
234
|
+
/** Block components - REQUIRED */
|
|
235
|
+
components: IBlockComponent;
|
|
236
|
+
|
|
237
|
+
/** Rich text formatting configuration (optional) */
|
|
238
|
+
richTextFormatting?: RichTextFormattingConfig;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Block Registry Configuration
|
|
243
|
+
* Central registry of all available block types
|
|
244
|
+
*/
|
|
245
|
+
export interface BlockRegistry {
|
|
246
|
+
/** Map of block type to definition */
|
|
247
|
+
types: Map<string, BlockTypeDefinition>;
|
|
248
|
+
|
|
249
|
+
/** Register a new block type */
|
|
250
|
+
register(definition: BlockTypeDefinition): void;
|
|
251
|
+
|
|
252
|
+
/** Register multiple client blocks at once */
|
|
253
|
+
registerClientBlocks(definitions: ClientBlockDefinition[]): void;
|
|
254
|
+
|
|
255
|
+
/** Get block type definition */
|
|
256
|
+
get(type: string): BlockTypeDefinition | undefined;
|
|
257
|
+
|
|
258
|
+
/** Get all registered block types */
|
|
259
|
+
getAll(): BlockTypeDefinition[];
|
|
260
|
+
|
|
261
|
+
/** Get block types by category */
|
|
262
|
+
getByCategory(category: BlockTypeDefinition['category']): BlockTypeDefinition[];
|
|
263
|
+
|
|
264
|
+
/** Check if a block type is registered */
|
|
265
|
+
has(type: string): boolean;
|
|
266
|
+
|
|
267
|
+
/** Clear all registered blocks */
|
|
268
|
+
clear(): void;
|
|
269
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Central type exports
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from './block';
|
|
6
|
+
export * from './post';
|
|
7
|
+
|
|
8
|
+
// Re-export commonly used types for convenience
|
|
9
|
+
export type {
|
|
10
|
+
IBlockComponent,
|
|
11
|
+
BlockEditProps,
|
|
12
|
+
BlockPreviewProps,
|
|
13
|
+
ClientBlockDefinition,
|
|
14
|
+
} from './block';
|
|
15
|
+
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post Types
|
|
3
|
+
* Data structures for blog posts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Block } from './block';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Post Status
|
|
10
|
+
*/
|
|
11
|
+
export type PostStatus = 'draft' | 'published' | 'scheduled' | 'archived';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* SEO Metadata
|
|
15
|
+
*/
|
|
16
|
+
export interface SEOMetadata {
|
|
17
|
+
/** SEO title (can differ from post title) */
|
|
18
|
+
title?: string;
|
|
19
|
+
|
|
20
|
+
/** Meta description */
|
|
21
|
+
description?: string;
|
|
22
|
+
|
|
23
|
+
/** Open Graph image URL */
|
|
24
|
+
ogImage?: string;
|
|
25
|
+
|
|
26
|
+
/** Keywords/tags for SEO */
|
|
27
|
+
keywords?: string[];
|
|
28
|
+
|
|
29
|
+
/** Canonical URL */
|
|
30
|
+
canonicalUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Publication Data
|
|
35
|
+
*/
|
|
36
|
+
export interface PublicationData {
|
|
37
|
+
/** Publication status */
|
|
38
|
+
status: PostStatus;
|
|
39
|
+
|
|
40
|
+
/** Publication date (ISO string) */
|
|
41
|
+
date?: string;
|
|
42
|
+
|
|
43
|
+
/** Scheduled publication date (if status is 'scheduled') */
|
|
44
|
+
scheduledDate?: string;
|
|
45
|
+
|
|
46
|
+
/** Author ID */
|
|
47
|
+
authorId?: string;
|
|
48
|
+
|
|
49
|
+
/** Last modified date */
|
|
50
|
+
updatedAt?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Privacy Settings
|
|
55
|
+
*/
|
|
56
|
+
export interface PrivacySettings {
|
|
57
|
+
/** Whether the post is private (not publicly accessible) */
|
|
58
|
+
isPrivate?: boolean;
|
|
59
|
+
|
|
60
|
+
/** Password protection (if set, post requires password to view) */
|
|
61
|
+
password?: string;
|
|
62
|
+
|
|
63
|
+
/** List of user IDs who have access (from plugin-users) */
|
|
64
|
+
sharedWithUsers?: string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Post Metadata
|
|
69
|
+
*/
|
|
70
|
+
export interface PostMetadata {
|
|
71
|
+
/** Featured image */
|
|
72
|
+
featuredImage?: {
|
|
73
|
+
id?: string; // Image ID (preferred, for plugin-images system)
|
|
74
|
+
src?: string; // Image URL (legacy support, will be converted to id)
|
|
75
|
+
alt?: string;
|
|
76
|
+
brightness?: number; // 0-200, 100 = normal
|
|
77
|
+
blur?: number; // 0-20
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** Categories */
|
|
81
|
+
categories?: string[];
|
|
82
|
+
|
|
83
|
+
/** Tags */
|
|
84
|
+
tags?: string[];
|
|
85
|
+
|
|
86
|
+
/** Excerpt/summary */
|
|
87
|
+
excerpt?: string;
|
|
88
|
+
|
|
89
|
+
/** Language code */
|
|
90
|
+
lang?: string;
|
|
91
|
+
|
|
92
|
+
/** Privacy settings */
|
|
93
|
+
privacy?: PrivacySettings;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Complete Blog Post Structure
|
|
98
|
+
* This is the headless JSON structure stored in the database
|
|
99
|
+
*/
|
|
100
|
+
export interface BlogPost {
|
|
101
|
+
/** Unique post identifier */
|
|
102
|
+
id: string;
|
|
103
|
+
|
|
104
|
+
/** Post title */
|
|
105
|
+
title: string;
|
|
106
|
+
|
|
107
|
+
/** URL slug (unique, auto-generated from title) */
|
|
108
|
+
slug: string;
|
|
109
|
+
|
|
110
|
+
/** Array of content blocks */
|
|
111
|
+
blocks: Block[];
|
|
112
|
+
|
|
113
|
+
/** SEO metadata */
|
|
114
|
+
seo: SEOMetadata;
|
|
115
|
+
|
|
116
|
+
/** Publication data */
|
|
117
|
+
publication: PublicationData;
|
|
118
|
+
|
|
119
|
+
/** Additional metadata */
|
|
120
|
+
metadata: PostMetadata;
|
|
121
|
+
|
|
122
|
+
/** Creation timestamp */
|
|
123
|
+
createdAt: string;
|
|
124
|
+
|
|
125
|
+
/** Last update timestamp */
|
|
126
|
+
updatedAt: string;
|
|
127
|
+
|
|
128
|
+
/** Version number for revision tracking */
|
|
129
|
+
version?: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Post List Item (for list views)
|
|
134
|
+
* Lightweight version of BlogPost for performance
|
|
135
|
+
*/
|
|
136
|
+
export interface PostListItem {
|
|
137
|
+
id: string;
|
|
138
|
+
title: string;
|
|
139
|
+
slug: string;
|
|
140
|
+
status: PostStatus;
|
|
141
|
+
date?: string;
|
|
142
|
+
excerpt?: string;
|
|
143
|
+
featuredImage?: string;
|
|
144
|
+
authorId?: string;
|
|
145
|
+
updatedAt: string;
|
|
146
|
+
category?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Post Filter Options
|
|
151
|
+
*/
|
|
152
|
+
export interface PostFilterOptions {
|
|
153
|
+
status?: PostStatus | PostStatus[];
|
|
154
|
+
category?: string;
|
|
155
|
+
tag?: string;
|
|
156
|
+
authorId?: string;
|
|
157
|
+
search?: string;
|
|
158
|
+
dateFrom?: string;
|
|
159
|
+
dateTo?: string;
|
|
160
|
+
limit?: number;
|
|
161
|
+
skip?: number;
|
|
162
|
+
sortBy?: 'date' | 'title' | 'updatedAt';
|
|
163
|
+
sortOrder?: 'asc' | 'desc';
|
|
164
|
+
}
|
|
165
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Blog Plugin Client Utilities
|
|
2
|
+
|
|
3
|
+
Helper functions for fetching blog data in client applications (non-React).
|
|
4
|
+
|
|
5
|
+
## fetchBlogs
|
|
6
|
+
|
|
7
|
+
Fetch blog posts from the API (returns a Promise).
|
|
8
|
+
|
|
9
|
+
### Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { fetchBlogs } from '@jhits/plugin-blog';
|
|
13
|
+
|
|
14
|
+
async function loadBlogs() {
|
|
15
|
+
try {
|
|
16
|
+
const { blogs, total } = await fetchBlogs({
|
|
17
|
+
limit: 10,
|
|
18
|
+
skip: 0,
|
|
19
|
+
status: 'published',
|
|
20
|
+
admin: false,
|
|
21
|
+
apiBaseUrl: '/api/blogs',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
console.log(`Found ${total} posts`);
|
|
25
|
+
blogs.forEach(blog => {
|
|
26
|
+
console.log(blog.title);
|
|
27
|
+
});
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('Failed to fetch blogs:', error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Options
|
|
35
|
+
|
|
36
|
+
- `limit` (number, default: 10): Maximum number of posts to fetch
|
|
37
|
+
- `skip` (number, default: 0): Number of posts to skip (for pagination)
|
|
38
|
+
- `status` (string, optional): Filter by status ('published', 'draft', 'concept')
|
|
39
|
+
- `admin` (boolean, default: false): Whether to fetch all posts for admin (includes drafts)
|
|
40
|
+
- `apiBaseUrl` (string, default: '/api/blogs'): API base URL
|
|
41
|
+
|
|
42
|
+
### Returns
|
|
43
|
+
|
|
44
|
+
Promise resolving to:
|
|
45
|
+
- `blogs` (PostListItem[]): Array of blog posts
|
|
46
|
+
- `total` (number): Total number of posts available
|
|
47
|
+
|
|
48
|
+
## fetchBlog
|
|
49
|
+
|
|
50
|
+
Fetch a single blog post by slug (returns a Promise).
|
|
51
|
+
|
|
52
|
+
### Usage
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { fetchBlog } from '@jhits/plugin-blog';
|
|
56
|
+
|
|
57
|
+
async function loadBlogPost(slug: string) {
|
|
58
|
+
try {
|
|
59
|
+
const blog = await fetchBlog({ slug });
|
|
60
|
+
console.log(blog.title);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Failed to fetch blog:', error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Options
|
|
68
|
+
|
|
69
|
+
- `slug` (string, required): Blog post slug
|
|
70
|
+
- `apiBaseUrl` (string, default: '/api/blogs'): API base URL
|
|
71
|
+
|
|
72
|
+
### Returns
|
|
73
|
+
|
|
74
|
+
Promise resolving to a `BlogPost` object.
|
|
75
|
+
|