droplinked-editor-configs 1.8.9 → 1.9.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 CHANGED
@@ -1,149 +1,604 @@
1
1
  # Droplinked Designer
2
2
 
3
- A visual page builder based on React and Puck Editor for creating and managing configurable components.
3
+ A visual page builder library based on React and Puck Editor for creating and managing configurable e-commerce components. This library provides both an editor component for building pages and renderer components for displaying them.
4
4
 
5
5
  ---
6
6
 
7
- ## Project Structure
7
+ ## 📦 Installation
8
+
9
+ ```bash
10
+ npm install droplinked-editor-configs
11
+ ```
12
+
13
+ ## 🚀 Quick Start
14
+
15
+ ### As an Editor
16
+
17
+ ```tsx
18
+ import { Editor, AppStoreProvider, Data } from 'droplinked-editor-configs';
19
+ import 'droplinked-editor-configs/dist/index.css';
20
+
21
+ const initialData: Data = {
22
+ root: { props: {} },
23
+ content: []
24
+ };
25
+
26
+ function App() {
27
+ return (
28
+ <Editor
29
+ shopName="your-shop-name"
30
+ initialData={initialData}
31
+ isLive={false}
32
+ onPublish={(data) => console.log('Published:', data)}
33
+ onDraft={(data) => console.log('Draft saved:', data)}
34
+ />
35
+ );
36
+ }
37
+ ```
38
+
39
+ ### As a Renderer
40
+
41
+ ```tsx
42
+ import { PageHeader, PageFooter, InnerContent } from 'droplinked-editor-configs';
43
+ import { ShopProvider } from 'droplinked-editor-configs';
44
+
45
+ function MyShop() {
46
+ const headerData = { /* your header data */ };
47
+ const footerData = { /* your footer data */ };
48
+ const contentData = { /* your content data */ };
49
+
50
+ return (
51
+ <ShopProvider shopName="your-shop-name">
52
+ <PageHeader
53
+ data={headerData}
54
+ cartItemCount={5}
55
+ onCartClick={() => {}}
56
+ handleNavigate={(path) => {}}
57
+ />
58
+ <InnerContent
59
+ data={contentData}
60
+ handleNavigate={(path) => {}}
61
+ />
62
+ <PageFooter
63
+ data={footerData}
64
+ handleNavigate={(path) => {}}
65
+ />
66
+ </ShopProvider>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 🏗️ Architecture Overview
74
+
75
+ ### Core Components
76
+
77
+ #### `Editor`
78
+ The main editor component that provides the visual page builder interface. It integrates:
79
+ - **Puck Editor**: The visual drag-and-drop editor
80
+ - **Shop Data Fetching**: Automatically fetches shop configuration based on `shopName`
81
+ - **State Management**: Uses AppStore for global state management
82
+ - **React Query**: For server state management
83
+
84
+ **Props:**
85
+ - `shopName`: Name of the shop to load configuration for
86
+ - `initialData`: Initial page structure
87
+ - `isLive`: Whether the editor is in live/preview mode
88
+ - `isNewTheme`: Flag for new theme creation
89
+ - `onPublish`: Callback when user publishes changes
90
+ - `onDraft`: Callback when user saves draft
91
+ - `onUpdate`: Callback for updates
92
+ - `onChange`: Callback on any data change
93
+ - `themeName`: Name of the theme being edited
94
+ - `publishLoading`: Loading state for publish action
95
+ - `draftLoading`: Loading state for draft action
96
+ - `permissions`: User permissions object
97
+ - `overrides`: UI component overrides
98
+ - `iframe`: Iframe configuration for preview
99
+ - `token`: Authentication token
100
+
101
+ #### `PageHeader`
102
+ Renders the header component with navigation and cart functionality.
103
+
104
+ **Props:**
105
+ - `data`: Header component data structure
106
+ - `onCartClick`: Callback for cart icon click
107
+ - `cartItemCount`: Number of items in cart
108
+ - `handleNavigate`: Navigation handler function
109
+ - `profileDropdownWrapper`: Custom profile dropdown component
110
+
111
+ #### `PageFooter`
112
+ Renders the footer component with links and social media.
113
+
114
+ **Props:**
115
+ - `data`: Footer component data structure
116
+ - `handleNavigate`: Navigation handler function
117
+
118
+ #### `InnerContent`
119
+ Renders the main content area with all configured components.
120
+
121
+ **Props:**
122
+ - `data`: Content data structure
123
+ - `handleNavigate`: Navigation handler function
124
+
125
+ ---
126
+
127
+ ## 🧠 State Management
128
+
129
+ ### AppStore (Zustand)
130
+
131
+ The library uses Zustand for global state management with persistence.
132
+
133
+ **Structure:**
134
+ ```typescript
135
+ interface IAppStore {
136
+ states: {
137
+ cart: { [shopName: string]: ICart }; // Shopping cart state
138
+ user: { [shopName: string]: { token: string; user: IUser } } | null; // User authentication
139
+ shop: IShop; // Shop configuration
140
+ };
141
+ methods: {
142
+ updateState: (props: { state: string; value: any }) => void;
143
+ };
144
+ }
145
+ ```
146
+
147
+ **Usage:**
148
+ ```tsx
149
+ import useAppStore from 'lib/stores/app/appStore';
150
+
151
+ function MyComponent() {
152
+ const { states, methods } = useAppStore();
153
+
154
+ // Access cart
155
+ const cart = states.cart['my-shop'];
156
+
157
+ // Update state
158
+ methods.updateState({ state: 'cart', value: newCart });
159
+ }
160
+ ```
161
+
162
+ **AppStoreProvider:**
163
+ The `AppStoreProvider` wraps components and provides AppStore context via React Context API. This is necessary for the Editor component to access global state.
164
+
165
+ ```tsx
166
+ <AppStoreProvider appStoreData={appStoreData}>
167
+ <YourComponent />
168
+ </AppStoreProvider>
169
+ ```
170
+
171
+ ### ShopProvider
172
+
173
+ Handles shop data fetching and provides loading state.
174
+
175
+ ```tsx
176
+ <ShopProvider shopName="your-shop-name">
177
+ <YourComponents />
178
+ </ShopProvider>
179
+ ```
180
+
181
+ ---
182
+
183
+ ## 📁 Project Structure
8
184
 
9
185
  ```
