(runtime: RuntimeState, plugin: PluginEntry, scope: PluginScope, base: string)
| 570 | } |
| 571 | |
| 572 | function pluginApi(runtime: RuntimeState, plugin: PluginEntry, scope: PluginScope, base: string): TuiPluginApi { |
| 573 | const api = runtime.api |
| 574 | const host = runtime.slots |
| 575 | const load = plugin.load |
| 576 | |
| 577 | const route: TuiPluginApi["route"] = { |
| 578 | register(list) { |
| 579 | return scope.track(api.route.register(list)) |
| 580 | }, |
| 581 | navigate(name, params) { |
| 582 | api.route.navigate(name, params) |
| 583 | }, |
| 584 | get current() { |
| 585 | return api.route.current |
| 586 | }, |
| 587 | } |
| 588 | |
| 589 | const theme: TuiPluginApi["theme"] = Object.assign(Object.create(api.theme), { |
| 590 | install: createThemeInstaller(load.origin, load.plugin_root, load.spec, plugin), |
| 591 | }) |
| 592 | |
| 593 | const event: TuiPluginApi["event"] = { |
| 594 | on(type, handler) { |
| 595 | return scope.track(api.event.on(type, handler)) |
| 596 | }, |
| 597 | } |
| 598 | |
| 599 | const keymap = createScopedKeymap(api.keymap, scope) |
| 600 | |
| 601 | let count = 0 |
| 602 | |
| 603 | const slots: TuiPluginApi["slots"] = { |
| 604 | register(plugin: TuiSlotPlugin) { |
| 605 | const id = count ? `${base}:${count}` : base |
| 606 | count += 1 |
| 607 | scope.track(host.register({ ...plugin, id })) |
| 608 | return id |
| 609 | }, |
| 610 | } |
| 611 | |
| 612 | return { |
| 613 | app: api.app, |
| 614 | attention: createScopedAttention(api.attention, scope, load.plugin_root), |
| 615 | // Keep deprecated `api.command` working for v1 plugins; remove in v2. |
| 616 | command: createCommandShim(keymap, api.ui.dialog, api.tuiConfig.keybinds), |
| 617 | keys: api.keys, |
| 618 | keymap, |
| 619 | mode: createScopedMode(api.mode, scope), |
| 620 | route, |
| 621 | ui: api.ui, |
| 622 | tuiConfig: api.tuiConfig, |
| 623 | kv: api.kv, |
| 624 | state: api.state, |
| 625 | theme, |
| 626 | get client() { |
| 627 | return api.client |
| 628 | }, |
| 629 | event, |
no test coverage detected