diff --git a/src/lib/core/MRPBlockLoader.ts b/src/lib/core/MRPBlockLoader.ts index a6a45f3..604bed5 100644 --- a/src/lib/core/MRPBlockLoader.ts +++ b/src/lib/core/MRPBlockLoader.ts @@ -1,8 +1,7 @@ import type { R } from "vitest/dist/reporters-P7C2ytIv.js" -import type { MRPConfig, ConfigBlocks } from "./MRPConfig" +import type { MRPConfig } from "./MRPConfig" import type { MRPState } from "./MRP" import { MRPData } from "./MRPData" -import { AppConfig } from "./kinds/app-config" type Components = { [key: string]: string | boolean @@ -100,7 +99,18 @@ export class BlockLoader extends MRPData { return this._config } - get components(): Record { + get sortedComponents(): NodeModule[] { + return this.config.event.getBlocksSorted().map( (name: string) => this._components[name]) + } + + get sortedKeys(): string[] { + return this.config.event.getBlocksSorted().map( (name: string) => this._components[name]) + // return Object.keys(this.config.event.blocks).sort((a, b) => this.config.event.blocks[a].order - this.config.event.blocks[b].order) + } + + get components(): NodeModule[] { return this._components + // console.log(this?.config?.event?.getBlocksSorted()) + // return this.config.event.getBlocksSorted().map( (name: string) => this._components[name]) } } \ No newline at end of file diff --git a/src/lib/core/kinds/app-config.ts b/src/lib/core/kinds/app-config.ts index 960a12e..7dfec44 100644 --- a/src/lib/core/kinds/app-config.ts +++ b/src/lib/core/kinds/app-config.ts @@ -81,11 +81,11 @@ const defaults = { order: 0 }, 'relay-feed': { - enabled: false, + enabled: true, order: 1 }, 'map': { - enabled: false, + enabled: true, order: 2 } } @@ -224,7 +224,34 @@ export class AppConfig extends NDKEvent { return this.blocks?.[key] } - getBlocksOrder(): string[] { + getBlocksSorted(): string[] { return Object.keys(this.blocks).sort((a, b) => this.getBlock(a).order - this.getBlock(b).order) } + + private shiftOrder(key: string, direction: 'up' | 'down'): void { + const block = this.config.blocks[key]; + let targetOrder = block.order + (direction === 'up' ? 1 : -1); + for (let key in this.config.blocks) { + if (this.config.blocks[key].order === targetOrder) { + this.config.blocks[key].order = block.order; + block.order = targetOrder; + break; + } + } + } + + shiftBlockUp(key: string): void { + const block = this.config.blocks[key]; + const maxOrder = Object.keys(this.config.blocks).length - 1; + if (block.order < maxOrder) { + this.shiftOrder(key, 'up'); + } + } + + shiftBlockDown(key: string): void { + if (this.config.blocks[key].order > 0) { + this.shiftOrder(key, 'down'); + } + } + } \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 20a7b21..7f08ce8 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -15,8 +15,10 @@ -{#if browser} - {#each Object.values( mrp?.loader?.components || {} ) as Component} + + +{#if browser && mrp?.loader?.sortedKeys?.length} + {#each mrp?.loader?.sortedComponents as Component} {#if Component} {/if}