10
186
  src/
11
- ├── configured-components/ # Define categories and components here
12
- └── [category]/ # Each folder is a category (e.g., design-layout)
13
- └── [component]/ # Each folder is a component
14
- ├── configs/ # Configs and interfaces
15
- └── ... # Component files
16
- ├── puck-editor/ # Puck editor core and wrapper
17
- ├── App.tsx # Main entry and configuration
18
- └── ...
187
+ ├── configured-components/ # Component library organized by category
188
+ ├── blog-posts/ # Blog components
189
+ ├── button/ # Button variants
190
+ ├── design-layout/ # Layout containers (grid, vertical, horizontal)
191
+ ├── hero-section/ # Hero section variants
192
+ ├── image-with-text/ # Image with text components
193
+ ├── layout/ # Header & Footer
194
+ │ ├── media/ # Image and video components
195
+ │ ├── multicolumn/ # Multi-column layouts
196
+ │ ├── products/ # Product grid and summary components
197
+ │ └── text/ # Text components (heading, body, caption, subtitle)
198
+
199
+ ├── components/ # Reusable UI components
200
+ │ ├── ui/ # Shadcn UI components
201
+ │ ├── legacy-components/ # Legacy components
202
+ │ ├── header/ # Header sub-components
203
+ │ ├── footer/ # Footer sub-components
204
+ │ ├── productGrid/ # Product grid components
205
+ │ └── blog-posts/ # Blog post components
206
+
207
+ ├── lib/
208
+ │ ├── stores/ # Zustand stores
209
+ │ │ ├── app/ # AppStore - global state
210
+ │ │ └── productQueryStore/ # Product query state
211
+ │ ├── models/ # TypeScript interfaces
212
+ │ └── utils/ # Utility functions
213
+
214
+ ├── apis/ # API services
215
+ │ ├── axiosConfig.ts # Axios configuration
216
+ │ ├── blogs/ # Blog API services
217
+ │ ├── product/ # Product API services
218
+ │ └── shop/ # Shop API services
219
+
220
+ ├── hooks/ # Custom React hooks
221
+ │ ├── useCustomNavigate.ts # Navigation hook
222
+ │ ├── useThemeInfo.ts # Theme information hook
223
+ │ └── shop/ # Shop-related hooks
224
+
225
+ ├── types/ # TypeScript type definitions
226
+ │ ├── editorProps.ts # Editor component props
227
+ │ └── renderersProps.ts # Renderer component props
228
+
229
+ ├── App.tsx # Demo/Example application
230
+ ├── Editor.tsx # Main editor component
231
+ ├── PageHeader.tsx # Header renderer
232
+ ├── PageFooter.tsx # Footer renderer
233
+ ├── InnerContent.tsx # Content renderer
234
+ ├── AppStoreProvider.tsx # AppStore context provider
235
+ ├── ShopProvider.tsx # Shop data provider
236
+ ├── NavigationContext.tsx # Navigation context
237
+ └── index.ts # Library entry point
19
238
  ```
20
239
 
21
240
  ---
22
241
 
23
- ## How to Add a New Component
242
+ ## 🔧 Component Configuration System
243
+
244
+ ### Component Categories
245
+
246
+ Components are organized into categories:
247
+ - **Design Layout**: Container components (Grid, Vertical, Horizontal)
248
+ - **Media**: Image and video components
249
+ - **Button**: Various button styles
250
+ - **Text**: Typography components
251
+ - **Layout**: Header and Footer
252
+ - **Hero Section**: Hero/banner components
253
+ - **Image with Text**: Combined image-text layouts
254
+ - **Products**: Product display components
255
+ - **Blog Posts**: Blog listing and post components
256
+ - **Multi Column**: Multi-column layouts
257
+
258
+ ### Configuration Files
259
+
260
+ Each component category has:
261
+ 1. **Component files** (`.tsx`): React component implementation
262
+ 2. **Config files** (`*Config.tsx`): Puck editor configuration
263
+ 3. **Interface files** (`interface.ts`): TypeScript type definitions
264
+ 4. **Category config** (`categoryConfig.ts`): Category metadata
265
+ 5. **Index file** (`index.tsx`): Exports for the category
266
+
267
+ ---
268
+
269
+ ## 🎨 Adding a New Component
24
270
 
25
- ### 1. Define the Props Interface
271
+ ### 1. Create Component Structure
26
272
 
27
- In the appropriate path (e.g., `src/configured-components/design-layout/[component]/configs/interface.ts`):
273
+ ```
274
+ src/configured-components/[category]/[component]/
275
+ ├── configs/
276
+ │ ├── interface.ts # TypeScript interface
277
+ │ └── [component]Config.tsx # Puck configuration
278
+ ├── [Component].tsx # Main component
279
+ └── [Component]VisualExample.tsx # Visual preview
280
+ ```
28
281
 
282
+ ### 2. Define the Props Interface
283
+
284
+ `configs/interface.ts`:
29
285
  ```typescript
