mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-05 06:41:50 +09:00
Revert the accidental merge of #6125 so the implementation can continue in draft PR #6181.
27 lines
770 B
TypeScript
27 lines
770 B
TypeScript
import { atom } from "nanostores";
|
|
import { createPubsub } from "./create";
|
|
|
|
// Allow commands to declare their types
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
export interface CommandRegistry {}
|
|
|
|
// Generate namespaced command types from CommandRegistry
|
|
type NamespacedCommands = {
|
|
[K in keyof CommandRegistry as `command:${K & string}`]: CommandRegistry[K];
|
|
};
|
|
|
|
export interface PubsubMap extends NamespacedCommands {
|
|
command: {
|
|
source: string;
|
|
name: string;
|
|
[key: string]: unknown;
|
|
};
|
|
}
|
|
|
|
export const { publish, usePublish, useSubscribe, subscribe } =
|
|
createPubsub<PubsubMap>();
|
|
export type Publish = typeof publish;
|
|
export type UsePublish = typeof usePublish;
|
|
|
|
export const $publisher = atom<{ publish?: Publish }>({});
|