globalContext manifest type
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { createExtensionClass } from '@umbraco-cms/backoffice/extension-api';
|
||||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UmbController, UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
|
||||
/**
|
||||
* Initializes extension classes for a host element.
|
||||
* Extension class will be given one argument, the host element.
|
||||
*
|
||||
* @param host The host element to initialize extension classes for.
|
||||
* @param extensionTypes The extension types(strings) to initialize.
|
||||
*
|
||||
*/
|
||||
export class UmbClassExtensionsInitializer extends UmbController {
|
||||
#extensionMap = new Map();
|
||||
|
||||
constructor(host: UmbControllerHostElement, extensionTypes: Array<string>) {
|
||||
super(host);
|
||||
|
||||
this.observe(umbExtensionsRegistry.extensionsOfTypes(extensionTypes), (extensions) => {
|
||||
if (!extensions) return;
|
||||
|
||||
extensions.forEach((extension) => {
|
||||
if (this.#extensionMap.has(extension.alias)) return;
|
||||
|
||||
// Instantiate and provide extension JS class. For Context API the classes provide them selfs when the class instantiates.
|
||||
this.#extensionMap.set(extension.alias, createExtensionClass(extension, [this._host]));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
this.#extensionMap.forEach((extension) => {
|
||||
extension.destroy();
|
||||
});
|
||||
this.#extensionMap.clear();
|
||||
}
|
||||
}
|
||||
@@ -2,3 +2,4 @@ export * from './interfaces/index.js';
|
||||
export * from './models/index.js';
|
||||
export * from './registry.js';
|
||||
export * from './extension-class-initializer.js';
|
||||
export * from './class-extensions-initializer.js';
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import type { ManifestClass } from '@umbraco-cms/backoffice/extension-api';
|
||||
|
||||
export interface ManifestGlobalContext extends ManifestClass {
|
||||
type: 'globalContext';
|
||||
}
|
||||
@@ -2,16 +2,19 @@ import { UmbBackofficeNotificationContainerElement, UmbBackofficeModalContainerE
|
||||
import { manifests as debugManifests } from './debug/manifests.js';
|
||||
import { manifests as propertyActionManifests } from './property-actions/manifests.js';
|
||||
import { manifests as propertyEditorManifests } from './property-editors/manifests.js';
|
||||
import { manifests as tinyMcePluginManifests } from './property-editors/uis/tiny-mce/plugins/manifests.js';
|
||||
import { manifests as tinyMcePluginManifests } from './property-editors/uis/tiny-mce/plugins/manifests.js';
|
||||
import { manifests as workspaceManifests } from './workspace/manifests.js';
|
||||
import { manifests as modalManifests } from './modal/common/manifests.js';
|
||||
import { UmbStoreExtensionInitializer } from './store/index.js';
|
||||
|
||||
import { UmbNotificationContext, UMB_NOTIFICATION_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/notification';
|
||||
import { UmbModalManagerContext, UMB_MODAL_MANAGER_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/modal';
|
||||
import { UmbContextProviderController } from '@umbraco-cms/backoffice/context-api';
|
||||
import type { UmbEntryPointOnInit } from '@umbraco-cms/backoffice/extension-api';
|
||||
import { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import {
|
||||
ManifestTypes,
|
||||
UmbBackofficeManifestKind,
|
||||
UmbClassExtensionsInitializer,
|
||||
} from '@umbraco-cms/backoffice/extension-registry';
|
||||
|
||||
export * from './action/index.js';
|
||||
export * from './collection/index.js';
|
||||
@@ -46,7 +49,7 @@ const manifests: Array<ManifestTypes | UmbBackofficeManifestKind> = [
|
||||
];
|
||||
|
||||
export const onInit: UmbEntryPointOnInit = (host, extensionRegistry) => {
|
||||
new UmbStoreExtensionInitializer(host);
|
||||
new UmbClassExtensionsInitializer(host, ['globalContext', 'store', 'treeStore', 'itemStore']);
|
||||
|
||||
extensionRegistry.registerMany(manifests);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ export * from './entity-tree-store.js';
|
||||
export * from './file-system-tree.store.js';
|
||||
export * from './item-store.interface.js';
|
||||
export * from './store-base.js';
|
||||
export * from './store-extension-initializer.js';
|
||||
export * from './store.interface.js';
|
||||
export * from './store.js';
|
||||
export * from './tree-store.interface.js';
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { createExtensionClass } from '@umbraco-cms/backoffice/extension-api';
|
||||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbObserverController } from '@umbraco-cms/backoffice/observable-api';
|
||||
|
||||
export class UmbStoreExtensionInitializer {
|
||||
public host: UmbControllerHostElement;
|
||||
#storeMap = new Map();
|
||||
|
||||
constructor(host: UmbControllerHostElement) {
|
||||
this.host = host;
|
||||
|
||||
new UmbObserverController(
|
||||
this.host,
|
||||
umbExtensionsRegistry.extensionsOfTypes(['store', 'treeStore', 'itemStore']),
|
||||
(stores) => {
|
||||
if (!stores) return;
|
||||
|
||||
stores.forEach((store) => {
|
||||
if (this.#storeMap.has(store.alias)) return;
|
||||
|
||||
// Instantiate and provide stores. Stores are self providing when the class is instantiated.
|
||||
this.#storeMap.set(store.alias, createExtensionClass(store, [this.host]));
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user