rename context consume event const

This commit is contained in:
Niels Lyngsø
2024-11-07 10:05:31 +01:00
parent 493e800a7e
commit e85f108b75
6 changed files with 18 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ import { UmbContextProvider } from '../provide/context-provider.js';
import { UmbContextToken } from '../token/context-token.js';
import { UmbContextConsumer } from './context-consumer.js';
import type { UmbContextRequestEventImplementation } from './context-request.event.js';
import { UMB_CONTENT_REQUEST_EVENT_TYPE } from './context-request.event.js';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE } from './context-request.event.js';
import { expect, oneEvent } from '@open-wc/testing';
const testContextAlias = 'my-test-context';
@@ -38,13 +38,13 @@ describe('UmbContextConsumer', () => {
describe('events', () => {
it('dispatches context request event when constructed', async () => {
const listener = oneEvent(window, UMB_CONTENT_REQUEST_EVENT_TYPE);
const listener = oneEvent(window, UMB_CONTEXT_REQUEST_EVENT_TYPE);
consumer.hostConnected();
const event = (await listener) as unknown as UmbContextRequestEventImplementation;
expect(event).to.exist;
expect(event.type).to.eq(UMB_CONTENT_REQUEST_EVENT_TYPE);
expect(event.type).to.eq(UMB_CONTEXT_REQUEST_EVENT_TYPE);
expect(event.contextAlias).to.eq(testContextAlias);
consumer.hostDisconnected();
});

View File

@@ -1,4 +1,9 @@
export const UMB_CONTENT_REQUEST_EVENT_TYPE = 'umb:context-request';
export const UMB_CONTEXT_REQUEST_EVENT_TYPE = 'umb:context-request';
/**
* @deprecated use UMB_CONTEXT_REQUEST_EVENT_TYPE
* This will be removed in Umbraco 17
*/
export const UMB_CONTENT_REQUEST_EVENT_TYPE = UMB_CONTEXT_REQUEST_EVENT_TYPE;
export const UMB_DEBUG_CONTEXT_EVENT_TYPE = 'umb:debug-contexts';
export type UmbContextCallback<T> = (instance: T) => void;
@@ -29,7 +34,7 @@ export class UmbContextRequestEventImplementation<ResultType = unknown>
public readonly callback: (context: ResultType) => boolean,
public readonly stopAtContextMatch: boolean = true,
) {
super(UMB_CONTENT_REQUEST_EVENT_TYPE, { bubbles: true, composed: true, cancelable: true });
super(UMB_CONTEXT_REQUEST_EVENT_TYPE, { bubbles: true, composed: true, cancelable: true });
}
clone() {

View File

@@ -1,6 +1,6 @@
import type { UmbContextRequestEvent } from '../consume/context-request.event.js';
import type { UmbContextToken } from '../token/index.js';
import { UMB_CONTENT_REQUEST_EVENT_TYPE } from '../consume/context-request.event.js';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE } from '../consume/context-request.event.js';
import { UmbContextProvideEventImplementation } from './context-provide.event.js';
/**
@@ -24,7 +24,7 @@ export class UmbContextBoundary {
const idSplit = contextIdentifier.toString().split('#');
this.#contextAlias = idSplit[0];
this.#eventTarget.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
this.#eventTarget.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
}
/**

View File

@@ -1,6 +1,6 @@
import type { UmbContextRequestEvent } from '../consume/context-request.event.js';
import type { UmbContextToken } from '../token/index.js';
import { UMB_CONTENT_REQUEST_EVENT_TYPE, UMB_DEBUG_CONTEXT_EVENT_TYPE } from '../consume/context-request.event.js';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE, UMB_DEBUG_CONTEXT_EVENT_TYPE } from '../consume/context-request.event.js';
import { UmbContextProvideEventImplementation } from './context-provide.event.js';
/**
@@ -41,7 +41,7 @@ export class UmbContextProvider<BaseType = unknown, ResultType extends BaseType
this.#apiAlias = idSplit[1] ?? 'default';
this.#instance = instance;
this.#eventTarget.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
this.#eventTarget.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, this.#handleContextRequest);
}
/**

View File

@@ -17,7 +17,7 @@ import { UMB_ROUTE_CONTEXT, type UmbRouterSlotElement } from '@umbraco-cms/backo
import { createExtensionElement } from '@umbraco-cms/backoffice/extension-api';
import type { UmbContextRequestEvent } from '@umbraco-cms/backoffice/context-api';
import {
UMB_CONTENT_REQUEST_EVENT_TYPE,
UMB_CONTEXT_REQUEST_EVENT_TYPE,
UmbContextBoundary,
UmbContextProvider,
} from '@umbraco-cms/backoffice/context-api';
@@ -63,7 +63,7 @@ export class UmbModalElement extends UmbLitElement {
// The following code is the context api proxy.
// It re-dispatches the context api request event to the origin target of this modal, in other words the element that initiated the modal. [NL]
this.element.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
this.element.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
if (!this.#modalContext) return;
// Note for this hack (The if-sentence): [NL]
// We do not currently have a good enough control to ensure that the proxy is last, meaning if another context is provided at this element, it might respond after the proxy event has been dispatched.

View File

@@ -1,4 +1,4 @@
import { UMB_CONTENT_REQUEST_EVENT_TYPE, type UmbContextRequestEvent } from '@umbraco-cms/backoffice/context-api';
import { UMB_CONTEXT_REQUEST_EVENT_TYPE, type UmbContextRequestEvent } from '@umbraco-cms/backoffice/context-api';
import type { RawEditorOptions } from '@umbraco-cms/backoffice/external/tinymce';
import { UUIIconRequestEvent } from '@umbraco-cms/backoffice/external/uui';
@@ -34,7 +34,7 @@ export const defaultFallbackConfig: RawEditorOptions = {
init_instance_callback: function (editor) {
// The following code is the context api proxy. [NL]
// It re-dispatches the context api request event to the origin target of this modal, in other words the element that initiated the modal. [NL]
editor.dom.doc.addEventListener(UMB_CONTENT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
editor.dom.doc.addEventListener(UMB_CONTEXT_REQUEST_EVENT_TYPE, ((event: UmbContextRequestEvent) => {
if (!editor.iframeElement) return;
event.stopImmediatePropagation();