فهرست منبع

feat(dashboard): Create basic slot registry types and utility functions

David Höck 10 ماه پیش
والد
کامیت
dd555be009

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 110 - 112
package-lock.json


+ 3 - 0
packages/dashboard/src/components/product-detail/general-information.tsx

@@ -0,0 +1,3 @@
+export default function GeneralInformation() {
+    return <p>Here comes the form for the basic information of a product</p>;
+}

+ 26 - 0
packages/dashboard/src/framework/defaults.ts

@@ -1,3 +1,4 @@
+import { registerDefaultSlots } from '@/framework/internal/layout-engine/slot-registry.js';
 import { navMenu } from '@/framework/internal/nav-menu/nav-menu.js';
 import { navMenu } from '@/framework/internal/nav-menu/nav-menu.js';
 import { BookOpen, Bot, Settings2, SquareTerminal } from 'lucide-react';
 import { BookOpen, Bot, Settings2, SquareTerminal } from 'lucide-react';
 
 
@@ -83,3 +84,28 @@ navMenu({
         // },
         // },
     ],
     ],
 });
 });
+
+registerDefaultSlots({
+    // pre-defined slot
+    product_detail: {
+        main: [
+            {
+                priority: 1,
+                component: () =>
+                    import('@/components/product-detail/general-information.js').then(m => m.default),
+                props: {},
+            },
+        ],
+    },
+    // generic slot
+    random_detail: {
+        side: [
+            {
+                priority: 1,
+                component: () =>
+                    import('@/components/product-detail/general-information.js').then(m => m.default),
+                props: {},
+            },
+        ],
+    },
+});

+ 89 - 0
packages/dashboard/src/framework/internal/layout-engine/slot-registry.ts

@@ -0,0 +1,89 @@
+import { ComponentType } from 'react';
+
+export type PredefinedSlotName = 'product_detail' | 'order_detail' | 'seller_detail';
+
+export type SlotIdMap = {
+    product_detail: 'main' | 'side';
+    order_detail: 'main' | 'side';
+    seller_detail: 'main' | 'side';
+};
+
+export type SlotId<T extends PredefinedSlotName> = SlotIdMap[T];
+
+export type SlotRegistry = {
+    [SlotName in PredefinedSlotName]: {
+        [ID in SlotId<SlotName>]?: Array<{
+            priority: number;
+            component: () => Promise<ComponentType<any>>;
+            props: Record<string, any>;
+        }>;
+    };
+} & {
+    [customSlot: string]: {
+        [customId: string]: Array<{
+            priority: number;
+            component: () => Promise<ComponentType<any>>;
+            props: Record<string, any>;
+        }>;
+    };
+};
+
+let globalSlotRegistry: SlotRegistry = {} as SlotRegistry;
+
+export function registerDefaultSlots(registry: Partial<SlotRegistry>) {
+    globalSlotRegistry = registry as SlotRegistry;
+}
+
+export function getSlotRegistry(): SlotRegistry {
+    return globalSlotRegistry;
+}
+
+export function registerSlot<T extends PredefinedSlotName>(
+    slotName: T,
+    slotId: SlotId<T>,
+    priority: number,
+    component: () => Promise<ComponentType<any>>,
+    props: Record<string, any>,
+): void;
+export function registerSlot(
+    slotName: string,
+    slotId: string,
+    priority: number,
+    component: () => Promise<ComponentType<any>>,
+    props: Record<string, any>,
+): void;
+export function registerSlot(
+    slotName: string,
+    slotId: string,
+    priority: number,
+    component: () => Promise<ComponentType<any>>,
+    props: Record<string, any> = {},
+) {
+    if (!globalSlotRegistry[slotName]) {
+        globalSlotRegistry[slotName] = {};
+    }
+    if (!globalSlotRegistry[slotName][slotId]) {
+        globalSlotRegistry[slotName][slotId] = [];
+    }
+    globalSlotRegistry[slotName][slotId].push({ priority, component, props });
+}
+
+export function unregisterSlot<T extends PredefinedSlotName>(slotName: T, slotId: SlotId<T>): void;
+export function unregisterSlot(slotName: string, slotId: string): void;
+export function unregisterSlot(slotName: string, slotId: string) {
+    if (globalSlotRegistry[slotName]) {
+        delete globalSlotRegistry[slotName][slotId];
+    }
+}
+
+export function getSlotComponent<T extends PredefinedSlotName>(
+    slotName: T,
+    slotId: SlotId<T>,
+): () => Promise<ComponentType<any>> | undefined;
+export function getSlotComponent(
+    slotName: string,
+    slotId: string,
+): () => Promise<ComponentType<any>> | undefined;
+export function getSlotComponent(slotName: string, slotId: string) {
+    return globalSlotRegistry[slotName]?.[slotId]?.[0]?.component;
+}

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است