frontend-plugin-api: support predicate overrides
Allow plugin and extension overrides to replace or remove existing if predicates. This makes conditional plugin and extension behavior overrideable through both plugin overrides and module-installed extension overrides. Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com> Made-with: Cursor
This commit is contained in:
@@ -549,13 +549,18 @@ export function createExtension<
|
||||
);
|
||||
}
|
||||
|
||||
let ifPredicate = options.if;
|
||||
if ('if' in overrideOptions) {
|
||||
ifPredicate = overrideOptions.if;
|
||||
}
|
||||
|
||||
return createExtension({
|
||||
kind: options.kind,
|
||||
name: options.name,
|
||||
attachTo: (overrideOptions.attachTo ??
|
||||
options.attachTo) as ExtensionDefinitionAttachTo,
|
||||
disabled: overrideOptions.disabled ?? options.disabled,
|
||||
if: overrideOptions.if ?? options.if,
|
||||
if: ifPredicate,
|
||||
inputs: bindInputs(
|
||||
{
|
||||
...(options.inputs ?? {}),
|
||||
|
||||
@@ -116,6 +116,11 @@ export interface OverridableFrontendPlugin<
|
||||
withOverrides(options: {
|
||||
extensions?: Array<ExtensionDefinition>;
|
||||
|
||||
/**
|
||||
* Overrides the shared condition that applies to all extensions in the plugin.
|
||||
*/
|
||||
if?: FilterPredicate;
|
||||
|
||||
/**
|
||||
* Overrides the display title of the plugin.
|
||||
*/
|
||||
@@ -329,6 +334,10 @@ export function createFrontendPlugin<
|
||||
return `Plugin{id=${pluginId}}`;
|
||||
},
|
||||
withOverrides(overrides) {
|
||||
let ifPredicate = options.if;
|
||||
if ('if' in overrides) {
|
||||
ifPredicate = overrides.if;
|
||||
}
|
||||
const overrideExtensions = overrides.extensions ?? [];
|
||||
const overriddenExtensionIds = new Set(
|
||||
overrideExtensions.map(
|
||||
@@ -344,6 +353,7 @@ export function createFrontendPlugin<
|
||||
return createFrontendPlugin({
|
||||
...options,
|
||||
pluginId,
|
||||
if: ifPredicate,
|
||||
title: overrides.title ?? options.title,
|
||||
icon: overrides.icon ?? options.icon,
|
||||
extensions: [...nonOverriddenExtensions, ...overrideExtensions],
|
||||
|
||||
Reference in New Issue
Block a user