()
| 23 | } |
| 24 | |
| 25 | export function createSlots() { |
| 26 | const empty: SlotView = () => null |
| 27 | const [view, setView] = createSignal<SlotView>(empty) |
| 28 | const Slot: SlotView = (props) => view()(props) |
| 29 | |
| 30 | return { |
| 31 | Slot, |
| 32 | setup(api: HostPluginApi): HostSlots { |
| 33 | const registry = createSolidSlotRegistry<RuntimeSlotMap, TuiSlotContext>( |
| 34 | api.renderer, |
| 35 | { theme: api.theme }, |
| 36 | { |
| 37 | onPluginError(event) { |
| 38 | console.error("[tui.slot] plugin error", { |
| 39 | plugin: event.pluginId, |
| 40 | slot: event.slot, |
| 41 | phase: event.phase, |
| 42 | source: event.source, |
| 43 | message: event.error.message, |
| 44 | }) |
| 45 | }, |
| 46 | }, |
| 47 | ) |
| 48 | const slot = createSlot<RuntimeSlotMap, TuiSlotContext>(registry) |
| 49 | setView(() => (props: TuiSlotProps<string>) => slot(props)) |
| 50 | |
| 51 | return { |
| 52 | register(plugin: HostSlotPlugin) { |
| 53 | if (!isHostSlotPlugin(plugin)) return () => {} |
| 54 | return registry.register(plugin) |
| 55 | }, |
| 56 | dispose() { |
| 57 | setView(() => empty) |
| 58 | }, |
| 59 | } |
| 60 | }, |
| 61 | clear() { |
| 62 | setView(() => empty) |
| 63 | }, |
| 64 | } |
| 65 | } |
no outgoing calls
no test coverage detected