working with router-slot fix

This commit is contained in:
Niels Lyngsø
2023-05-16 22:09:26 +02:00
parent 418bb2285f
commit d91959bcca
8 changed files with 1201 additions and 16058 deletions

View File

@@ -48,7 +48,9 @@ export const UmbControllerHostMixin = <T extends HTMLElementConstructor>(superCl
this.#controllers.push(ctrl); this.#controllers.push(ctrl);
if (this.#attached) { if (this.#attached) {
ctrl.hostConnected(); // If a controller is created on a already attached element, then it will be added directly. This might not be optimal. As the controller it self has not finished its constructor method jet. therefor i postpone the call:
Promise.resolve().then(() => ctrl.hostConnected());
//ctrl.hostConnected();
} }
} }

View File

@@ -13,7 +13,7 @@ import { UmbModalToken } from './token/modal-token';
import { UmbId } from '@umbraco-cms/backoffice/id'; import { UmbId } from '@umbraco-cms/backoffice/id';
import { createExtensionElement, umbExtensionsRegistry } from '@umbraco-cms/backoffice/extensions-api'; import { createExtensionElement, umbExtensionsRegistry } from '@umbraco-cms/backoffice/extensions-api';
import { UmbObserverController } from '@umbraco-cms/backoffice/observable-api'; import { UmbObserverController } from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller'; import { UmbController, UmbControllerHostElement } from '@umbraco-cms/backoffice/controller';
import type { ManifestModal } from '@umbraco-cms/backoffice/extensions-registry'; import type { ManifestModal } from '@umbraco-cms/backoffice/extensions-registry';
/** /**
@@ -40,12 +40,13 @@ type OptionalSubmitArgumentIfUndefined<T> = T extends undefined
submit: (arg: T) => void; submit: (arg: T) => void;
}; };
//TODO consider splitting this into two separate handlers // TODO: consider splitting this into two separate handlers
export class UmbModalHandlerClass<ModalData extends object = object, ModalResult = unknown> { // TODO: Rename to become a controller.
export class UmbModalHandlerClass<ModalData extends object = object, ModalResult = unknown> extends UmbController {
private _submitPromise: Promise<ModalResult>; private _submitPromise: Promise<ModalResult>;
private _submitResolver?: (value: ModalResult) => void; private _submitResolver?: (value: ModalResult) => void;
private _submitRejecter?: () => void; private _submitRejecter?: () => void;
#host: UmbControllerHostElement; private _parentRouter: IRouterSlot | null;
public modalElement: UUIModalDialogElement | UUIModalSidebarElement; public modalElement: UUIModalDialogElement | UUIModalSidebarElement;
#modalRouterElement: UmbRouterSlotElement = new UmbRouterSlotElement(); #modalRouterElement: UmbRouterSlotElement = new UmbRouterSlotElement();
@@ -57,6 +58,8 @@ export class UmbModalHandlerClass<ModalData extends object = object, ModalResult
public type: UmbModalType = 'dialog'; public type: UmbModalType = 'dialog';
public size: UUIModalSidebarSize = 'small'; public size: UUIModalSidebarSize = 'small';
private modalAlias: string; //TEMP... TODO: Remove this.
constructor( constructor(
host: UmbControllerHostElement, host: UmbControllerHostElement,
router: IRouterSlot | null, router: IRouterSlot | null,
@@ -64,8 +67,10 @@ export class UmbModalHandlerClass<ModalData extends object = object, ModalResult
data?: ModalData, data?: ModalData,
config?: UmbModalConfig config?: UmbModalConfig
) { ) {
this.#host = host; super(host);
this._parentRouter = router;
this.key = config?.key || UmbId.new(); this.key = config?.key || UmbId.new();
this.modalAlias = modalAlias.toString();
if (modalAlias instanceof UmbModalToken) { if (modalAlias instanceof UmbModalToken) {
this.type = modalAlias.getDefaultConfig()?.type || this.type; this.type = modalAlias.getDefaultConfig()?.type || this.type;
@@ -82,13 +87,25 @@ export class UmbModalHandlerClass<ModalData extends object = object, ModalResult
}); });
this.modalElement = this.#createContainerElement(); this.modalElement = this.#createContainerElement();
this.modalElement.appendChild(this.#modalRouterElement); /**
*
* Maybe we could just get a Modal Router Slot. But it needs to have the ability to actually inject via slot. so the modal inner element can be within.
*
*/
if (router) { if (router) {
this.#modalRouterElement.parent = router; this.#modalRouterElement.parent = router;
} }
this.modalElement.appendChild(this.#modalRouterElement);
this.#observeModal(modalAlias.toString(), data); this.#observeModal(modalAlias.toString(), data);
} }
public hostConnected() {
// Not much to do now..?
}
public hostDisconnected() {
// Not much to do now..?
}
#createContainerElement() { #createContainerElement() {
return this.type === 'sidebar' ? this.#createSidebarElement() : this.#createDialogElement(); return this.type === 'sidebar' ? this.#createSidebarElement() : this.#createDialogElement();
} }
@@ -139,24 +156,33 @@ export class UmbModalHandlerClass<ModalData extends object = object, ModalResult
Now when the element is an observable it makes it more complex because this host needs to subscribe to updates to the element, instead of just having a reference to it. Now when the element is an observable it makes it more complex because this host needs to subscribe to updates to the element, instead of just having a reference to it.
If we find a better generic solution to communicate between the modal and the implementor, then we can remove the element as part of the modalHandler. */ If we find a better generic solution to communicate between the modal and the implementor, then we can remove the element as part of the modalHandler. */
#observeModal(modalAlias: string, data?: ModalData) { #observeModal(modalAlias: string, data?: ModalData) {
new UmbObserverController( if (this.host) {
this.#host, new UmbObserverController(
umbExtensionsRegistry.getByTypeAndAlias('modal', modalAlias), this.host,
async (manifest) => { umbExtensionsRegistry.getByTypeAndAlias('modal', modalAlias),
if (manifest) { async (manifest) => {
const innerElement = await this.#createInnerElement(manifest, data); if (manifest) {
if (innerElement) { const innerElement = await this.#createInnerElement(manifest, data);
this.#appendInnerElement(innerElement); if (innerElement) {
return; this.#appendInnerElement(innerElement);
return;
}
} }
this.#removeInnerElement();
} }
this.#removeInnerElement(); );
} }
);
} }
#appendInnerElement(element: HTMLElement) { #appendInnerElement(element: HTMLElement) {
this.#modalRouterElement.appendChild(element); this.#modalRouterElement.appendChild(element);
/*this.#modalRouterElement.routes = [
{
path: '',
component: element,
},
];
this.#modalRouterElement.render();*/
this.#innerElement.next(element); this.#innerElement.next(element);
} }
@@ -167,4 +193,9 @@ export class UmbModalHandlerClass<ModalData extends object = object, ModalResult
this.#innerElement.next(undefined); this.#innerElement.next(undefined);
} }
} }
public destroy() {
super.destroy();
// TODO: Make sure to clean up..
}
} }

