Official SDK for developing plugins for the TopLocs decentralized community platform
The TopLocs Plugin SDK provides a complete development environment for building, testing, and deploying plugins for the TopLocs platform. It includes hot module reloading, TypeScript support, and a visual development environment that simulates the TopLocs plugin system.
- π₯ Hot Module Reloading - Instant feedback during development
- π§© Module Federation - Production-ready plugin architecture
- π¦ TypeScript First - Full type safety and IntelliSense support
- π¨ Tailwind CSS - Pre-configured styling system
- πΌοΈ Visual Dev Environment - See your plugin in context
- π§ Zero Config - Works out of the box
npm install @toplocs/plugin-sdk
# or
pnpm add @toplocs/plugin-sdk
# or
yarn add @toplocs/plugin-sdk// dev.ts
import { createPluginDevelopmentEnvironment } from '@toplocs/plugin-sdk';
import pluginConfig from './plugin.config';
import TopicContent from './components/TopicContent.vue';
import TopicSidebar from './components/TopicSidebar.vue';
const app = createPluginDevelopmentEnvironment({
pluginConfig,
components: {
TopicContent,
TopicSidebar
}
});
app.mount('#app');// plugin.config.ts
import type { BasePluginConfig } from '@toplocs/plugin-sdk';
const config: BasePluginConfig = {
id: 'my-awesome-plugin',
name: 'My Awesome Plugin',
url: 'http://localhost:3006/assets/plugin.js',
version: '1.0.0',
description: 'Adds awesome features to TopLocs',
author: 'Your Name',
slots: [
{
entity: 'Topic',
page: 'Info',
slot: 'Content',
component: 'TopicContent'
},
{
entity: 'Topic',
page: 'Info',
slot: 'Sidebar',
component: 'TopicSidebar'
}
]
};
export default config;// vite.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import federation from '@originjs/vite-plugin-federation';
export default defineConfig({
plugins: [
vue(),
federation({
name: 'my-awesome-plugin',
filename: 'plugin.js',
exposes: {
'./TopicContent': './src/components/TopicContent.vue',
'./TopicSidebar': './src/components/TopicSidebar.vue'
},
shared: ['vue', 'vue-router']
})
]
});TopLocs plugins integrate into specific "slots" within the platform:
| Entity | Pages | Available Slots |
|---|---|---|
| Topic | Info, Settings | Content, Sidebar |
| Location | Info, Settings | Content, Sidebar |
Every plugin component receives standardized props:
interface PluginComponentProps {
parentId: string; // ID of the parent entity (topic/location)
query: LocationQuery; // Route query parameters
}<template>
<div class="plugin-content">
<h2>{{ title }}</h2>
<p>Viewing {{ entityType }} with ID: {{ parentId }}</p>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue';
const props = defineProps<{
parentId: string;
query: Record<string, any>;
}>();
const entityType = computed(() =>
props.parentId.startsWith('topic-') ? 'Topic' : 'Location'
);
const title = computed(() =>
`My Plugin - ${entityType.value}`
);
</script>npm run dev- Starts development server with HMR
- Visual environment at
http://localhost:5173 - Instant component updates
- Vue DevTools support
npm run build
npm run preview- Tests production build
- Module Federation enabled
- Simulates real plugin loading
The SDK provides a visual development environment with:
- Entity Selector: Switch between Topic/Location contexts
- Page Navigation: Test different page contexts (Info/Settings)
- Slot Visualization: See how your components fit
- Live Reload: Instant updates as you code
Creates a Vue application configured for plugin development.
function createPluginDevelopmentEnvironment(config: PluginDevConfig): App<Element>Parameters:
config.pluginConfig: Your plugin configurationconfig.components: Map of component names to Vue componentsconfig.importPaths: (Optional) Custom import paths
Returns: Configured Vue application instance
export interface BasePluginConfig {
id: string;
name: string;
url: string;
version?: string;
description?: string;
author?: string;
slots: PluginSlot[];
}
export interface PluginSlot {
entity: 'Topic' | 'Location';
page: 'Info' | 'Settings';
slot: 'Content' | 'Sidebar';
component: string;
}
export interface PluginDevConfig {
pluginConfig?: BasePluginConfig;
components?: Record<string, any>;
importPaths?: {
configPath?: string;
sidebarPath?: string;
contentPath?: string;
};
}PluginEnvironment: Main development environment componentDirectComponent: Direct component renderer (dev mode)PluginComponent: Federation component loader (preview mode)
-
Component Organization
src/ βββ components/ β βββ TopicContent.vue β βββ TopicSidebar.vue β βββ shared/ βββ plugin.config.ts βββ dev.ts -
State Management
- Use Vue 3 Composition API
- Leverage
provide/injectfor plugin-wide state - Keep components self-contained
-
Styling
- Use Tailwind classes for consistency
- Scope custom styles to avoid conflicts
- Follow TopLocs design system
-
Performance
- Lazy load heavy components
- Optimize bundle size
- Use Vue's async components
Module Federation Errors
# Clear cache and rebuild
rm -rf node_modules/.vite
npm run buildType Errors
# Ensure TypeScript is configured correctly
npm run type-checkHMR Not Working
- Check Vite config
- Ensure components are properly exported
- Verify dev server is running
We welcome contributions! Please see our Contributing Guide for details.
MIT Β© TopLocs Team
Made with β€οΈ by the TopLocs team