30
286
  export interface MyComponentProps {
31
- foo: string;
32
- bar: number;
287
+ title: string;
288
+ description?: string;
289
+ backgroundColor?: string;
290
+ id?: string;
33
291
  }
34
292
  ```
35
293
 
36
- ### 2. Implement the React Component
37
-
38
- In the appropriate path (e.g., `src/configured-components/design-layout/[component]/MyComponent.tsx`):
294
+ ### 3. Implement the Component
39
295
 
296
+ `MyComponent.tsx`:
40
297
  ```tsx
41
- import { DropZone } from "../../../puck-editor";
42
298
  import { MyComponentProps } from "./configs/interface";
43
299
 
44
- const MyComponent: React.FC<MyComponentProps> = ({ foo, bar }) => (
45
- <div>{foo} - {bar}</div>
46
- );
300
+ const MyComponent: React.FC<MyComponentProps> = ({
301
+ title,
302
+ description,
303
+ backgroundColor
304
+ }) => {
305
+ return (
306
+ <div style={{ backgroundColor }}>
307
+ <h2>{title}</h2>
308
+ {description && <p>{description}</p>}
309
+ </div>
310
+ );
311
+ };
47
312
 
48
313
  export default MyComponent;
49
314
  ```
50
315
 
51
- ### 3. Define the Component Config for Puck
316
+ ### 4. Create Visual Example
52
317
 
53
- In `src/configured-components/design-layout/[component]/configs/[component]Config.tsx`:
318
+ `MyComponentVisualExample.tsx`:
319
+ ```tsx
320
+ const MyComponentVisualExample = () => (
321
+ <div className="preview-container">
322
+ <span>My Component Preview</span>
323
+ </div>
324
+ );
54
325
 
