diff --git a/src/Umbraco.Web.UI.Client/src/core/controller/controller-host.mixin.ts b/src/Umbraco.Web.UI.Client/libs/controller/controller-host.mixin.ts similarity index 83% rename from src/Umbraco.Web.UI.Client/src/core/controller/controller-host.mixin.ts rename to src/Umbraco.Web.UI.Client/libs/controller/controller-host.mixin.ts index 0463d493d4..9f237a2b3f 100644 --- a/src/Umbraco.Web.UI.Client/src/core/controller/controller-host.mixin.ts +++ b/src/Umbraco.Web.UI.Client/libs/controller/controller-host.mixin.ts @@ -1,13 +1,13 @@ -import type { HTMLElementConstructor } from '../models'; +import type { HTMLElementConstructor } from '../../src/core/models'; import { UmbControllerInterface } from './controller.interface'; export declare class UmbControllerHostInterface extends HTMLElement { //#controllers:UmbController[]; //#attached:boolean; - hasController(controller:UmbControllerInterface): boolean; + hasController(controller: UmbControllerInterface): boolean; getControllers(filterMethod: (ctrl: UmbControllerInterface) => boolean): UmbControllerInterface[]; - addController(controller:UmbControllerInterface): void; - removeController(controller:UmbControllerInterface): void; + addController(controller: UmbControllerInterface): void; + removeController(controller: UmbControllerInterface): void; } /** @@ -19,7 +19,6 @@ export declare class UmbControllerHostInterface extends HTMLElement { */ export const UmbControllerHostMixin = (superClass: T) => { class UmbContextConsumerClass extends superClass { - #controllers: UmbControllerInterface[] = []; #attached = false; @@ -29,7 +28,7 @@ export const UmbControllerHostMixin = (superCl * @param {UmbControllerInterface} ctrl */ hasController(ctrl: UmbControllerInterface): boolean { - return (this.#controllers.indexOf(ctrl) !== -1); + return this.#controllers.indexOf(ctrl) !== -1; } /** @@ -45,18 +44,17 @@ export const UmbControllerHostMixin = (superCl * @param {UmbControllerInterface} ctrl */ addController(ctrl: UmbControllerInterface): void { - // Check if there is one already with same unique - if(ctrl.unique) { - this.#controllers.forEach(x => { - if(x.unique === ctrl.unique) { + if (ctrl.unique) { + this.#controllers.forEach((x) => { + if (x.unique === ctrl.unique) { this.removeController(x); } }); } this.#controllers.push(ctrl); - if(this.#attached) { + if (this.#attached) { ctrl.hostConnected(); } } @@ -68,9 +66,9 @@ export const UmbControllerHostMixin = (superCl */ removeController(ctrl: UmbControllerInterface): void { const index = this.#controllers.indexOf(ctrl); - if(index !== -1) { + if (index !== -1) { this.#controllers.splice(index, 1); - if(this.#attached) { + if (this.#attached) { ctrl.hostDisconnected(); } ctrl.destroy(); @@ -83,8 +81,8 @@ export const UmbControllerHostMixin = (superCl * @param {string} unique */ removeControllerByAlias(unique: string): void { - this.#controllers.forEach(x => { - if(x.unique === unique) { + this.#controllers.forEach((x) => { + if (x.unique === unique) { this.removeController(x); } }); diff --git a/src/Umbraco.Web.UI.Client/src/core/controller/controller.class.ts b/src/Umbraco.Web.UI.Client/libs/controller/controller.class.ts similarity index 100% rename from src/Umbraco.Web.UI.Client/src/core/controller/controller.class.ts rename to src/Umbraco.Web.UI.Client/libs/controller/controller.class.ts diff --git a/src/Umbraco.Web.UI.Client/src/core/controller/controller.interface.ts b/src/Umbraco.Web.UI.Client/libs/controller/controller.interface.ts similarity index 100% rename from src/Umbraco.Web.UI.Client/src/core/controller/controller.interface.ts rename to src/Umbraco.Web.UI.Client/libs/controller/controller.interface.ts diff --git a/src/Umbraco.Web.UI.Client/src/core/controller/controller.test.ts b/src/Umbraco.Web.UI.Client/libs/controller/controller.test.ts similarity index 88% rename from src/Umbraco.Web.UI.Client/src/core/controller/controller.test.ts rename to src/Umbraco.Web.UI.Client/libs/controller/controller.test.ts index 4da206b75e..b59c7bd9cd 100644 --- a/src/Umbraco.Web.UI.Client/src/core/controller/controller.test.ts +++ b/src/Umbraco.Web.UI.Client/libs/controller/controller.test.ts @@ -1,16 +1,14 @@ import { expect } from '@open-wc/testing'; import { customElement } from 'lit/decorators.js'; -import { UmbContextProviderController } from '../context-api/provide/context-provider.controller'; import { UmbControllerHostInterface, UmbControllerHostMixin } from './controller-host.mixin'; +import { UmbContextProviderController } from '@umbraco-cms/context-api'; class MyClass { prop = 'value from provider'; } @customElement('test-my-controller-host') -class MyHostElement extends UmbControllerHostMixin(HTMLElement) { - -} +export class MyHostElement extends UmbControllerHostMixin(HTMLElement) {} describe('UmbContextProvider', () => { type NewType = UmbControllerHostInterface; @@ -22,10 +20,8 @@ describe('UmbContextProvider', () => { hostElement = document.createElement('test-my-controller-host') as UmbControllerHostInterface; }); - describe('Destroyed controllers is gone from host', () => { it('has a host property', () => { - const ctrl = new UmbContextProviderController(hostElement, 'my-test-context', contextInstance); expect(hostElement.hasController(ctrl)).to.be.true; @@ -38,7 +34,6 @@ describe('UmbContextProvider', () => { describe('Unique controllers replace each other', () => { it('has a host property', () => { - const firstCtrl = new UmbContextProviderController(hostElement, 'my-test-context', contextInstance); const secondCtrl = new UmbContextProviderController(hostElement, 'my-test-context', contextInstance); @@ -46,5 +41,4 @@ describe('UmbContextProvider', () => { expect(hostElement.hasController(secondCtrl)).to.be.true; }); }); - }); diff --git a/src/Umbraco.Web.UI.Client/src/core/controller/index.ts b/src/Umbraco.Web.UI.Client/libs/controller/index.ts similarity index 100% rename from src/Umbraco.Web.UI.Client/src/core/controller/index.ts rename to src/Umbraco.Web.UI.Client/libs/controller/index.ts diff --git a/src/Umbraco.Web.UI.Client/libs/resources/resource.controller.ts b/src/Umbraco.Web.UI.Client/libs/resources/resource.controller.ts index de8c9b7812..7754e71fc1 100644 --- a/src/Umbraco.Web.UI.Client/libs/resources/resource.controller.ts +++ b/src/Umbraco.Web.UI.Client/libs/resources/resource.controller.ts @@ -1,7 +1,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { UmbController } from '../../src/core/controller/controller.class'; -import { UmbControllerHostInterface } from '../../src/core/controller/controller-host.mixin'; -import { UmbContextConsumerController } from '../../src/core/context-api/consume/context-consumer.controller'; import { UmbNotificationOptions, UmbNotificationService, @@ -9,6 +6,8 @@ import { UMB_NOTIFICATION_SERVICE_CONTEXT_TOKEN, } from '../../src/core/notification'; import { ApiError, CancelablePromise, ProblemDetails } from '@umbraco-cms/backend-api'; +import { UmbController, UmbControllerHostInterface } from '@umbraco-cms/controller'; +import { UmbContextConsumerController } from '@umbraco-cms/context-api'; export class UmbResourceController extends UmbController { #promise: Promise; diff --git a/src/Umbraco.Web.UI.Client/libs/resources/tryExecuteAndNotify.method.ts b/src/Umbraco.Web.UI.Client/libs/resources/tryExecuteAndNotify.method.ts index 2660a56345..456b30fbac 100644 --- a/src/Umbraco.Web.UI.Client/libs/resources/tryExecuteAndNotify.method.ts +++ b/src/Umbraco.Web.UI.Client/libs/resources/tryExecuteAndNotify.method.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { UmbControllerHostInterface } from '../../src/core/controller/controller-host.mixin'; +import { UmbNotificationOptions } from '../../src/core/notification'; import { UmbResourceController } from './resource.controller'; -import { UmbNotificationOptions } from 'src/core/notification'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; export function tryExecuteAndNotify( host: UmbControllerHostInterface, diff --git a/src/Umbraco.Web.UI.Client/src/core/observable-api/observer.controller.ts b/src/Umbraco.Web.UI.Client/src/core/observable-api/observer.controller.ts index f7f1cf5c4f..6598b7a358 100644 --- a/src/Umbraco.Web.UI.Client/src/core/observable-api/observer.controller.ts +++ b/src/Umbraco.Web.UI.Client/src/core/observable-api/observer.controller.ts @@ -1,17 +1,14 @@ import { Observable } from 'rxjs'; import { UmbObserver } from './observer'; -import type { UmbControllerInterface } from 'src/core/controller/controller.interface'; -import { UmbControllerHostInterface } from '@umbraco-cms/controller'; - +import { UmbControllerInterface, UmbControllerHostInterface } from '@umbraco-cms/controller'; export class UmbObserverController extends UmbObserver implements UmbControllerInterface { - _alias?: string; public get unique() { return this._alias; } - constructor(host:UmbControllerHostInterface, source: Observable, callback: (_value: T) => void, alias?: string) { + constructor(host: UmbControllerHostInterface, source: Observable, callback: (_value: T) => void, alias?: string) { super(source, callback); this._alias = alias; @@ -29,6 +26,4 @@ export class UmbObserverController extends UmbObserver implements UmbContr hostConnected() { return; } - - } diff --git a/src/Umbraco.Web.UI.Client/src/core/stores/store.ts b/src/Umbraco.Web.UI.Client/src/core/stores/store.ts index 3720a2f01a..d2c8b8f8c7 100644 --- a/src/Umbraco.Web.UI.Client/src/core/stores/store.ts +++ b/src/Umbraco.Web.UI.Client/src/core/stores/store.ts @@ -1,6 +1,6 @@ import type { Observable } from 'rxjs'; -import { UmbControllerHostInterface } from '../controller/controller-host.mixin'; import { UniqueBehaviorSubject } from '../observable-api/unique-behavior-subject'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; export interface UmbDataStoreIdentifiers { key?: string; diff --git a/src/Umbraco.Web.UI.Client/tsconfig.json b/src/Umbraco.Web.UI.Client/tsconfig.json index 3c47b835e2..8049716d82 100644 --- a/src/Umbraco.Web.UI.Client/tsconfig.json +++ b/src/Umbraco.Web.UI.Client/tsconfig.json @@ -23,7 +23,7 @@ "@umbraco-cms/models": ["src/core/models"], "@umbraco-cms/backend-api": ["libs/backend-api"], "@umbraco-cms/context-api": ["src/core/context-api"], - "@umbraco-cms/controller": ["src/core/controller"], + "@umbraco-cms/controller": ["libs/controller"], "@umbraco-cms/element": ["src/core/element"], "@umbraco-cms/extensions-api": ["src/core/extensions-api"], "@umbraco-cms/extensions-registry": ["src/core/extensions-registry"],