Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createStylesheet(
document: Document,
modifiers = {},
): StyleSheetType<*> {
const styles = getFirstTag(document, 'styles');
const stylesheet = {};
if (styles) {
const styleElements = styles.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
'style',
);
for (let i = 0; i < styleElements.length; i += 1) {
const styleElement = styleElements.item(i);
const hasModifier =
styleElement.parentNode &&
styleElement.parentNode.tagName === 'modifier';
let styleId = styleElement.getAttribute('id');
if (hasModifier) {
// TODO(adam): Use less hacky way to get id of parent style element.
styleId = styleElement.parentNode.parentNode.getAttribute('id');
}
// This must be a root style or a modifier style
onUpdate: HvComponentOnUpdate,
options: HvComponentOptions,
) => {
if (element.nodeType === NODE_TYPE.ELEMENT_NODE) {
// Hidden elements don't get rendered
if (element.getAttribute('hide') === 'true') {
return null;
}
}
if (element.nodeType === NODE_TYPE.COMMENT_NODE) {
// XML comments don't get rendered.
return null;
}
if (
element.nodeType === NODE_TYPE.ELEMENT_NODE &&
element.namespaceURI === Namespaces.HYPERVIEW
) {
switch (element.localName) {
case LOCAL_NAME.BODY:
case LOCAL_NAME.VIEW:
case LOCAL_NAME.FORM:
case LOCAL_NAME.HEADER:
case LOCAL_NAME.ITEM:
case LOCAL_NAME.SECTION_TITLE:
// TODO: Create HvView component
return view(element, stylesheets, onUpdate, options);
case LOCAL_NAME.TEXT:
// TODO: Create HvText component
return text(element, stylesheets, onUpdate, options);
case LOCAL_NAME.BEHAVIOR:
case LOCAL_NAME.MODIFIER:
case LOCAL_NAME.STYLES:
href: string,
action: NavAction,
element: Element,
opts: BehaviorOptions,
): void => {
const { showIndicatorId, delay } = opts;
const formData: ?FormData = getFormData(element);
// Serialize form data as query params, if present.
const baseUrl = UrlService.getUrlFromHref(href, this.url);
const url = UrlService.addFormDataToUrl(baseUrl, formData);
let preloadScreen = null;
if (showIndicatorId) {
const screens: NodeList<element> = this.document.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
'screen',
);
const loadingScreen: ?Element = Array.from(screens).find(
s => s && s.getAttribute('id') === showIndicatorId,
);
if (loadingScreen) {
preloadScreen = Date.now(); // Not trully unique but sufficient for our use-case
this.setPreloadScreen(preloadScreen, loadingScreen);
}
}
const routeParams = { url, preloadScreen, delay };
switch (action) {
case NAV_ACTIONS.PUSH:
this.navigation.push(routeParams);</element>
renderPicker = (style: StyleSheetType<*>): ReactNode => {
const element: Element = this.props.element;
const props = {
onValueChange: value => {
this.setState({ pickerValue: value });
},
selectedValue: this.state.pickerValue,
style,
};
// Gets all of the elements. All picker item elements
// with a value and label are turned into options for the picker.
const children: Array = Array.from(
element.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
LOCAL_NAME.PICKER_ITEM,
),
)
.filter(Boolean)
.map((item: Element) => {
const label: ?DOMString = item.getAttribute('label');
const value: ?DOMString = item.getAttribute('value');
if (!label || value === null) {
return null;
}
return React.createElement(Picker.Item, { label, value });
});
return React.createElement(Picker, props, ...children);
};
export const getFirstTag = (document: Document, localName: LocalName) => {
const elements = document.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
localName,
);
if (elements && elements[0]) {
return elements[0];
}
return null;
};
render() {
const { element, stylesheets, onUpdate, options } = this.props;
let viewOptions = options;
const { skipHref } = viewOptions || {};
const props: InternalProps = createProps(element, stylesheets, viewOptions);
const scrollable = !!element.getAttribute('scroll');
let Component = View;
const inputRefs = [];
if (scrollable) {
const textFields = element.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
'text-field',
);
const textAreas = element.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
'text-area',
);
const hasFields = textFields.length > 0 || textAreas.length > 0;
Component = hasFields
? KeyboardAwareScrollViewWithScrollContext
: ScrollViewWithScrollContext;
props.id = element.getAttribute('id');
if (hasFields) {
props.extraScrollHeight = 32;
props.keyboardOpeningTime = 0;
props.keyboardShouldPersistTaps = 'handled';
props.scrollEventThrottle = 16;
props.getTextInputRefs = () => inputRefs;
const registerInputHandler = ref => {
inputRefs.push(ref);
/**
* Copyright (c) Garuda Labs, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import * as Namespaces from 'hyperview/src/services/namespaces';
import React, { PureComponent } from 'react';
import { ActivityIndicator } from 'react-native';
import { LOCAL_NAME } from 'hyperview/src/types';
import type { Props } from './types';
export default class HvSpinner extends PureComponent {
static namespaceURI = Namespaces.HYPERVIEW;
static localName = LOCAL_NAME.SPINNER;
props: Props;
render() {
const { element } = this.props;
const color = element.getAttribute('color') || undefined;
return ;
}
}
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import * as Namespaces from 'hyperview/src/services/namespaces';
import React, { PureComponent } from 'react';
import { ActivityIndicator } from 'react-native';
import { LOCAL_NAME } from 'hyperview/src/types';
import type { Props } from './types';
import WebView from 'react-native-webview';
import { createProps } from 'hyperview/src/services';
export default class HvWebView extends PureComponent {
static namespaceURI = Namespaces.HYPERVIEW;
static localName = LOCAL_NAME.WEB_VIEW;
props: Props;
render() {
const props: any = createProps(
this.props.element,
this.props.stylesheets,
this.props.options,
);
const color = props['activity-indicator-color'];
const injectedJavaScript = props['injected-java-script'];
const source = { uri: props.url };
return (
}
source={source}
import type { InternalProps, Props } from './types';
import React, { PureComponent } from 'react';
import { ScrollView, View } from 'react-native';
import { addHref, createProps } from 'hyperview/src/services';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scrollview';
import { LOCAL_NAME } from 'hyperview/src/types';
const ScrollViewWithScrollContext = ScrollContext.withScrollableComponent(
ScrollView,
);
const KeyboardAwareScrollViewWithScrollContext = ScrollContext.withScrollableComponent(
KeyboardAwareScrollView,
);
export default class HvView extends PureComponent {
static namespaceURI = Namespaces.HYPERVIEW;
static localName = LOCAL_NAME.VIEW;
static localNameAliases = [
LOCAL_NAME.BODY,
LOCAL_NAME.FORM,
LOCAL_NAME.HEADER,
LOCAL_NAME.ITEM,
LOCAL_NAME.SECTION_TITLE,
];
props: Props;
render() {
const { element, stylesheets, onUpdate, options } = this.props;
let viewOptions = options;
const { skipHref } = viewOptions || {};
const props: InternalProps = createProps(element, stylesheets, viewOptions);
const scrollable = !!element.getAttribute('scroll');
onToggle = (selectedValue: ?DOMString) => {
const { element, onUpdate } = this.props;
const newElement = element.cloneNode(true);
const options = newElement.getElementsByTagNameNS(
Namespaces.HYPERVIEW,
'option',
);
for (let i = 0; i < options.length; i += 1) {
const option = options.item(i);
if (option) {
const value = option.getAttribute('value');
if (value === selectedValue) {
const selected = option.getAttribute('selected') === 'true';
option.setAttribute('selected', selected ? 'false' : 'true');
}
}
}
onUpdate('#', 'swap', element, { newElement });
};