chore(packages): move the packages to root

This commit is contained in:
Brandy Carney
2018-03-12 16:02:25 -04:00
parent 097f1a2cd3
commit d37623a2ca
1255 changed files with 38 additions and 38 deletions

22
react/src/apis/apis.ts Normal file
View File

@ -0,0 +1,22 @@
import { ModalOptions } from '@ionic/core';
import { Delegate } from '../react-framework-delegate';
import { getOrAppendElement } from '../utils/helpers';
export function createModal(opts: ModalOptions): Promise<HTMLIonModalElement> {
return createOverlayInternal('ion-modal-controller', opts);
}
export function createPopover(opts: ModalOptions): Promise<HTMLIonModalElement> {
return createOverlayInternal('ion-popover-controller', opts);
}
function createOverlayInternal(controllerTagName: string, opts: any) {
opts.delegate = Delegate;
const element = getOrAppendElement(controllerTagName) as HTMLIonModalControllerElement;
return (element as any).componentOnReady().then(() => {
return element.create(opts);
});
}

2
react/src/declarations.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
declare module 'react';
declare module 'react-dom';

3
react/src/index.ts Normal file
View File

@ -0,0 +1,3 @@
export { Delegate } from './react-framework-delegate';
export * from './apis/apis';
export * from './utils/wc-shim';

View File

@ -0,0 +1,44 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { FrameworkDelegate } from '@ionic/core';
import { isElementModal, isElementNav } from './utils/helpers';
export function attachViewToDom(parentElement: HTMLElement, reactComponent: any, propsOrData: any, classesToAdd: string[]) {
const wrappingDiv = shouldWrapInIonPage(parentElement) ? document.createElement('ion-page') : document.createElement('div');
if (classesToAdd) {
for (const clazz of classesToAdd) {
wrappingDiv.classList.add(clazz);
}
}
parentElement.appendChild(wrappingDiv);
// mount the React component
const reactElement = React.createElement(reactComponent, propsOrData);
const mountedComponentInstance = ReactDOM.render(reactElement, wrappingDiv);
return Promise.resolve({
element: wrappingDiv,
reactElement: reactElement,
instance: mountedComponentInstance
});
}
export function removeViewFromDom(parentElement: HTMLElement, childElement: HTMLElement): Promise<any> {
ReactDOM.unmountComponentAtNode(childElement);
parentElement.removeChild(childElement);
return Promise.resolve();
}
const Delegate: FrameworkDelegate = {
attachViewToDom: attachViewToDom,
removeViewFromDom: removeViewFromDom,
};
export { Delegate }
export function shouldWrapInIonPage(element: HTMLElement) {
return isElementModal(element) || isElementNav(element);
}

View File

@ -0,0 +1,18 @@
export function getOrAppendElement(tagName: string): Element {
const element = document.querySelector(tagName);
if (element) {
return element;
}
const tmp = document.createElement(tagName);
document.body.appendChild(tmp);
return tmp;
}
export function isElementNav(element: HTMLElement) {
return element.tagName.toUpperCase() === 'ION-NAV';
}
export function isElementModal(element: HTMLElement) {
return element.classList.contains('modal-wrapper');
}

View File

@ -0,0 +1,24 @@
export function wc(events = {}, obj = {}) {
let storedEl: HTMLElement;
return function (el: HTMLElement) {
(Object as any).entries(events).forEach((keyValues: string[]) => {
const name = keyValues[0];
const value = keyValues[1];
const action = (el) ? el.addEventListener : storedEl.removeEventListener;
if (typeof value === 'function') {
action(name, value);
return;
}
});
if (el) {
(Object as any).entries(obj).forEach((keyValues: string[]) => {
const name = keyValues[0];
const value = keyValues[1];
(el as any)[name] = value;
});
}
storedEl = el;
};
}