MCPcopy Create free account
hub / github.com/UI5/webcomponents / convertEventScoping

Function convertEventScoping

packages/base/src/jsx-utils.ts:5–32  ·  view source on GitHub ↗
(type: typeof UI5Element, props: Record<string, any>, key: string)

Source from the content-addressed store, hash-verified

3import { pascalToKebabCase } from "./util/StringHelper.js";
4
5function convertEventScoping(type: typeof UI5Element, props: Record<string, any>, key: string) {
6 const events = type.getMetadata().getEvents();
7
8 Object.keys(props).forEach(prop => {
9 if (prop.startsWith("on")) {
10 // Exteract the kebab-case event: onChange - change, onSelectionChange - selection-change, etc.
11 const pascalEvent = prop.slice("on".length);
12 const kebabCaseEvent = pascalToKebabCase(pascalEvent);
13 // Also support camelCase events
14 const camelCaseEvent = pascalEvent.charAt(0).toLowerCase() + pascalEvent.slice(1);
15
16 let origEvent: string | undefined;
17 if (kebabCaseEvent in events) {
18 origEvent = kebabCaseEvent;
19 } else if (camelCaseEvent in events) {
20 origEvent = camelCaseEvent;
21 }
22 // Attach for the "ui5-" preffixed event
23 if (origEvent) {
24 if ((prop !== "onClick")) {
25 props[`onui5-${origEvent}`] = props[prop];
26 // TODO keep native events for now, find a way to mark them for runtime
27 delete props[prop];
28 }
29 }
30 }
31 });
32}
33
34export function isUI5ElementClass(type: string | typeof UI5Element): type is typeof UI5Element {
35 return typeof type === "function" && "getMetadata" in type;

Callers 1

preprocessFunction · 0.85

Calls 3

pascalToKebabCaseFunction · 0.85
getEventsMethod · 0.80
getMetadataMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…