326
+ export default MyComponentVisualExample;
327
+ ```
328
+
329
+ ### 5. Define Puck Configuration
330
+
331
+ `configs/myComponentConfig.tsx`:
55
332
  ```tsx
333
+ import { Config } from "droplinked-editor-core";
56
334
  import MyComponent from "../MyComponent";
57
335
  import MyComponentVisualExample from "../MyComponentVisualExample";
58
- import { Config } from "../../../puck-editor";
59
336
 
60
337
  export const myComponentConfig: Config["components"][string] = {
61
338
  label: "My Component",
62
- labelIcon: <span>🌟</span>,
63
339
  visualExample: <MyComponentVisualExample />,
64
340
  fields: {
65
- foo: { type: "text", label: "Foo" },
66
- bar: { type: "number", label: "Bar" },
341
+ title: {
342
+ type: "text",
343
+ label: "Title"
344
+ },
345
+ description: {
346
+ type: "textarea",
347
+ label: "Description"
348
+ },
349
+ backgroundColor: {
350
+ type: "text",
351
+ label: "Background Color"
352
+ },
67
353
  },
68
354
  defaultProps: {
69
- foo: "Hello",
70
- bar: 1,
355
+ title: "Default Title",
356
+ description: "Default description",
357
+ backgroundColor: "#ffffff",
71
358
  },
72
359
  render: (props) => <MyComponent {...props} />,
73
360
  };
74
361
  ```
75
362
 
76
- ### 4. Add to Exports
77
-
78
- In `src/configured-components/design-layout/index.tsx`:
363
+ ### 6. Export from Category
79
364
 
365
+ `src/configured-components/[category]/index.tsx`:
80
366
  ```tsx
81
- import { myComponentConfig } from "./[component]/configs/[component]Config";
367
+ import { myComponentConfig } from "./my-component/configs/myComponentConfig";
82
368
 
