extensionRegistrationsSortedByTypeAndWeight
This commit is contained in:
@@ -11,6 +11,7 @@ import { loadExtension } from '../load-extension.function';
|
||||
import { hasInitExport } from '../has-init-export.function';
|
||||
import type { UmbControllerHostInterface } from '@umbraco-cms/controller';
|
||||
import { UmbContextToken } from '@umbraco-cms/context-api';
|
||||
import { createObservablePart } from '@umbraco-cms/observable-api';
|
||||
|
||||
export class UmbExtensionRegistry {
|
||||
// TODO: Use UniqueBehaviorSubject, as we don't want someone to edit data of extensions.
|
||||
@@ -147,27 +148,6 @@ export class UmbExtensionRegistry {
|
||||
//
|
||||
// TODO: DisctinctUntilChanged by using aliases?
|
||||
}
|
||||
|
||||
// TODO: consider ust having the a.type.localeCompare(b.type); in the extension view, to then be able to use other existing observables?
|
||||
/**
|
||||
* Gets all the extensions registrations, but does not merge with kinds.
|
||||
* @returns
|
||||
*/
|
||||
extensionRegistrationsSortedByTypeAndWeight<ExtensionType = ManifestBase>(): Observable<Array<ExtensionType>> {
|
||||
return this.extensions.pipe(
|
||||
map((exts) =>
|
||||
exts.sort((a, b) => {
|
||||
// If type is the same, sort by weight
|
||||
if (a.type === b.type) {
|
||||
return (b.weight || 0) - (a.weight || 0);
|
||||
}
|
||||
|
||||
// Otherwise sort by type
|
||||
return a.type.localeCompare(b.type);
|
||||
})
|
||||
)
|
||||
) as Observable<Array<ExtensionType>>;
|
||||
}
|
||||
}
|
||||
|
||||
export const UMB_EXTENSION_REGISTRY_TOKEN = new UmbContextToken<UmbExtensionRegistry>('UmbExtensionRegistry');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { html } from 'lit';
|
||||
import { customElement, state } from 'lit/decorators.js';
|
||||
import { map } from 'rxjs';
|
||||
import { UMB_CONFIRM_MODAL_TOKEN } from '../../../shared/modals/confirm';
|
||||
import { isManifestElementNameType, umbExtensionsRegistry } from '@umbraco-cms/extensions-api';
|
||||
import type { ManifestBase } from '@umbraco-cms/models';
|
||||
@@ -23,9 +24,23 @@ export class UmbExtensionRootWorkspaceElement extends UmbLitElement {
|
||||
}
|
||||
|
||||
private _observeExtensions() {
|
||||
this.observe(umbExtensionsRegistry.extensionRegistrationsSortedByTypeAndWeight(), (extensions) => {
|
||||
this._extensions = extensions || undefined;
|
||||
});
|
||||
this.observe(
|
||||
umbExtensionsRegistry.extensions.pipe(
|
||||
map((exts) =>
|
||||
exts.sort((a, b) => {
|
||||
// If type is the same, sort by weight
|
||||
if (a.type === b.type) {
|
||||
return (b.weight || 0) - (a.weight || 0);
|
||||
}
|
||||
// Otherwise sort by type
|
||||
return a.type.localeCompare(b.type);
|
||||
})
|
||||
)
|
||||
),
|
||||
(extensions) => {
|
||||
this._extensions = extensions || undefined;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async #removeExtension(extension: ManifestBase) {
|
||||
|
||||
Reference in New Issue
Block a user