Skip to content

Commit

Permalink
feat(core): Remove enums from event-dispatch.
Browse files Browse the repository at this point in the history
These cause optimization issues in external.
  • Loading branch information
iteriani committed Apr 19, 2024
1 parent 164dde4 commit de04524
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 164 deletions.
56 changes: 29 additions & 27 deletions packages/core/primitives/event-dispatch/src/accessibility.ts
Expand Up @@ -6,39 +6,41 @@
* found in the LICENSE file at https://angular.io/license
*/

/**
* An event-type set when the event contract detects a KEYDOWN event but
* doesn't know if the key press can be treated like a click. The dispatcher
* will use this event-type to parse the keypress and handle it accordingly.
*/
export const MAYBE_CLICK_EVENT_TYPE = 'maybe_click';
/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property for non-global dispatches before it retriggers the event and it
* signifies that the event contract should not dispatch this event globally.
*/
export const SKIP_GLOBAL_DISPATCH = 'a11ysgd';
/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property before it retriggers the event and it signifies that the event
* contract should not look at CLICK actions for KEYDOWN events.
*/
export const SKIP_A11Y_CHECK = 'a11ysc';

/**
* Defines special EventInfo and Event properties used when
* A11Y_SUPPORT_IN_DISPATCHER is enabled.
*/
export enum Attribute {
/**
* An event-type set when the event contract detects a KEYDOWN event but
* doesn't know if the key press can be treated like a click. The dispatcher
* will use this event-type to parse the keypress and handle it accordingly.
*/
MAYBE_CLICK_EVENT_TYPE = 'maybe_click',

/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property for non-global dispatches before it retriggers the event and it
* signifies that the event contract should not dispatch this event globally.
*/
SKIP_GLOBAL_DISPATCH = 'a11ysgd',

/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property before it retriggers the event and it signifies that the event
* contract should not look at CLICK actions for KEYDOWN events.
*/
SKIP_A11Y_CHECK = 'a11ysc',
}
export const Attribute = {
MAYBE_CLICK_EVENT_TYPE,
SKIP_GLOBAL_DISPATCH,
SKIP_A11Y_CHECK,
};

declare global {
interface Event {
[Attribute.MAYBE_CLICK_EVENT_TYPE]?: boolean;
[Attribute.SKIP_GLOBAL_DISPATCH]?: boolean;
[Attribute.SKIP_A11Y_CHECK]?: boolean;
[MAYBE_CLICK_EVENT_TYPE]?: boolean;
[SKIP_GLOBAL_DISPATCH]?: boolean;
[SKIP_A11Y_CHECK]?: boolean;
}
}
126 changes: 63 additions & 63 deletions packages/core/primitives/event-dispatch/src/attribute.ts
Expand Up @@ -6,72 +6,72 @@
* found in the LICENSE file at https://angular.io/license
*/