83
- export const designLayoutComponents = {
84
- // ...existing code...
369
+ export const categoryComponents = {
370
+ ...existingComponents,
85
371
  myComponent: myComponentConfig,
86
372
  };
87
373
  ```
88
374
 
89
- ### 5. Add to Category (Optional)
375
+ ### 7. Add to Category Config
90
376
 
91
- In `src/configured-components/design-layout/categoryConfig.ts`:
377
+ `categoryConfig.ts`:
378
+ ```typescript
379
+ export const categoryConfig: Config["categories"] = {
380
+ myCategory: {
381
+ title: "My Category",
382
+ components: ["myComponent", /* other components */],
383
+ },
384
+ };
385
+ ```
92
386
 
387
+ ### 8. Register in Main Config
388
+
389
+ `src/index.ts`:
93
390
  ```typescript
94
- export const designLayoutCategory: Config["categories"] = {
95
- designLayout: {
96
- // ...existing code...
97
- components: [
98
- // ...existing code...
99
- "myComponent"
100
- ],
391
+ export const editorMainConfig: Config = {
392
+ categories: {
393
+ ...existingCategories,
394
+ ...myCategoryConfig,
101
395
  },
396
+ components: {
397
+ ...existingComponents,
398
+ ...myCategoryComponents,
399
+ }
102
400
  };
103
401
  ```
104
402
 
105
403
  ---
106
404
 
107
- ## Using Components in the Page Builder
405
+ ## 🔨 Building & Development
406
+
407
+ ### Development Mode
408
+
409
+ Run the development server with hot reload:
410
+
411
+ ```bash
412
+ npm install
413
+ npm run dev
414
+ ```
415
+
416
+ Access at: `http://localhost:5173`
108
417
 
109
- - After defining and adding your component, it will be available in the Puck Editor for selection and use.
110
- - You can drag & drop it onto the page and edit its properties.
418
+ ### Build for Production
419
+
420
+ Build the library for npm distribution:
421
+
422
+ ```bash
423
+ npm run build
424
+ ```
425
+
426
+ This creates:
427
+ - `dist/droplinked-editor.es.js` - ES module build
428
+ - `dist/droplinked-editor.umd.js` - UMD build
429
+ - `dist/index.d.ts` - TypeScript definitions
430
+ - `dist/style.css` - Bundled styles
111
431
 
112
432
  ---
113
433
 
114
- ## Important Notes
434
+ ### Publishing to npm
115
435
 
116
- - Each component must define its props in a type-safe manner.
117
- - Create a `visualExample` for each component so it can be displayed in the UI.
118
- - Use `DropZone` to create droppable areas.
119
- - The component name and its export key must be unique.
436
+ 1. Update version in `package.json`
437
+ 2. Build the library: `npm run build`
438
+ 3. Publish: `npm publish`
120
439
 
121
440
  ---
122
441
 
123
- ## Development & Running
442
+ ## 🧩 Advanced Usage
124
443
 
125
- 1. Install dependencies:
126
- ```bash
127
- npm install
444
+ ### Custom Navigation
445
+
446
+ Implement custom navigation handler:
447
+
448
+ ```tsx
449
+ const handleNavigate = (path: string) => {
450
+ // Your custom navigation logic
451
+ router.push(path);
452
+ };
453
+
454
+ <InnerContent
455
+ data={contentData}
456
+ handleNavigate={handleNavigate}
457
+ />
128
458
  ```
129
459
 
130
- 2. Run the project:
131
- ```bash
132
- npm run dev
460
+ ### Custom Profile Dropdown
461
+
462
+ Pass custom profile dropdown wrapper:
463
+
464
+ ```tsx
465
+ const CustomProfileDropdown = ({ children }) => (
466
+ <div className="custom-dropdown">
467
+ {children}
468
+ </div>
469
+ );
470
+
471
+ <PageHeader
472
+ data={headerData}
473
+ profileDropdownWrapper={CustomProfileDropdown}
474
+ // ... other props
475
+ />
133
476
  ```
134
477
 
135
- 3. View the project in your browser:
478
+ ---
479
+
480
+ ## 📚 API Reference
481
+
482
+ ### Exports
483
+
484
+ ```typescript
485
+ // Components
486
+ export { Editor } // Main editor component
487
+ export { PageHeader } // Header renderer
488
+ export { PageFooter } // Footer renderer
489
+ export { InnerContent } // Content renderer
490
+ export { AppStoreProvider } // AppStore context provider
491
+
492
+ // Configs
493
+ export { editorMainConfig } // Full editor configuration
494
+ export { innerContentConfig } // Content-only configuration
495
+
496
+ // Types
497
+ export type { Config, Data } // From droplinked-editor-core
498
+ export type { EditorProps } // Editor component props
499
+ export type { PageHeaderProps, PageFooterProps, innerContentProps }
500
+ ```
501
+
502
+ ### Data Structure
503
+
504
+ The `Data` type represents the page structure:
505
+
506
+ ```typescript
507
+ interface Data {
508
+ root: {
509
+ props: Record<string, any>;
510
+ };
511
+ content: Array<{
512
+ type: string; // Component type
513
+ props: {
514
+ id: string; // Unique component ID
515
+ [key: string]: any; // Component-specific props
516
+ };
517
+ }>;
518
+ }
519
+ ```
520
+
521
+ ---
522
+
523
+ ## 🛠️ Tech Stack
524
+
525
+ - **React 19** - UI library
526
+ - **TypeScript** - Type safety
527
+ - **Vite** - Build tool
528
+ - **Puck Editor** - Visual editor core
529
+ - **Zustand** - State management
530
+ - **React Query** - Server state management
531
+ - **Axios** - HTTP client
532
+ - **Tailwind CSS** - Styling
533
+ - **Shadcn UI** - UI components
534
+ - **Chakra UI** - Additional UI components
535
+ - **Framer Motion** - Animations
536
+
537
+ ---
538
+
539
+ ## 📖 Key Concepts
540
+
541
+ ### DropZone
542
+
543
+ Use `DropZone` from `droplinked-editor-core` to create droppable areas:
544
+
545
+ ```tsx
546
+ import { DropZone } from "droplinked-editor-core";
547
+
548
+ <div className="container">
549
+ <DropZone zone="content" />
550
+ </div>
551
+ ```
552
+
553
+ ### Component IDs
554
+
555
+ Each component instance requires a unique `id` prop for identification and updates.
556
+
557
+ ### Visual Examples
558
+
559
+ Always provide a `visualExample` component for the component picker UI.
560
+
561
+ ### Categories
562
+
563
+ Organize components into categories for better UX in the editor sidebar.
564
+
565
+ ---
566
+
567
+ ## 📝 Best Practices
568
+
569
+ 1. **Type Safety**: Always define TypeScript interfaces for component props
570
+ 2. **Default Props**: Provide sensible defaults in component config
571
+ 3. **Visual Examples**: Create clear, representative visual examples
572
+ 4. **Unique IDs**: Ensure component IDs are unique across the page
573
+ 5. **Responsive Design**: Make components responsive using Tailwind utilities
574
+ 6. **Accessibility**: Follow accessibility best practices
575
+ 7. **Performance**: Lazy load heavy components when possible
576
+ 8. **State Management**: Use AppStore for global state, local state for component-specific data
577
+
578
+ ---
579
+
580
+ ## 🤝 Contributing
581
+
582
+ When adding new components or features:
136
583
 
137
- Default address: [http://localhost:5173](http://localhost:5173)
584
+ 1. Follow the established folder structure
585
+ 2. Create proper TypeScript interfaces
586
+ 3. Add visual examples for editor UI
587
+ 4. Update category configurations
588
+ 5. Export from appropriate index files
589
+ 6. Test in both editor and renderer modes
590
+ 7. Document any new patterns or APIs
138
591
 
139
592
  ---
140
593
 
141
- ## Resources & Documentation
594
+ ## 📚 Resources & Documentation
142
595
 
143
596
  - [Puck Editor Documentation](https://puck-editor.com/docs)
144
597
  - [React Documentation](https://react.dev/)
145
598
  - [TypeScript Handbook](https://www.typescriptlang.org/docs/)
599
+ - [Zustand Documentation](https://github.com/pmndrs/zustand)
600
+ - [React Query Documentation](https://tanstack.com/query/latest)
601
+ - [Vite Documentation](https://vitejs.dev/)
146
602
 
147
603
  ---
148
604
 
149
- For further guidance, refer to the project documentation or code comments.
@@ -22,4 +22,5 @@ export interface IHomePageProduct {
22
22
  discountRuleset: boolean;
23
23
  gatedRuleset: boolean;
24
24
  nftRecording: any;
25
+ defaultImageIndex?: number;
25
26
  }