@lynx-js/web-core
Version:
This is an internal experimental package, do not use
28 lines • 1.14 kB
JavaScript
import { queryNodes } from './queryNodes.js';
import { setNativePropsEndpoint } from '../../endpoints.js';
function applyNativeProps(element, nativeProps) {
for (const key in nativeProps) {
const value = nativeProps[key];
if (key === 'text' && element?.tagName === 'X-TEXT') {
if (element.firstElementChild
&& element.firstElementChild.tagName == 'RAW-TEXT') {
element = element.firstElementChild;
}
}
if (CSS.supports(key, value)
&& element.style) {
element.style.setProperty(key, value);
}
else {
element.setAttribute(key, value);
}
}
}
export function registerNativePropsHandler(rpc, lynxViewInstance) {
rpc.registerHandler(setNativePropsEndpoint, (type, identifier, component_id, first_only, native_props, root_unique_id) => {
queryNodes(lynxViewInstance, type, identifier, component_id, first_only, root_unique_id, (element) => {
applyNativeProps(element, native_props);
});
});
}
//# sourceMappingURL=registerSetNativePropsHandler.js.map