(type: typeof UI5Element, props: Record<string, any>, key: string)
| 3 | import { pascalToKebabCase } from "./util/StringHelper.js"; |
| 4 | |
| 5 | function 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 | |
| 34 | export function isUI5ElementClass(type: string | typeof UI5Element): type is typeof UI5Element { |
| 35 | return typeof type === "function" && "getMetadata" in type; |
no test coverage detected
searching dependent graphs…