View File

@@ -115,6 +115,7 @@ export class UmbModalRouteRegistration<UmbModalTokenData extends object = object
const modalData = this.#onSetupCallback ? this.#onSetupCallback(params) : undefined; const modalData = this.#onSetupCallback ? this.#onSetupCallback(params) : undefined;
if (modalData !== false) { if (modalData !== false) {
console.log('routeSetup has router:', router);
this.#modalHandler = modalContext.open(this.#modalAlias, modalData, this.modalConfig, router); this.#modalHandler = modalContext.open(this.#modalAlias, modalData, this.modalConfig, router);
this.#modalHandler.onSubmit().then(this.#onSubmit, this.#onReject); this.#modalHandler.onSubmit().then(this.#onSubmit, this.#onReject);
return this.#modalHandler; return this.#modalHandler;

File diff suppressed because it is too large Load Diff

View File

@@ -68,7 +68,7 @@
"lit": "^2.7.0", "lit": "^2.7.0",
"lodash-es": "4.17.21", "lodash-es": "4.17.21",
"monaco-editor": "^0.36.1", "monaco-editor": "^0.36.1",
"router-slot": "file:router-slot-2.0.0.tgz", "router-slot": "file:router-slot-2.0.1.tgz",
"rxjs": "^7.8.0", "rxjs": "^7.8.0",
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },

View File

@@ -46,6 +46,7 @@ export class UmbInputDataTypeElement extends FormControlMixin(UmbLitElement) {
new UmbModalRouteRegistrationController(this, UMB_PROPERTY_EDITOR_UI_PICKER_MODAL) new UmbModalRouteRegistrationController(this, UMB_PROPERTY_EDITOR_UI_PICKER_MODAL)
.onSetup(() => { .onSetup(() => {
console.log('registration setup.');
return { return {
selection: [this._value.toString()], selection: [this._value.toString()],
submitLabel: 'Submit', submitLabel: 'Submit',

View File

@@ -59,7 +59,6 @@ export class UmbRouterSlotElement extends UmbLitElement {
this.#modalRouter.parent = this.#router; this.#modalRouter.parent = this.#router;
this.#modalRouter.style.display = 'none'; this.#modalRouter.style.display = 'none';
this.#router.addEventListener('changestate', this._updateRouterPath.bind(this)); this.#router.addEventListener('changestate', this._updateRouterPath.bind(this));
//this.#router.appendChild(this.#modalRouter);
this.#router.appendChild(document.createElement('slot')); this.#router.appendChild(document.createElement('slot'));
} }