export enum Attribute {
/**
* The jsaction attribute defines a mapping of a DOM event to a
* generic event (aka jsaction), to which the actual event handlers
* that implement the behavior of the application are bound. The
* value is a semicolon separated list of colon separated pairs of
* an optional DOM event name and a jsaction name. If the optional
* DOM event name is omitted, 'click' is assumed. The jsaction names
* are dot separated pairs of a namespace and a simple jsaction
* name. If the namespace is absent, it is taken from the closest
* ancestor element with a jsnamespace attribute, if there is
* any. If there is no ancestor with a jsnamespace attribute, the
* simple name is assumed to be the jsaction name.
*
* Used by EventContract.
*/
JSACTION = 'jsaction',
/**
* The jsaction attribute defines a mapping of a DOM event to a
* generic event (aka jsaction), to which the actual event handlers
* that implement the behavior of the application are bound. The
* value is a semicolon separated list of colon separated pairs of
* an optional DOM event name and a jsaction name. If the optional
* DOM event name is omitted, 'click' is assumed. The jsaction names
* are dot separated pairs of a namespace and a simple jsaction
* name. If the namespace is absent, it is taken from the closest
* ancestor element with a jsnamespace attribute, if there is
* any. If there is no ancestor with a jsnamespace attribute, the
* simple name is assumed to be the jsaction name.
*
* Used by EventContract.
*/
export const JSACTION = 'jsaction';

/**
* The jsnamespace attribute provides the namespace part of the
* jaction names occurring in the jsaction attribute where it's
* missing.
*
* Used by EventContract.
*/
JSNAMESPACE = 'jsnamespace',
/**
* The jsnamespace attribute provides the namespace part of the
* jaction names occurring in the jsaction attribute where it's
* missing.
*
* Used by EventContract.
*/
export const JSNAMESPACE = 'jsnamespace';

/**
* The oi attribute is a log impression tag for impression logging
* and action tracking. For an element that carries a jsaction
* attribute, the element is identified for the purpose of
* impression logging and click tracking by the dot separated path
* of all oi attributes in the chain of ancestors of the element.
*
* Used by ActionFlow.
*/
OI = 'oi',
/**
* The oi attribute is a log impression tag for impression logging
* and action tracking. For an element that carries a jsaction
* attribute, the element is identified for the purpose of
* impression logging and click tracking by the dot separated path
* of all oi attributes in the chain of ancestors of the element.
*
* Used by ActionFlow.
*/
export const OI = 'oi';

/**
* The ved attribute is an encoded ClickTrackingCGI proto to track
* visual elements.
*
* Used by ActionFlow.
*/
VED = 'ved',
/**
* The ved attribute is an encoded ClickTrackingCGI proto to track
* visual elements.
*
* Used by ActionFlow.
*/
export const VED = 'ved';

/**
* The vet attribute is the visual element type used to identify tracked
* visual elements.
*/
VET = 'vet',
/**
* The vet attribute is the visual element type used to identify tracked
* visual elements.
*/
export const VET = 'vet';

/**
* Support for iteration on reprocessing.
*
* Used by ActionFlow.
*/
export const JSINSTANCE = 'jsinstance';

/**
* Support for iteration on reprocessing.
*
* Used by ActionFlow.
*/
JSINSTANCE = 'jsinstance',
/**
* All click jsactions that happen on the element that carries this
* attribute or its descendants are automatically logged.
* Impressions of jsactions on these elements are tracked too, if
* requested by the impression() method of ActionFlow.
*
* Used by ActionFlow.
*/
export const JSTRACK = 'jstrack';

/**
* All click jsactions that happen on the element that carries this
* attribute or its descendants are automatically logged.
* Impressions of jsactions on these elements are tracked too, if
* requested by the impression() method of ActionFlow.
*
* Used by ActionFlow.
*/
JSTRACK = 'jstrack',
}
export const Attribute = {JSNAMESPACE, OI, VED, VET, JSINSTANCE, JSTRACK};
13 changes: 6 additions & 7 deletions packages/core/primitives/event-dispatch/src/cache.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Property} from './property';
import {JSACTION, JSNAMESPACE} from './property';

