|
| 1 | +# CloudCannon File Browser |
| 2 | + |
| 3 | +A modern file browser and code editor built with React and Monaco Editor that integrates with the CloudCannon JavaScript API v1. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **File Browser**: Navigate through your site files with a tree-like structure |
| 8 | +- **Code Editor**: VSCode-like editing experience with syntax highlighting for multiple languages |
| 9 | +- **Real-time Sync**: Automatically syncs with CloudCannon's file system |
| 10 | +- **Auto-save**: Keyboard shortcuts (Ctrl/Cmd + S) for quick saving |
| 11 | +- **File Type Detection**: Automatic language detection based on file extensions |
| 12 | +- **Responsive Design**: Modern, clean interface that works across different screen sizes |
| 13 | + |
| 14 | +## Getting Started |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | + |
| 18 | +This application is designed to run within the CloudCannon editor environment. Make sure you have: |
| 19 | + |
| 20 | +- Access to CloudCannon editor |
| 21 | +- The CloudCannon JavaScript API available on the window object |
| 22 | + |
| 23 | +### Installation |
| 24 | + |
| 25 | +1. Navigate to the project directory: |
| 26 | + ```bash |
| 27 | + cd examples/file-browser |
| 28 | + ``` |
| 29 | + |
| 30 | +2. Install dependencies: |
| 31 | + ```bash |
| 32 | + npm install |
| 33 | + ``` |
| 34 | + |
| 35 | +3. Start the development server: |
| 36 | + ```bash |
| 37 | + npm run dev |
| 38 | + ``` |
| 39 | + |
| 40 | +4. Open your browser and navigate to `http://localhost:3000` |
| 41 | + |
| 42 | +### Building for Production |
| 43 | + |
| 44 | +```bash |
| 45 | +npm run build |
| 46 | +``` |
| 47 | + |
| 48 | +The built files will be in the `dist` directory. Create a site on CloudCannon using these files |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +### Within CloudCannon Editor |
| 53 | + |
| 54 | +1. Load this application within the CloudCannon editor iframe |
| 55 | +2. The app will automatically detect and connect to the CloudCannon API |
| 56 | +3. Browse files in the left sidebar |
| 57 | +4. Click on any file to open it in the editor |
| 58 | +5. Make changes and save with Ctrl/Cmd + S or using the Save button |
| 59 | + |
| 60 | +### API Integration |
| 61 | + |
| 62 | +The application uses the CloudCannon JavaScript API v1: |
| 63 | + |
| 64 | +```typescript |
| 65 | +// Access the API |
| 66 | +const api = window.CloudCannonAPI?.useVersion('v1'); |
| 67 | + |
| 68 | +// Get all files |
| 69 | +const files = await api.files(); |
| 70 | + |
| 71 | +// Work with individual files |
| 72 | +const file = api.file('path/to/file.md'); |
| 73 | +const content = await file.get(); |
| 74 | +await file.set(newContent); |
| 75 | +``` |
| 76 | + |
| 77 | +## Architecture |
| 78 | + |
| 79 | +### Components |
| 80 | + |
| 81 | +- **App.tsx**: Main application component that orchestrates the file browser and editor |
| 82 | +- **FileBrowser.tsx**: Tree-view file browser with folder expansion and file selection |
| 83 | +- **CodeEditor.tsx**: Monaco Editor wrapper with save functionality and language detection |
| 84 | +- **useCloudCannonAPI.ts**: Custom hook for managing CloudCannon API connection and state |
| 85 | + |
| 86 | +### File Structure |
| 87 | + |
| 88 | +``` |
| 89 | +src/ |
| 90 | +├── components/ |
| 91 | +│ ├── FileBrowser.tsx # File tree browser component |
| 92 | +│ └── CodeEditor.tsx # Monaco editor component |
| 93 | +├── hooks/ |
| 94 | +│ └── useCloudCannonAPI.ts # CloudCannon API integration hook |
| 95 | +├── types/ |
| 96 | +│ └── cloudcannon.ts # TypeScript definitions for CloudCannon API |
| 97 | +├── App.tsx # Main application component |
| 98 | +├── main.tsx # React entry point |
| 99 | +└── index.css # Global styles with Tailwind |
| 100 | +``` |
| 101 | + |
| 102 | +## Supported File Types |
| 103 | + |
| 104 | +The editor automatically detects and provides syntax highlighting for: |
| 105 | + |
| 106 | +- **Web**: HTML, CSS, SCSS, SASS, Less, JavaScript, TypeScript, JSX, TSX |
| 107 | +- **Data**: JSON, YAML, XML |
| 108 | +- **Markup**: Markdown |
| 109 | +- **Programming**: Python, Ruby, PHP, Java, C/C++, C#, Go, Rust |
| 110 | +- **Shell**: Bash, Shell scripts |
| 111 | +- **Database**: SQL |
| 112 | +- **Other**: Dockerfile, R, and more |
| 113 | + |
| 114 | +## Keyboard Shortcuts |
| 115 | + |
| 116 | +- **Ctrl/Cmd + S**: Save current file |
| 117 | +- **Standard Monaco shortcuts**: All Monaco Editor shortcuts are available |
| 118 | + |
| 119 | +## Error Handling |
| 120 | + |
| 121 | +The application includes comprehensive error handling for: |
| 122 | + |
| 123 | +- CloudCannon API connection issues |
| 124 | +- File loading errors |
| 125 | +- Save operation failures |
| 126 | +- Network connectivity problems |
| 127 | + |
| 128 | +## Development |
| 129 | + |
| 130 | +### Scripts |
| 131 | + |
| 132 | +- `npm run dev`: Start development server |
| 133 | +- `npm run build`: Build for production |
| 134 | +- `npm run preview`: Preview production build |
| 135 | +- `npm run lint`: Run ESLint |
| 136 | + |
| 137 | +### Technologies Used |
| 138 | + |
| 139 | +- **React 18**: UI framework |
| 140 | +- **TypeScript**: Type safety |
| 141 | +- **Monaco Editor**: Code editing (VSCode's editor) |
| 142 | +- **Tailwind CSS**: Styling |
| 143 | +- **Vite**: Build tool |
| 144 | +- **Lucide React**: Icons |
| 145 | + |
| 146 | +## Troubleshooting |
| 147 | + |
| 148 | +### API Not Found Error |
| 149 | + |
| 150 | +If you see "CloudCannonAPI not found", make sure: |
| 151 | + |
| 152 | +1. You're running the app within the CloudCannon editor environment |
| 153 | +2. The CloudCannonAPI is available on the window object |
| 154 | +3. The v1 API is supported in your CloudCannon version |
| 155 | + |
| 156 | +### File Loading Issues |
| 157 | + |
| 158 | +If files aren't loading: |
| 159 | + |
| 160 | +1. Check browser console for API errors |
| 161 | +2. Verify file permissions in CloudCannon |
| 162 | +3. Ensure the API has proper access to the file system |
| 163 | + |
| 164 | +### Build Issues |
| 165 | + |
| 166 | +If you encounter build issues: |
| 167 | + |
| 168 | +1. Clear node_modules and reinstall: `rm -rf node_modules && npm install` |
| 169 | +2. Clear Vite cache: `npm run dev -- --force` |
| 170 | +3. Check TypeScript errors: `npm run build` |
| 171 | + |
| 172 | +## License |
| 173 | + |
| 174 | +This project is part of the CloudCannon JavaScript API examples and follows the same license terms. |
0 commit comments