Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions js/app/packages/app/component/Soup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';
import { registerHotkey } from 'core/hotkey/hotkeys';
import {
type Component,
createEffect,
createMemo,
createRenderEffect,
createSignal,
Expand Down Expand Up @@ -220,6 +221,7 @@ export function Soup() {

const splitPanelContext = useSplitPanelOrThrow();
const {
handle,
splitHotkeyScope,
unifiedListContext: {
viewsDataStore: viewsData,
Expand All @@ -235,6 +237,11 @@ export function Soup() {
const [preview, setPreview] = previewState();
const selectedEntity = () => view().selectedEntity;

// Sync selected view to split metadata
createEffect(() => {
handle.updateMeta?.({ viewId: selectedView() });
});

const orchestrator = useGlobalBlockOrchestrator();

const entityQueryClient = useEntityQueryClient();
Expand Down
52 changes: 41 additions & 11 deletions js/app/packages/app/component/split-layout/componentRegistry.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
import { ChannelCompose } from '@block-channel/component/Compose';
import { LoadingBlock } from '@core/component/LoadingBlock';
import { DEV_MODE_ENV, LOCAL_ONLY } from '@core/constant/featureFlags';
import type { ViewId } from '@core/types/view';
import { type JSXElement, lazy } from 'solid-js';
import { EmailCompose } from '../../../block-email/component/Compose';
import { Soup } from '../Soup';

export type ComponentFactory = (params?: Record<string, any>) => JSXElement;

const REGISTRY = new Map<
string,
(params?: Record<string, any>) => JSXElement
>();
export type UnifiedListMeta = {
kind: 'unified-list';
viewId: ViewId;
};

export function registerComponent(name: string, factory: ComponentFactory) {
REGISTRY.set(name, factory);
export type ComponentMeta = UnifiedListMeta | { kind?: undefined };

export type ComponentMetaMap = {
'unified-list': UnifiedListMeta;
};

type ComponentRegistration = {
factory: ComponentFactory;
initialMeta?: ComponentMeta;
};

const REGISTRY = new Map<string, ComponentRegistration>();

export function registerComponent<T extends Omit<ComponentMeta, 'kind'>>(
name: string,
factory: ComponentFactory,
initialMeta?: T
) {
const metaWithKind = initialMeta ? { kind: name, ...initialMeta } : undefined;
REGISTRY.set(name, { factory, initialMeta: metaWithKind as ComponentMeta });
}

export function resolveComponent(name: string, params?: Record<string, any>) {
const factory = REGISTRY.get(name);
if (!factory) throw new Error(`Component '${name}' not registered`);
return () => factory(params);
export type ResolvedComponent = {
element: () => JSXElement;
initialMeta?: ComponentMeta;
};

export function resolveComponent(
name: string,
params?: Record<string, any>
): ResolvedComponent {
const registration = REGISTRY.get(name);
if (!registration) throw new Error(`Component '${name}' not registered`);
return {
element: () => registration.factory(params),
initialMeta: registration.initialMeta,
};
}

registerComponent('unified-list', () => <Soup />);
registerComponent('unified-list', () => <Soup />, { viewId: 'inbox' });
registerComponent('loading', () => <LoadingBlock />);
registerComponent('channel-compose', () => <ChannelCompose />);
registerComponent('email-compose', () => <EmailCompose />);
Expand Down
51 changes: 42 additions & 9 deletions js/app/packages/app/component/split-layout/layoutManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import {
createSignal,
type JSXElement,
} from 'solid-js';
import { createStore, produce, reconcile } from 'solid-js/store';
import { resolveComponent } from './componentRegistry';
import { createStore, produce, reconcile, type Store } from 'solid-js/store';
import {
type ComponentMeta,
type ComponentMetaMap,
resolveComponent,
} from './componentRegistry';
import { createHistory, type History } from './history';

const ENABLE_DEFAULT_ALWAYS_IN_HISTORY = true;
Expand Down Expand Up @@ -47,6 +51,8 @@ type ComponentMount = {
kind: 'component';
name: string;
element: ElementFn;
meta: Store<ComponentMeta>;
updateMeta: (data: Omit<ComponentMeta, 'kind'>) => void;
};

export type SplitMount = BlockMount | ComponentMount;
Expand Down Expand Up @@ -146,10 +152,13 @@ export type SplitManager = {
hasSplit: (type: BlockName | 'component', id: string) => boolean;

/** Get a potential split id by its content type and id */
getSplitByContent: (
type: BlockName | 'component',
id: string
) => SplitHandle | undefined;
getSplitByContent: {
<K extends keyof ComponentMetaMap>(
type: 'component',
id: K
): SplitHandle<ComponentMetaMap[K]> | undefined;
(type: BlockName | 'component', id: string): SplitHandle | undefined;
};

/** Get a reactive string that is the display name of the active split. */
tabTitle: () => string | undefined;
Expand All @@ -161,7 +170,7 @@ export type SplitManager = {
setResizeContext: (cts: ResizeZoneCtx) => void;
} & UrlCapabilities;

export type SplitHandle = {
export type SplitHandle<TMeta extends ComponentMeta = ComponentMeta> = {
unregisterContentChangeListener: (
cb: (payload: SplitEventPayload[SplitEvent.ContentChange]) => void
) => void;
Expand All @@ -186,6 +195,10 @@ export type SplitHandle = {
close: () => void;
reset: () => void;
id: SplitId;
/** Component metadata store (only available for component splits) */
meta: () => Store<TMeta> | undefined;
/** Update component metadata (only available for component splits) */
updateMeta: ((data: Omit<TMeta, 'kind'>) => void) | undefined;
} & UrlCapabilities;

function newSplitId(): SplitId {
Expand All @@ -199,8 +212,20 @@ function createPinnedMount(
content: SplitContent
): SplitMount {
if (content.type === 'component') {
const element = resolveComponent(content.id, content.params);
return { kind: 'component', name: content.id, element };
const resolved = resolveComponent(content.id, content.params);
const [meta, setMeta] = createStore<ComponentMeta>(
resolved.initialMeta ?? {}
);
const updateMeta = (data: Omit<ComponentMeta, 'kind'>) => {
setMeta({ kind: content.id, ...data } as ComponentMeta);
};
return {
kind: 'component',
name: content.id,
element: resolved.element,
meta,
updateMeta,
};
}

const handle = orchestrator.createBlockInstance(content.type, content.id);
Expand Down Expand Up @@ -535,6 +560,14 @@ export function createSplitLayout(
}
}
},
meta: () =>
currentSplit.mount.kind === 'component'
? currentSplit.mount.meta
: undefined,
updateMeta:
currentSplit.mount.kind === 'component'
? currentSplit.mount.updateMeta
: undefined,
};
};

Expand Down
8 changes: 8 additions & 0 deletions js/app/packages/app/component/split-layout/layoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ export function globalRemoveFromSplitHistory(
handle?.removeFromHistory(predicate);
}
}

/**
* Check if there's a unified-list split with the inbox view active.
*/
export function isInboxOpen(manager: SplitManager): boolean {
const split = manager.getSplitByContent('component', 'unified-list');
return split?.meta()?.viewId === 'inbox';
}