/**
* Map from jsaction annotation to a parsed map from event name to action name.
Expand Down Expand Up @@ -62,8 +62,8 @@ export function setParsed(text: string, parsed: {[key: string]: string}) {
* @param element .
*/
export function clear(element: Element) {
if (Property.JSACTION in element) {
delete element[Property.JSACTION];
if (JSACTION in element) {
delete element[JSACTION];
}
}

Expand All @@ -88,8 +88,7 @@ export function getNamespace(element: Element): string | null | undefined {
* @param jsnamespace .
*/
export function setNamespace(element: Element, jsnamespace: string | null) {
// @ts-ignore
element[Property.JSNAMESPACE] = jsnamespace;
element[JSNAMESPACE] = jsnamespace!;
}

/**
Expand All @@ -98,7 +97,7 @@ export function setNamespace(element: Element, jsnamespace: string | null) {
* @param element .
*/
export function clearNamespace(element: Element) {
if (Property.JSNAMESPACE in element) {
delete element[Property.JSNAMESPACE];
if (JSNAMESPACE in element) {
delete element[JSNAMESPACE];
}
}
8 changes: 4 additions & 4 deletions packages/core/primitives/event-dispatch/src/dispatcher.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Attribute as AccessibilityAttribute} from './accessibility';
import {MAYBE_CLICK_EVENT_TYPE, SKIP_A11Y_CHECK, SKIP_GLOBAL_DISPATCH} from './accessibility';
import {Char} from './char';
import * as eventLib from './event';
import {EventInfo, EventInfoWrapper} from './event_info';
Expand Down Expand Up @@ -321,7 +321,7 @@ export class Dispatcher {
* be re-dispatched.
*/
function resolveA11yEvent(eventInfoWrapper: EventInfoWrapper, isGlobalDispatch = false): boolean {
if (eventInfoWrapper.getEventType() !== AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE) {
if (eventInfoWrapper.getEventType() !== MAYBE_CLICK_EVENT_TYPE) {
return true;
}

Expand All @@ -343,10 +343,10 @@ function resolveA11yEvent(eventInfoWrapper: EventInfoWrapper, isGlobalDispatch =
// This prevents the event contract from setting the
// AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE type for Keydown
// events.
eventInfoWrapper.getEvent()[AccessibilityAttribute.SKIP_A11Y_CHECK] = true;
eventInfoWrapper.getEvent()[SKIP_A11Y_CHECK] = true;
// Since globally dispatched events will get handled by the dispatcher,
// don't have the event contract dispatch it again.
eventInfoWrapper.getEvent()[AccessibilityAttribute.SKIP_GLOBAL_DISPATCH] = true;
eventInfoWrapper.getEvent()[SKIP_GLOBAL_DISPATCH] = true;
return false;
}
}
Expand Down
34 changes: 14 additions & 20 deletions packages/core/primitives/event-dispatch/src/eventcontract.ts
Expand Up @@ -31,8 +31,8 @@
*/

import * as a11yClickLib from './a11y_click';
import {Attribute as AccessibilityAttribute} from './accessibility';
import {Attribute} from './attribute';
import {MAYBE_CLICK_EVENT_TYPE, SKIP_A11Y_CHECK, SKIP_GLOBAL_DISPATCH} from './accessibility';
import {JSACTION, JSNAMESPACE} from './attribute';
import * as cache from './cache';
import {Char} from './char';
import {EarlyJsactionData} from './earlyeventcontract';
Expand All @@ -48,7 +48,7 @@ import {
} from './event_contract_defines';
import * as eventInfoLib from './event_info';
import {EventType} from './event_type';
import {Property} from './property';
import {OWNER} from './property';
import {Restriction} from './restriction';

/**
Expand Down Expand Up @@ -218,10 +218,7 @@ export class EventContract implements UnrenamedEventContract {

this.populateAction(eventInfo);

if (
this.dispatcher &&
!eventInfoLib.getEvent(eventInfo)[AccessibilityAttribute.SKIP_GLOBAL_DISPATCH]
) {
if (this.dispatcher && !eventInfoLib.getEvent(eventInfo)[SKIP_GLOBAL_DISPATCH]) {
const globalEventInfo: eventInfoLib.EventInfo = eventInfoLib.cloneEventInfo(eventInfo);

// In some cases, `populateAction` will rewrite `click` events to
Expand All @@ -240,10 +237,7 @@ export class EventContract implements UnrenamedEventContract {
}

let stopPropagationAfterDispatch = false;
if (
this.stopPropagation &&
eventInfoLib.getEventType(eventInfo) !== AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE
) {
if (this.stopPropagation && eventInfoLib.getEventType(eventInfo) !== MAYBE_CLICK_EVENT_TYPE) {
if (
eventLib.isGecko &&
(eventInfoLib.getTargetElement(eventInfo).tagName === 'INPUT' ||
Expand All @@ -260,7 +254,7 @@ export class EventContract implements UnrenamedEventContract {
}
} else if (
this.stopPropagation &&
eventInfoLib.getEventType(eventInfo) === AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE
eventInfoLib.getEventType(eventInfo) === MAYBE_CLICK_EVENT_TYPE
) {
// We first need to let the dispatcher determine whether we can treat
// this event as a click event.
Expand Down Expand Up @@ -345,11 +339,11 @@ export class EventContract implements UnrenamedEventContract {
} else if (
EventContract.A11Y_SUPPORT_IN_DISPATCHER &&
eventInfoLib.getEventType(eventInfo) === EventType.KEYDOWN &&
!eventInfoLib.getEvent(eventInfo)[AccessibilityAttribute.SKIP_A11Y_CHECK]
!eventInfoLib.getEvent(eventInfo)[SKIP_A11Y_CHECK]
) {
// We use a string literal as this value needs to be referenced in the
// dispatcher's binary.
eventInfoLib.setEventType(eventInfo, AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE);
eventInfoLib.setEventType(eventInfo, MAYBE_CLICK_EVENT_TYPE);
}

// Walk to the parent node, unless the node has a different owner in
Expand All @@ -365,8 +359,8 @@ export class EventContract implements UnrenamedEventContract {
// ancestor chain of the event target node.
break;
}
if (actionElement[Property.OWNER]) {
actionElement = actionElement[Property.OWNER] as Element;
if (actionElement[OWNER]) {
actionElement = actionElement[OWNER] as Element;
continue;
}
if (actionElement.parentNode?.nodeName !== '#document-fragment') {
Expand Down Expand Up @@ -453,7 +447,7 @@ export class EventContract implements UnrenamedEventContract {
}
if (EventContract.A11Y_SUPPORT_IN_DISPATCHER) {
if (
eventInfoLib.getEventType(eventInfo) === AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE &&
eventInfoLib.getEventType(eventInfo) === MAYBE_CLICK_EVENT_TYPE &&
actionMap[EventType.CLICK] !== undefined
) {
// We'll take the first CLICK action we find and have the dispatcher
Expand Down Expand Up @@ -688,7 +682,7 @@ export function addDeferredA11yClickSupport(eventContract: EventContract) {
function checkDispatcherForA11yClick(eventInfo: eventInfoLib.EventInfo): boolean {
return (
EventContract.A11Y_SUPPORT_IN_DISPATCHER &&
eventInfoLib.getEventType(eventInfo) === AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE
eventInfoLib.getEventType(eventInfo) === MAYBE_CLICK_EVENT_TYPE
);
}

Expand Down Expand Up @@ -724,7 +718,7 @@ function shouldPreventDefaultBeforeDispatching(
export function parseActions(actionElement: Element, container: Node): {[key: string]: string} {
let actionMap: {[key: string]: string} | undefined = cache.get(actionElement);
if (!actionMap) {
const jsactionAttribute = getAttr(actionElement, Attribute.JSACTION);
const jsactionAttribute = getAttr(actionElement, JSACTION);
if (!jsactionAttribute) {
actionMap = EMPTY_ACTION_MAP;
cache.set(actionElement, actionMap);
Expand Down Expand Up @@ -820,7 +814,7 @@ function getNamespaceFromElement(element: Element): string | null {
// namespace is string|null if the query took place in the past, or
// undefined if the query did not take place.
if (namespace === undefined) {
namespace = getAttr(element, Attribute.JSNAMESPACE);
namespace = getAttr(element, JSNAMESPACE);
cache.setNamespace(element, namespace);
}
return namespace;
Expand Down

0 comments on commit de04524

Please sign in to comment.